cl-str icon indicating copy to clipboard operation
cl-str copied to clipboard

Introduce *sharedp* variable

Open christophejunke opened this issue 5 years ago • 2 comments

Hi,

It could be interesting to have a way to allow operation on strings share the same storage as an input string. For example, substring could make a displaced string instead of calling subseq (e.g. slices in Go, string views in C++)

Following the naming from cl-ppcre, I'd like to introduce *sharedp* with a default value of NIL, and make functions learn this behaviour when possible, namely: when *sharedp* is T, functions may return strings that share storage with their inputs (or even return an input); operations remain non-destructive w.r.t. inputs

christophejunke avatar Sep 29 '20 12:09 christophejunke

For context, I am starting to collect some of my utility functions to package them as small libraries (starting with https://github.com/christophejunke/tilde-slash), and I'd prefer to reuse or extend cl-str instead of having a separate string library.

christophejunke avatar Sep 29 '20 14:09 christophejunke

That seems a nice optional feature. (considering it doesn't bring much complexity :) I like to think that the current code is very approachable and helps to learn the built-in string manipulation).

Thanks for sharing and porting your utilities.

vindarel avatar Sep 29 '20 16:09 vindarel