[Scheme-reports] mutable unicode strings
Per Bothner 01 Jul 2014 21:26 UTC
I'm working on improving Kawa's Unicode support to
be spec-compliant:
https://sourceware.org/ml/kawa/2014-q2/msg00077.html
I have two related questions/issues:
(1) The Chibi "cursor" API for fast O(1) string access seems
reasonable:
https://code.google.com/p/chibi-scheme/source/browse/doc/chibi.scrbl
However, there are no functions for string mutation - i.e. the
replacement for string-set!. Anyone implemented or designed such?
(2) Once we have variable-length characters (UTF-8 or UTF-16)
stored in a buffer, then any string that you can mutate with
string-set! inherently becomes a variable-length string. So
we might as well let the Scheme programmer make use of that.
I'm thinking of adding a general function:
(string-replace! to to-start to-end from [from-start [from-end]])
I.e. this is a generalization of string-copy! but it replaces the
substring of to from to-start to to-end by from (or a substring thereof).
It would also be useful to have an append-at-end function, since that may
be the most common use-case for mutable strings:
(string-append! to val ...)
where each val is a character or a string that is appended to to.
I.e. (string-append! dst-str src-str ...)
is equivalent to:
(string-replace! to (string-length to) (string-length to)
(string-append src-str ...))
(Characters are expanded to strings as needed.)
Does this seem reasonable? Any prior art I should know about?
--
--Per Bothner
per@bothner.com http://per.bothner.com/
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports