PSC Code Manual

util/string.lsp [src]

String functions

Functions

Function signature Description
(begins-with str pattern) Returns nil unless STR begins with PATTERN
(ends-with str pattern) Returns nil unless STR ends with PATTERN
(escape-newlines str) Returns STR with newlines escaped
(escape-quotes str) Returns STR with double-quotes escaped
(escape-url url) Substitutes HTML escapes for problematic characters
(first-line str) Returns the first line of STR
(increment-mark mark) Return the next string in spreadsheet column order
(lowercase str) Returns STR in lowercase
(strbreak str) Returns a list of single character strings comprising STR
(string-subst-all new old str) Uses vl-string-subst repeatedly to substitute all occurrences of OLD for NEW in STR
(stringp x) Returns nil if X is not string
(strjoin str-list delimiter) Concatenates strings in STR-LIST with DELIMITER
(strsplit str delimiter) Splits STR on a DELIMITER
(uppercase str) Returns STR in uppercase
(wcmatch-escape str) Escapes special characters in STR for use in wcmatch

(begins-with str pattern)

Returns nil unless STR begins with PATTERN

VARS:
(STR STR)
(PATTERN STR)

TESTS:
(BEGINS-WITH "hello" "h")
(BEGINS-WITH "hello" "")
(NOT (BEGINS-WITH "hello" "a"))

(ends-with str pattern)

Returns nil unless STR ends with PATTERN

VARS:
(STR STR)
(PATTERN STR)

TESTS:
(ENDS-WITH "hello" "o")
(ENDS-WITH "hello" "")
(NOT (ENDS-WITH "hello" "a"))

(escape-newlines str)

Returns STR with newlines escaped

VARS:
(STR STR)

TESTS:
(= (ESCAPE-NEWLINES "hi") "hi")
(= (ESCAPE-NEWLINES "item1
item2") "item1\nitem2")

(escape-quotes str)

Returns STR with double-quotes escaped

VARS:
(STR STR)

(escape-url url)

Substitutes HTML escapes for problematic characters

VARS:
(URL STR)

(first-line str)

Returns the first line of STR

VARS:
(STR STR)

TESTS:
(= (FIRST-LINE "hi") "hi")
(= (FIRST-LINE "item1
item2") "item1")

(increment-mark mark)

Return the next string in spreadsheet column order

VARS:
(MARK STR)

TESTS:
(= (INCREMENT-MARK "A") "B")
(= (INCREMENT-MARK "Z") "AA")
(= (INCREMENT-MARK "ZZ") "AAA")

(lowercase str)

Returns STR in lowercase

VARS:
(STR STR)

TESTS:
(= (LOWERCASE "hi") "hi")
(= (LOWERCASE "HI") "hi")

(strbreak str)

Returns a list of single character strings comprising STR

VARS:
(STR STR)

TESTS:
(EQUAL (STRBREAK "hi") '("h" "i"))
(= (STRBREAK "") nil)

(string-subst-all new old str)

Uses vl-string-subst repeatedly to substitute all occurrences of OLD for NEW in STR

VARS:
(NEW STR)
(OLD STR)
(STR STR)

TESTS:
(= (STRING-SUBST-ALL "hello" "hi" "hi hi") "hello hello")

(stringp x)

Returns nil if X is not string

TESTS:
(STRINGP "hello")
(NOT (STRINGP 1))

(strjoin str-list delimiter)

Concatenates strings in STR-LIST with DELIMITER

Example:

(strjoin '("hello" "world") ", ")

returns the string "hello, world".

VARS:
(STR-LIST nil (LISTP STR-LIST) (VL-EVERY 'STRINGP STR-LIST))
(DELIMITER STR)

TESTS:
(= (STRJOIN '("key" "val") "=") "key=val")
(= (STRJOIN '("hello" "world") ", ") "hello, world")

(strsplit str delimiter)

Splits STR on a DELIMITER

Example:

(strsplit "hello, world" ", ")

returns the list ("hello" "world").

VARS:
(STR STR)
(DELIMITER STR)

TESTS:
(EQUAL (STRSPLIT "key=val" "=") '("key" "val"))
(EQUAL (STRSPLIT "hello, world" ", ") '("hello" "world"))

(uppercase str)

Returns STR in uppercase

TESTS:
(= (UPPERCASE "HI") "HI")
(= (UPPERCASE "hi") "HI")

(wcmatch-escape str)

Escapes special characters in STR for use in wcmatch

VARS:
(STR STR)

TESTS:
(= (WCMATCH-ESCAPE "what # is 1*1?") "what `# is 1`*1`?")
(= (WCMATCH-ESCAPE "backtick[`]@my-mail.com~") "backtick`[```]`@my`-mail`.com`~")