cl-str

API Reference

str

Modern, consistent and terse Common Lisp string manipulation library.

STR

  • Variable *IGNORE-CASE*
    nil
  • Variable *OMIT-NULLS*
    nil
  • Variable +VERSION+
    "0.8"
  • Function VERSION
  • Function TRIM-LEFT (s)
    Remove whitespaces at the beginning of s.
  • Function TRIM-RIGHT (s)
    Remove whitespaces at the end of s.
  • Function TRIM (s)
    Remove whitespaces at the beginning and end of s. @begin[lang=lisp](code) (trim " foo ") ;; => "foo" @end(code)
  • Function CONCAT (&rest strings)
    Join all the string arguments into one string.
  • Function JOIN (separator strings)
  • Function SPLIT (separator s &key (omit-nulls *omit-nulls*))
    Split s into substring by separator (cl-ppcre takes a regex, we do not).
  • Function SPLIT-OMIT-NULLS (separator s)
    Call split with :omit-nulls to t. Can be clearer in certain situations.
  • Function SUBSTRING (start end s)
    Return the substring of `s' from `start' to `end'. It uses `subseq' with differences: - argument order, s at the end - `start' and `end' can be lower than 0 or bigger than the length of s. - for convenience `end' can be nil or t to denote the end of the string.
  • Variable *ELLIPSIS*
    "..."
    Ellipsis to add to the end of a pruned (truncated) string.
  • Function PRUNE (len s &key (ellipsis *ellipsis*))
    If s is longer than `len', truncate it to this length and add an ellipsis at the end ("..." by default). Cut it down to `len' minus the length of the ellipsis.
  • Function WORDS (s &key (limit 0))
    Return list of words, which were delimited by white space. If the optional limit is 0 (the default), trailing empty strings are removed from the result list (see cl-ppcre).
  • Function UNWORDS (strings)
    Join the list of strings with a whitespace.
  • Function LINES (s &key (omit-nulls *omit-nulls*))
    Split the string by newline characters and return a list of lines.
  • Function UNLINES (strings)
    Join the list of strings with a newline character.
  • Function REPEAT (count s)
    Make a string of S repeated COUNT times.
  • Function REPLACE-ALL (old new s)
    Replace `old` by `new` in `s`. Arguments are not regexs.
  • Function EMPTY? (s)
    Is s nil or the empty string ?
  • Function EMPTYP (s)
    Is s nil or the empty string ?
  • Function BLANK? (s)
    Is s nil or only contains whitespaces ?
  • Function BLANKP (s)
    Is s nil or only contains whitespaces ?
  • Function STARTS-WITH? (start s &key (ignore-case *ignore-case*))
    Return t if s starts with the substring 'start', nil otherwise.
  • Function ENDS-WITH? (end s &key (ignore-case *ignore-case*))
    Return t if s ends with the substring 'end', nil otherwise.
  • Function CONTAINS? (substring s &key (ignore-case *ignore-case*))
    Return `t` if `s` contains `substring`, nil otherwise. Ignore the case with `:ignore-case t`. A simple call to the built-in `search` (which returns the position of the substring).
  • Function PREFIX (items)
    Find the common prefix between strings. Uses the built-in `mismatch', that returns the position at which the strings fail to match. Example: `(str:prefix '("foobar" "foozz"))` => "foo" - items: list of strings - Return: a string.
  • Function COMMON-PREFIX (items)
  • Function SUFFIX (items)
    Find the common suffix between strings. Uses the built-in `mismatch', that returns the position at which the strings fail to match. Example: `(str:suffix '("foobar" "zzbar"))` => "bar" - items: list of strings - Return: a string.
  • Function PREFIX? (items s)
    Return s if s is common prefix between items.
  • Function SUFFIX? (items s)
    Return s if s is common suffix between items.
  • Function ADD-PREFIX (items s)
    Prepend s to the front of each items.
  • Function ADD-SUFFIX (items s)
    Append s to the end of eahc items.
  • Function FROM-FILE (pathname &rest keys)
    Read the file and return its content as a string. From v0.7 simply uses uiop:read-file-string. There is also read-file-lines. Example: (str:from-file "path/to/file.txt" :external-format :utf-8) - external-format: if nil, the system default. Can be bound to :utf-8.
  • Function TO-FILE (pathname s &key (if-exists :supersede) (if-does-not-exist :create))
    Write string `s' to file `pathname'. If the file does not exist, create it (use `:if-does-not-exist'), if it already exists, replace its content (`:if-exists'). Returns the string written to file.
  • Macro STRING-CASE (str &rest forms)
    A case-like macro that works with strings (case works only with symbols). Example: (str:string-case input ("foo" (do something)) (nil (print "input is nil") (otherwise (print "none of the previous forms was caught"))) You might also like pattern matching. The example below with optima is very similar: (optima:match "hey" ("hey" (print "it matched")) (otherwise :nothing)) Note that there is also http://quickdocs.org/string-case/.
  • Function S-FIRST (s)
    Return the first substring of `s'.
  • Function S-REST (s)
    Return the rest substring of `s'.
  • Function S-NTH (n s)
    Return the nth substring of `s'. You could also use (string (elt "test" 1)) ;; => "e"

str.test

Test suite for cl-str.

No packages.