For Development HEAD DRAFTSearch (procedure/syntax/module):

Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]

11.25 srfi.118 - Simple adjustable-size strings

Module: srfi.118

This SRFI defines two string mutating operations that can change the length of the string: string-append! and string-replace!.

Note that, in Gauche, the body of strings is immutable; when you mutate a string, Gauche creates a fresh new string body and just switch a pointer in the original string to point the new string body. So it is not a problem to implement this SRFI in Gauche, but it also means you won’t get any performance benefit by using these operations. Using immutable counterparts (string-append and string-replace) gives you the same performance. (Be aware that the interface is slightly different from the immutable versions.)

We provide this module only for the compatibility. Gauche-specific programs should stay away from this module. Particularly, avoid code like the example in SRFI-118 document (build a string by append!-ing small chunks at a time)—they’re quadratic on Gauche.

Function: string-append! string values …

[SRFI-118]{srfi.118} The string argument must be a mutable string. Modify string by appending values, each of which is either a character or a string.

(rlet1 a (string-copy "abc")
  (string-append! a #\X "YZ"))
 ⇒ "abcXYZ"
Function: string-replace! dst dst-start dst-end src :optional src-start src-end

[SRFI-118]{srfi.118} The dst argument must be a mutable string. Replace dst between dst-start (inclusive) and dst-end (exclusive) with a string src. The optional arguments src-start and src-end limits the region of src to be used.

Be aware that the order of arguments differ from SRFI-13’s string-replace (see Other string operations); string-replace! resembles to string-copy! (also in SRFI-13), rather than string-replace.

(rlet1 a (string-copy "abc")
  (string-replace! a 1 2 "XYZ"))
 ⇒ "aXYZc"

Next: , Previous: , Up: Library modules - SRFIs   [Contents][Index]

For Development HEAD DRAFTSearch (procedure/syntax/module):