Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a "in place" String.sub (without any copy) #3899

Closed
vicuna opened this issue Nov 30, 2005 · 1 comment
Closed

a "in place" String.sub (without any copy) #3899

vicuna opened this issue Nov 30, 2005 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Nov 30, 2005

Original bug ID: 3899
Reporter: philippe_wang
Status: closed (set by @damiendoligez on 2005-12-15T12:59:35Z)
Resolution: not fixable
Priority: normal
Severity: feature
Category: ~DO NOT USE (was: OCaml general)

Bug description

I wish I could return a substring (like String.sub but) without copy.

It would allow to do something like :

let s = "hello world" ;;

val s : string = "hello world"

let sub = String.sub_without_copy s 0 5 ;;

val sub : string = "hello"

s.[0] <- 'H' ; s.[1] <- 'E' ; s.[2] <- 'L' ;;

  • : unit = ()

sub ;;

val sub : string = "HELlo"

s ;;

val s : string = "HELlo world"

(it is very unpleasant to deal with a record type to handle such a feature...)

Additional information

val sub : string -> int -> int -> string

   String.sub  s start len returns a fresh string of length len , contain-
   ing the characters number start to start + len - 1 of  string  s  Raise
   Invalid_argument if start and len do not designate a valid substring of
   s ; that is, if start < 0 , or len < 0 , or start + len > String.length
   s
@vicuna
Copy link
Author

vicuna commented Dec 15, 2005

Comment author: @damiendoligez

Given our representation of strings, this is impossible to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant