(html (head (title "sph-lib (sph string)") (link (@ (rel "stylesheet") (type "text/css") (href "/css/sph.css"))) (meta (@ (name "viewport") (content "width=device-width,initial-scale=1"))) #f) (body () (div (@ (class top)) (nav (a (@ (href "/")) "start") ", " (a (@ (href "/feed.xml")) "feed")) "") (div (@ (class "middle")) (div (@ (class mtime) (title "last modification time of the current page")) "2023-04-05") (section (h1 "(sph string)") (div (p "string processing. includes string-replace-string, a fast replacer.") (p "part of " (a (@ (href "../../sph-lib.html")) "sph-lib")) ((section (@ (class "library-description")) (h1 "library description") (div (p "# syntax") (p "string-case :: string (condition any:consequent) ...") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "like case but for strings instead of symbols.")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "example:")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "(string-case \"test\"")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "(\"a\" 1)")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "((\"b\" \"c\") 2)")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "(mystringlist 3)")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "(else 4))")))) (section (@ (class "library-name")) (h1 "module name") (p "(sph string)")) (section (@ (class "library-exports")) (h1 "exported bindings") (div (div (@ (class "doc-bindings")) (div (@ (id "doc-b-" "any->string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "any->string") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "any -> string")) (div (@ (class "description")) (("generalized string conversion function." (br) "get the string representation for the value of an object." (br) "symbols like \\\".\\\" are converted to \\\"#{.}\\\" using display.")))) (div (@ (id "doc-b-" "any->string-display") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "any->string-display") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "any->string-pretty-print") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "any->string-pretty-print") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "any->string-write") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "any->string-write") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "any->string-write*") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "any->string-write*") " " (span (@ (class "first-sig")) "a ->")) "" (div (@ (class "description")) (("write converts symbols like \\\".\\\" to #{.}, this procedure avoids this")))) (div (@ (id "doc-b-" "list->string-columns") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "list->string-columns") " " (span (@ (class "first-sig")) "a #:justify #:separator #:max-width ->")) (div (@ (class "rest-sig")) (div "(string ...) #:justify symbol:left/right #:separator string #:max-width integer -> string")) (div (@ (class "description")) (("create a string of equally sized columns containing elements of the string list \\\"a\\\", separated" (br) "by #:separator")))) (div (@ (id "doc-b-" "parenthesise") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "parenthesise") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> string")) (div (@ (class "description")) (("surround string with an open and a closing round bracket")))) (div (@ (id "doc-b-" "parenthesised?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "parenthesised?") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> boolean")) (div (@ (class "description")) (("checks if the string is enclosed by round brackets." (br) "also checks if every opening bracket is paired with a closing one after it")))) (div (@ (id "doc-b-" "regexp-match-replace") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "regexp-match-replace") " " (span (@ (class "first-sig")) "a replacements ->")) (div (@ (class "rest-sig")) (div "string ((regexp . string:replacement)/(regexp string:search-string . string:replacement) ...) -> string")) (div (@ (class "description")) (("replace strings inside string portions matched by regular expressions" (br) "the two part replacement element makes a simple replace," (br) "the three part version replaces search-string only inside matches with replacement")))) (div (@ (id "doc-b-" "regexp-replace") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "regexp-replace") " " (span (@ (class "first-sig")) "str regexp replacement ->")) (div (@ (class "rest-sig")) (div "string string/regexp string/procedure:{match-structure -> string} -> string")) (div (@ (class "description")) (("replace all occurences of regexp in string with replacement")))) (div (@ (id "doc-b-" "sph-string-description") (class "doc-b")) (div (span (@ (class "type")) "variable") ": " (span (@ (class "name")) "sph-string-description")) "" "") (div (@ (id "doc-b-" "string-ascii->utf8") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-ascii->utf8") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> string")) (div (@ (class "description")) (("convert an ascii string that has incorrectly coded utf8 chars to an utf8 string")))) (div (@ (id "doc-b-" "string-brackets-closed?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-brackets-closed?") " " (span (@ (class "first-sig")) "a start-char end-char ->")) (div (@ (class "rest-sig")) (div "string character character -> boolean")) (div (@ (class "description")) (("checks if every start-char in string has an end-char somewhere after it." (br) "this can be used to check if there are missing round brackets in a string." (br) "example: (string-brackets-closed? \\\"(ab (cd (e)) f)\\\" #\\\\( #\\\\))")))) (div (@ (id "doc-b-" "string-brackets-unclosed-count") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-brackets-unclosed-count") " " (span (@ (class "first-sig")) "a start-char end-char ->")) (div (@ (class "rest-sig")) (div "string character character -> integer:unclosed-count")) "") (div (@ (id "doc-b-" "string-camelcase->dash") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-camelcase->dash") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> string") (div "aA -> a-a") (div "aa aAa -> aa a-aa")) "") (div (@ (id "doc-b-" "string-camelcase->underscore") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-camelcase->underscore") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> string") (div "aA -> a-a") (div "aa aAa -> aa a-aa")) "") (div (@ (id "doc-b-" "string-case") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "string-case")) "" "") (div (@ (id "doc-b-" "string-compress-space") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-compress-space") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> string")) (div (@ (class "description")) (("replace multiple subsequent space characters with one space")))) (div (@ (id "doc-b-" "string-contains-all?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-contains-all?") " " (span (@ (class "first-sig")) "a b ->")) (div (@ (class "rest-sig")) (div "string (string ...) -> boolean")) (div (@ (class "description")) (("result in a boolean indicating if string contains all of the patterns")))) (div (@ (id "doc-b-" "string-contains-char?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-contains-char?") " " (span (@ (class "first-sig")) "a char ->")) (div (@ (class "rest-sig")) (div "string character -> boolean")) "") (div (@ (id "doc-b-" "string-contains-some?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-contains-some?") " " (span (@ (class "first-sig")) "a b ->")) (div (@ (class "rest-sig")) (div "string (string ...) -> boolean")) (div (@ (class "description")) (("result in a boolean indicating if string contains any of the patterns")))) (div (@ (id "doc-b-" "string-downcase-first") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-downcase-first") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> string") (div "AA -> aA") (div "Aa -> aa")) "") (div (@ (id "doc-b-" "string-drop-prefix") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-drop-prefix") " " (span (@ (class "first-sig")) "prefix a ->")) (div (@ (class "rest-sig")) (div "string string -> string")) "") (div (@ (id "doc-b-" "string-drop-prefix-if-exists") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-drop-prefix-if-exists") " " (span (@ (class "first-sig")) "prefix a ->")) (div (@ (class "rest-sig")) (div "string string -> string")) (div (@ (class "description")) (("remove prefix if string has prefix")))) (div (@ (id "doc-b-" "string-drop-suffix") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-drop-suffix") " " (span (@ (class "first-sig")) "suffix a ->")) (div (@ (class "rest-sig")) (div "string string -> string")) "") (div (@ (id "doc-b-" "string-drop-suffix-if-exists") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-drop-suffix-if-exists") " " (span (@ (class "first-sig")) "suffix a ->")) (div (@ (class "rest-sig")) (div "string string -> string")) (div (@ (class "description")) (("remove suffix if string has suffix")))) (div (@ (id "doc-b-" "string-each") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-each") " " (span (@ (class "first-sig")) "a b [c d] ->")) "" "") (div (@ (id "doc-b-" "string-enclose") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-enclose") " " (span (@ (class "first-sig")) "a enclose-str ->")) "" (div (@ (class "description")) (("append enclose-str to beginning and end of argument string")))) (div (@ (id "doc-b-" "string-equal?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-equal?") " " (span (@ (class "first-sig")) "a b [c d e f] ->")) "" "") (div (@ (id "doc-b-" "string-fill-left") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-fill-left") " " (span (@ (class "first-sig")) "a target-length character ->")) (div (@ (class "rest-sig")) (div "string character integer -> string")) (div (@ (class "description")) (("prepend character to the given string until the string length equals target-length." (br) "examples" (br) " (string-fill-left \\\"1\\\" #\\\\0 2) -> \\\"01\\\"" (br) " (string-fill-left \\\"10\\\" #\\\\0 2) -> \\\"10\\\"" (br) "string-fill-left-zeros")))) (div (@ (id "doc-b-" "string-fill-right") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-fill-right") " " (span (@ (class "first-sig")) "a target-length character ->")) "" "") (div (@ (id "doc-b-" "string-indices") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-indices") " " (span (@ (class "first-sig")) "a search-string ->")) (div (@ (class "rest-sig")) (div "string string -> (integer ...)")) (div (@ (class "description")) (("result in a list of indices at which search-string occurs in a string")))) (div (@ (id "doc-b-" "string-indices-char") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-indices-char") " " (span (@ (class "first-sig")) "a search-char ->")) (div (@ (class "rest-sig")) (div "string char -> (integer ...)")) (div (@ (class "description")) (("create a list of indices at which search-char occurs in a string")))) (div (@ (id "doc-b-" "string-join-tree") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-join-tree") " " (span (@ (class "first-sig")) "a delimiter ->")) (div (@ (class "rest-sig")) (div "(list/string ...) string -> string")) (div (@ (class "description")) (("same as (string-join (flatten a) delimiter)")))) (div (@ (id "doc-b-" "string-last-index") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-last-index") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> integer")) (div (@ (class "description")) (("get the last possible index of a string")))) (div (@ (id "doc-b-" "string-longest-prefix") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-longest-prefix") " " (span (@ (class "first-sig")) "a prefix-list ->")) (div (@ (class "rest-sig")) (div "string (string ...) -> string/boolean")) (div (@ (class "description")) (("result in the element of prefix-list that is the longest prefix of prefix-list in string \\\"a\\\"")))) (div (@ (id "doc-b-" "string-lowercase?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-lowercase?") " " (span (@ (class "first-sig")) "a ->")) "" (div (@ (class "description")) (("test if a string contains no uppercase characters")))) (div (@ (id "doc-b-" "string-matches-any-regexp?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-matches-any-regexp?") " " (span (@ (class "first-sig")) "a regexp-list ->")) (div (@ (class "rest-sig")) (div "string (regexp-object ...) -> boolean")) "") (div (@ (id "doc-b-" "string-matches-every-regexp?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-matches-every-regexp?") " " (span (@ (class "first-sig")) "a regexp-list ->")) (div (@ (class "rest-sig")) (div "string (regexp-object ...) -> boolean")) "") (div (@ (id "doc-b-" "string-multiply") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-multiply") " " (span (@ (class "first-sig")) "a n ->")) (div (@ (class "rest-sig")) (div "string integer -> string")) "") (div (@ (id "doc-b-" "string-numeric?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-numeric?") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> boolean")) (div (@ (class "description")) (("check if string is a valid scheme representation of a number")))) (div (@ (id "doc-b-" "string-octet-length") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-octet-length") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "string -> integer")) (div (@ (class "description")) (("the number of bytes of string, regardless of the character encoding, without terminator like \\\"null\\\"")))) (div (@ (id "doc-b-" "string-quote") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-quote") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "string-replace-char") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-replace-char") " " (span (@ (class "first-sig")) "a char replacement ->")) (div (@ (class "rest-sig")) (div "string character character -> string")) (div (@ (class "description")) (("replace all occurences of \\\"char\\\" in a string")))) (div (@ (id "doc-b-" "string-replace-chars") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-replace-chars") " " (span (@ (class "first-sig")) "a spec ->")) (div (@ (class "rest-sig")) (div "string ((char [replacements] ...) ...) -> string")) (div (@ (class "description")) (("replace chars in string with none, one or multiple chars")))) (div (@ (id "doc-b-" "string-replace-string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-replace-string") " " (span (@ (class "first-sig")) "a replace replacement ->")) (div (@ (class "rest-sig")) (div "string string string -> string")) (div (@ (class "description")) (("replace all occurences of string \\\"replace\\\" inside string \\\"a\\\" with string \\\"replacement\\\"." (br) "tests have shown it to be up to 28x times faster than regexp-substitute/global (guile2.06 22x, guile3 5.75-28x)." (br) "this procedure is quite nice to debug - comment out one or all string-copy! calls and" (br) "the result string will be a partial result")))) (div (@ (id "doc-b-" "string-replace-strings") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-replace-strings") " " (span (@ (class "first-sig")) "a strings-and-replacements ->")) (div (@ (class "rest-sig")) (div "string ((string:search . string:replacement) ...) -> string")) "") (div (@ (id "doc-b-" "string-skip-string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-skip-string") " " (span (@ (class "first-sig")) "a skip ->")) (div (@ (class "rest-sig")) (div "string string -> integer")) (div (@ (class "description")) (("skip over string \\\"skip\\\" at the beginning of a string and return the first index afterwards," (br) "or the first index 0 if skip string is not a prefix")))) (div (@ (id "doc-b-" "string-slice-at-words") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-slice-at-words") " " (span (@ (class "first-sig")) "a slice-length ->")) (div (@ (class "rest-sig")) (div "string integer -> (string ...)")) (div (@ (class "description")) (("split line into slices/chunks of size slice-length, unless it would split words (subsequent characters without the space character)," (br) "in which case the word is moved to the next slice. ignores newlines. can be used for single lines. can be used for \\\"text-wrapping\\\"." (br) "splits string at spaces, then uses the parts to build lines while checking if the line length with spaces would exceed slice-length." (br) "if yes, the exceeding part is moved to the next line")))) (div (@ (id "doc-b-" "string-split-regexp") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-split-regexp") " " (span (@ (class "first-sig")) "str regexp [handle-delim] ->")) (div (@ (class "rest-sig")) (div "string string [symbol:discard/concat] -> (string ...)")) (div (@ (class "description")) (("split string into a list of substrings delimited by a regular expression." (br) "1. all regexp matches are collected" (br) "2. substrings between matches are extracted")))) (div (@ (id "doc-b-" "string-trim-string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "string-trim-string") " " (span (@ (class "first-sig")) "a trim ->")) (div (@ (class "rest-sig")) (div "string string -> string")) (div (@ (class "description")) (("remove all occurences of string \\\"trim\\\" from the beginning of a string." (br) "like string-trim but with a trim-string instead of a character")))) (div (@ (id "doc-b-" "symbol?->string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "symbol?->string") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "any -> any")) (div (@ (class "description")) (("converts \\\"a\\\" to string only if it is a symbol, otherwise results in \\\"a\\\""))))))))))) ()))