(examples-for string-eval-fn

("returns a function to eval a user-supplied string"
 (let s "hello \~|u|, \~x + \~y is \~(+ x y), thank you!"
   (let f (string-eval-fn s '(u x y))
     (f "world" 37 5)))
 "hello world, 37 + 5 is 42, thank you!"))

(examples-for string/eval-with-args

("evals a user-supplied string"
 (let s "hello \~|u|, \~x + \~y is \~(+ x y), thank heavens!"
   (string/eval-with-args s '(u x y) "world" 36 6))
 "hello world, 36 + 6 is 42, thank heavens!")

("reports errors"
 (on-err errors
         (let s "hello \~|u|, \~x + \~y is \~(+ 2 y), thank heavens!"
           (string/eval-with-args s '(a b c) "world" 36 6)))
 ("error evaluating \"hello \~|u|, \~x + \~y is \~(+ 2 y), thank heavens!\"

with arg names (a b c)nand args ("world" 36 6)“

“Called builtin/apply with args

NydpGenerated_2F5C2EF513C87E2349A55BCB331F83CC856076BBB89CDFAAA1817D62AFEEF0DB.rb:15
(fn (a b c) (string-pieces \"hello \" u \", \" x \" + \" y \" is \" (+ 2 y) \", thank heavens!\"))
(\"world\" 36 6)"

“Called builtin/+ with args

2
nil"

“nil can’t be coerced into Integer”)))

(examples-for string/pad-left

("does not change a string whose length is greater than the given length"
 (string/pad-left "Toronto" 3 "X")
 "Toronto")

("adds left padding to a string such that the result is the given length"
 (string/pad-left "toto" 8 "X")
 "XXXXtoto")

("accepts multi-character padding"
 (string/pad-left "toto" 12 "XYZ")
 "XYZXYZXYtoto"))

(examples-for string/pad-right

("does not change a string whose length is greater than the given length"
 (string/pad-right "Toronto" 3 "X")
 "Toronto")

("adds right padding to a string such that the result is the given length"
 (string/pad-right "toto" 8 "X")
 "totoXXXX")

("accepts multi-character padding"
 (string/pad-right "toto" 12 "XYZ")
 "totoXYZXYZXY"))

(examples-for string-split

("splits a string using given expression"
 (string-split "a and b and c and d" " and ")
 ("a" "b" "c" "d"))

("with no delimiter argument, returns chars in string"
 (collect !empty? (string-split "word"))
 ("w" "o" "r" "d"))

("splits on regexp"
 (string-split "hello, darkness ; my old friend\nI've come : to talk - with you again..." (regexp "\[\\n;:\\-,\]"))
 ("hello" " darkness " " my old friend" "I've come " " to talk " " with you again..."))

("returns empty leading, internal, and trailing segments"
 (string-split "and" "and")
 ("" ""))

("returns empty leading, internal, and trailing segments"
 (string-split "andandand" "and")
 ("" "" "" "")))

(examples-for string-replace

("replaces parts of a string with the given replacement"
 (string-replace "and" "or" "a and b and c and d")
 "a or b or c or d")

("replaces with hash lookup"
 (string-replace
   "['<>&\"]"
   { "'" "&#39;"
     "<" "&lt;"
     ">" "&gt;"
     "\"" "&quot;" }
   "it's >such< a \"lovely\" day")
 "it&#39;s &gt;such&lt; a &quot;lovely&quot; day")

("replace with regexp"
 (string-replace "and|or" "x" "a and b or c and d")
 "a x b x c x d")

("replace with literal regexp"
 (string-replace (regexp "and|or") "x" "a and b or c and d")
 "a x b x c x d"))

(examples-for string-truncate

("truncates a string to the given length"
 (string-truncate "a and b and c and d" 8)
 "a and b ")

("truncate to zero"
 (string-truncate "a and b and long and complex" 0)
 ""))

(examples-for string-match

("no match returns nil"
 (string-match "this that another" "XXXX")
 nil)

("match with regexp"
 (let m (string-match "a and b and c and d" "and")
   (list m.match m.captures))
 ("and" nil))

("no match with regexp"
 (let m (string-match "a and b and c and d" "not-in-string")
   (list m.match m.captures))
 (nil nil))

("match with regexp and capturing groups"
 (let m (string-match "  foo\b    bar" "(^\\s+)")
   (list m.match m.captures))
 ("  " ("  "))))

(examples-for string-pieces

("interpolates a string"
 "foobar ~(+ 1 2) you know"
 "foobar 3 you know"))

(examples-for joinstr

("joins elements into a string"
 (joinstr "" '("foo" "bar" "bax"))
 "foobarbax")

("joins separate elements into a string"
 (joinstr "/" "foo" "bar" "bax")
 "foo/bar/bax")

("joins a single thing"
 (joinstr "/" "foo")
 "foo")

("joins nested and separate elements into a string"
 (joinstr "/" "foo" "bar" '(twiddle diddle) "bax")
 "foo/bar/twiddle/diddle/bax")

("joins elements into a string"
 (joinstr " - " '(1 2 3))
 "1 - 2 - 3"))

(examples-for j

("joins elements with empty string"
 (j 1 2 3)
 "123")
("joins elements of a list with empty string"
 (j '(1 2 3))
 "123"))

(examples-for string-strip

("removes leading whitespace"               (string-strip "    hello!")  "hello!" )
("removes trailing whitespace"              (string-strip "(world)   ") "(world)" )
("removes leading and trailing whitespace"  (string-strip "\n\nme\n\n") "me"      )
("ignores leading and trailing whitespace for intenal lines"
 (string-strip "\n\n  me  \n\n  you  \n\n\t them \t\n\n")
 "me  \n\n  you  \n\n\t them"      ))