Package COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STRING


This package exports some string processing functions.


License:

    AGPL3

    Copyright Pascal J. Bourguignon 2002 - 2015

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.
    If not, see <http://www.gnu.org/licenses/>

character-designator
type
CHARACTER-DESIGNATOR is the type of character or designators of
                     strings of length 1.

CHARACTER-DESIGNATOR-P

(concatenate-strings list-of-string-designators)
function
LIST-OF-STRING-DESIGNATORS:
                 EACH element may be either a string-designator or a list of characters,
                 or a list containing a string-designator or a list of character,
                 and a start and end position denoting a substring.

RETURN:          A string containing the concatenation of the strings
                 of the LIST-OF-STRINGS.
(deftranslation table text language translation &rest langs-trans)
macro
DO:             Define a translation table.
TABLE:          A symbol naming a variable to be bound to the
                translation table (with defvar).
TEXT:           A string containing the localizable text.
LANGUAGE:       A keyword denoting a language.
TRANSLATION:    A translation of the TEXT in the LANGUAGE.
LANGS-TRANS:    Other couples language translation.
EXAMPLE:        (deftranslation *words* "car" :fr "automobile"
                                                :es "coche")
                (localize *words* :fr "car")
                --> "automobile"
SEE ALSO:       LOCALIZE
(explode object &optional result-type)
generic-function
RETURN:         A sequence of character of type RESULT-TYPE containing
                the character of the OBJECT.
RESULT-TYPE:    A sequence type accepted by MAP (not NIL). Default: LIST.
OBJECT:         Can be a string, a symbol (its symbol-name is exploded),
                or a random object (its prin1 representation is exploded).
(explode-string character-designators &optional result-type)
function
RETURN:         A new sequence of type RESULT-TYPE, containing the
                characters in the sequence CHARACTER-DESIGNATORS.
RESULT-TYPE:    A sequence type accepted by MAP.  Default: LIST.
(implode char-seq &optional result-type package)
function
RETURN:         An object of type RESULT-TYPE made with the character
                in the CHAR-SEQ sequence. Default: SYMBOL.
RESULT-TYPE:    SYMBOL (default), or STRING, or another type, in which
                case the object is obtained from reading from the
                string obtained from the implosion of the characters
                CHAR-SEQ.
PACKAGE:        When RESULT-TYPE is SYMBOL, then the package where the
                symbol is interned. Default: *PACKAGE*.
(implode-string character-designators)
function
RETURN: A new string containing the characters in the sequence CHARACTER-DESIGNATORS.
NOTE:   (implode-string cds) == (explode-string cds 'string)
(localize table language text)
function
RETURN:     A version of the TEXT in the given LANGUAGE,
            or in english if LANGUAGE is not found,
            or TEXT itself if none found.
SEE ALSO:   DEFTRANSLATION
(mixed-case-p string-designator)
function
RETURN:         Whether the string denoted by STRING-DESIGNATOR
                contains both upper case characters and lower case
                characters.  If there are characters that are
                both-case-p, then mixed-case-p returns true.
(no-lower-case-p string-designator)
function
RETURN:         Whether the string denoted by STRING-DESIGNATOR
                contains no lower case character.
(no-upper-case-p string-designator)
function
RETURN:         Whether the string denoted by STRING-DESIGNATOR
                contains no upper case character.
(prefixp prefix sequence &key start end test)
generic-function
PREFIX:  A sequence designator.
STRING:  A sequence designator.
START:   The start of the subsequence of SEQUENCE to consider. Default: 0.
END:     The end   of the subsequence of SEQUENCE to consider. Default: NIL.
TEST:    A function to compare the elements of the SEQUENCE.
RETURN:  Whether PREFIX is a prefix of the (subseq SEQUENCE START END).
(split-escaped-string string-designator escape separator)
function
STRING-DESIGNATOR:  A string designator.
ESCAPE:             A character designator.
SEPARATOR:          A character designator.
DO:                 Split the STRING-DESIGNATOR on the SEPARATOR
                    character.  It may be escaped with the ESCAPE
                    character, in which case it's not split.
RETURN:             A list of substrings of the string denoted by
                    STRING-DESIGNATOR.
(split-name-value string)
function
RETURN:  a cons with two substrings of string such as:
         (string= (concat (car res) "=" (cdr res)) string)
         and (length (car res)) is minimum.
(split-string string &optional separators remove-empty)
function
STRING:         A sequence.

SEPARATOR:      A sequence.

RETURN:         A list of subsequence of STRING, split upon any element of SEPARATORS.
                Separators are compared to elements of the STRING with EQL.

NOTE:           It's actually a simple split-sequence now.

EXAMPLES:       (split-string '(1 2 0 3 4 5 0 6 7 8 0 9) '(0))
                --> ((1 2) (3 4 5) (6 7 8) (9))
                (split-string #(1 2 0 3 4 5 0 6 7 8 0 9) #(0))
                --> (#(1 2) #(3 4 5) #(6 7 8) #(9))
                (split-string "1 2 0 3 4 5 0 6 7 8" '(#space #0))
                --> ("1" "2" "" "" "3" "4" "5" "" "" "6" "7" "8")
string-designator
type
STRING-DESIGNATOR       is the type of string designators.
(STRING-DESIGNATOR n)  is the type of string designators of strings of length n.

NOTE:    characters are all designators of strings of length 1,
         therefore (STRING-DESIGNATOR n) with n/=1 doesn't designate a
         CHARACTER.

STRING-DESIGNATOR-P

(string-justify-left string &optional width left-margin separators)
function
RETURN:         A left-justified string built from string.

WIDTH:          The maximum width of the generated lines.  Default is 72 characters.

LEFT-MARGIN:    The left margin, filled with spaces.  Default is 0 characters.

SEPARATORS:     A sequence containing the characters on which to split the words.
                Default: #(#space #newline).
(string-pad string length &key padchar justification)
function
PADCHAR:        A character designator (string, symbol or chararcter).
JUSTIFICATION:  :LEFT, :CENTER, or :RIGHT where to place the string.
DO:             Append the PADCHAR before, after or at both end of string
                to pad it to length.
RETURN:         A padded string.
(string-replace string pattern replace &key test)
function
RETURN:   A string build from STRING where all occurences of PATTERN
          are replaced by the REPLACE string.
TEST:     The function used to compare the elements of the PATTERN
          with the elements of the STRING.
(suffixp suffix string &key start end test)
generic-function
SUFFIX:  A sequence designator.
STRING:  A sequence designator.
START:   The start of the subsequence of SEQUENCE to consider. Default: 0.
END:     The end   of the subsequence of SEQUENCE to consider. Default: NIL.
TEST:    A function to compare the elements of the SEQUENCE.
RETURN:  Whether SUFFIX is a suffix of the (subseq SEQUENCE START END).
(unsplit-string string-list separator &key adjustable fill-pointer size-increment)
function
DO:             The inverse than split-string.
SEPARATOR:      (OR STRINGP CHARACTERP)
ADJUSTABLE:     Create the string as an adjustable array.
FILL-POINTER:   Add a fill pointer to the string.
SIZE-INCREMENT: Add it to the size needed for the result.