Project

General

Profile

Actions

Feature #19314

closed

String#bytesplice should support partial copy

Added by shugo (Shugo Maeda) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:111674]

Description

String#bytesplice should support partial copy without temporary String objects.

For example, given x = "0123456789", either of the following replaces the contents of x with "0167856789":

x.bytesplice(2, 3, x, 6, 3)
x.bytesplice(2..4, x, 6..8)

Considerations

  • What should be the return value?
    • The return value should be the whole source string for performance and consistency with bytesplice(offset, len, s).
  • Can the source and destination ranges overlap?
    • Yes.
  • Can the source and destination lengths be different?
    • Yes.
  • Can range form and offset/length form be mixed in the source and destination?
    • No.
  • What should happen when any offset doesn't land on character boundary in text strings.
    • IndexError should be raised.
  • Can the length be omitted in the destination?
    • Maybe yes, but it may be confusing.

Use cases


Related issues 1 (1 open0 closed)

Related to Ruby master - Feature #19315: Lazy substrings in CRubyOpenActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0