2017-08-27

(sph string)

string processing. includes string-replace-string, a fast replacer

part of sph-lib

import name

(sph string)

exports

any->string

procedure

signature

a ->

any -> string

description

generalized string conversion function.

get the string representation for the value of an object.

symbols like "." are converted to "#{.}" using display.

any->string-display

procedure

signature

a ->

any->string-pretty-print

procedure

signature

a ->

any->string-write

procedure

signature

a ->

any->string-write*

procedure

signature

a ->

description

write converts symbols like "." to #{.}, this procedure avoids this

list->string-columns

procedure

signature

a #:justify #:separator #:max-width ->

(string ...) #:justify symbol:left/right #:separator string #:max-width integer -> string

description

create a string of equally sized columns containing elements of the string list "a", separated

by #:separator

parenthesise

procedure

signature

a ->

string -> string

description

surround string with an open and a closing parenthesis

regexp-match-replace

procedure

signature

a replacements ->

string ((regexp . string:replacement)/(regexp string:search-string . string:replacement) ...) -> string

description

replace strings inside string portions matched by regular expressions

the two part replacement element makes a simple replace,

the three part version replaces search-string only inside matches with replacement

regexp-replace

procedure

signature

str regexp replacement ->

string string/regexp string/procedure:{match-structure -> string} -> string

description

replace all occurences of regexp in string with replacement

sph-string-description

variable

string-ascii->utf8

procedure

signature

a ->

string -> string

description

convert an ascii string that has incorrectly coded utf8 chars to an utf8 string

string-camelcase->dash

procedure

signature

a ->

string -> string

aA -> a-a

aa aAa -> aa a-aa

string-camelcase->underscore

procedure

signature

a ->

string -> string

aA -> a-a

aa aAa -> aa a-aa

string-case

syntax

string-compress-space

procedure

signature

a ->

string -> string

description

replace multiple subsequent space characters with one space

string-contains-all?

procedure

signature

a b ->

string (string ...) -> boolean

description

result in a boolean indicating if string contains all of the patterns

string-contains-char?

procedure

signature

a char ->

string character -> boolean

string-contains-some?

procedure

signature

a b ->

string (string ...) -> boolean

description

result in a boolean indicating if string contains any of the patterns

string-downcase-first

procedure

signature

a ->

string -> string

AA -> aA

Aa -> aa

string-drop-prefix

procedure

signature

prefix a ->

string string -> string

string-drop-prefix-if-exists

procedure

signature

prefix a ->

string string -> string

description

remove prefix if string has prefix

string-drop-suffix

procedure

signature

suffix a ->

string string -> string

string-drop-suffix-if-exists

procedure

signature

suffix a ->

string string -> string

description

remove suffix if string has suffix

string-each

procedure

signature

proc string ->

string-enclose

procedure

signature

a enclose-str ->

description

append enclose-str to beginning and end of argument string

string-equal?

procedure

signature

a b [c d e f] ->

string-fill-left

procedure

signature

a target-length character ->

string character integer -> string

description

prepend character to the given string until the string length equals target-length.

examples

(string-fill-left "1" #

string-fill-right

procedure

signature

a target-length character ->

string-indices

procedure

signature

a search-string ->

string string -> (integer ...)

description

result in a list of indices at which search-string occurs in a string

string-indices-char

procedure

signature

a search-char ->

string char -> (integer ...)

description

create a list of indices at which search-char occurs in a string

string-join-tree

procedure

signature

a delimiter ->

(list/string ...) string -> string

description

same as (string-join (flatten a) delimiter)

string-last-index

procedure

signature

a ->

string -> integer

description

get the last possible index of a string

string-longest-prefix

procedure

signature

a prefix-list ->

string (string ...) -> string/boolean

description

result in the element of prefix-list that is the longest prefix from prefix-list in string "a"

string-lowercase?

procedure

signature

a ->

description

test if a string contains no uppercase characters

string-matches-any-regexp?

procedure

signature

a regexp-list ->

string (regexp-object ...) -> boolean

string-matches-every-regexp?

procedure

signature

a regexp-list ->

string (regexp-object ...) -> boolean

string-multiply

procedure

signature

a n ->

string integer -> string

string-numeric?

procedure

signature

a ->

string -> boolean

description

check if string is a valid scheme representation of a number

string-octet-length

procedure

signature

a ->

string -> integer

description

the number of bytes of string, regardless of the character encoding, without terminator like "null"

string-quote

procedure

signature

a ->

string-replace-char

procedure

signature

a char replacement ->

string character character -> string

description

replace all occurences of "char" in a string

string-replace-chars

procedure

signature

a spec ->

string ((char [replacements] ...) ...) -> string

description

replace chars in string with none, one or multiple chars

string-replace-string

procedure

signature

a replace replacement ->

string string string -> string

description

replace all occurences of string "replace" inside string "a" with string "replacement".

tests with guile 2.06 have shown it to be 22x faster than regexp-substitute/global

string-skip-string

procedure

signature

a skip ->

string string -> integer

description

skip over string "skip" at the beginning of a string and return the first index afterwards,

or the first index 0 if skip string is not a prefix

string-slice-at-words

procedure

signature

a slice-length ->

string integer -> (string ...)

description

split line into slices/chunks of size slice-length, unless it would split words (subsequent characters without the space character),

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"

string-split-regexp

procedure

signature

str regexp [handle-delim] ->

string string [symbol:discard/concat] -> (string ...)

description

split string into a list of substrings delimited by a regular expression.

string-trim-string

procedure

signature

a trim ->

string string -> string

description

remove all occurences of string "trim" from the beginning of a string.

like string-trim but with a trim-string instead of a character

symbol?->string

procedure

signature

a ->

any -> any

description

converts "a" to string only if it is a symbol, otherwise results in "a"


tags: programming guile documentation library scheme sph-lib string sph-string