Common Lisp Package: COM.INFORMATIMAGO.COMMON-LISP.CESARUM.STRING

This package exports some string processing functions. License: AGPL3 Copyright Pascal J. Bourguignon 2002 - 2012 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/>

README:

FUNCTION

Public

CONCATENATE-STRINGS (LIST-OF-STRINGS)

LIST-OF-STRINGS: Each element may be either a string, or a list containing a string, and a start and end position denoting a substring. RETURN: A string containing the concatenation of the strings of the LIST-OF-STRINGS.

EXPLODE-STRING (STRING &OPTIONAL (RESULT-TYPE 'LIST))

RETURN: A new sequence containing the character in the sequence string. RESULT-TYPE: A sequence type accepted by MAP. Default: LIST.

IMPLODE (CHAR-SEQ &OPTIONAL (RESULT-TYPE 'SYMBOL) (PACKAGE *PACKAGE*))

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 (CHAR-SEQ)

RETURN: A new string containing the characters in the sequence CHAR-SEQ.

LOCALIZE (TABLE LANGUAGE TEXT)

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

PREFIXP (PREFIX STRING &KEY (START 0) (END NIL) (TEST #'CHAR=))

PREFIX: A sequence. STRING: A sequence. START: The start of the substring of STRING to consider. Default: 0. END: The end of the substring of STRING to consider. Default: NIL. TEST: A function to compare the elements of the strings. RETURN: Whether PREFIX is a prefix of the (substring STRING START END).

SPLIT-ESCAPED-STRING (STRING ESCAPE SEPARATOR)

DO: Split the string on the separator character. It may be escaped with the escape character. RETURN: A list of substrings of string.

SPLIT-NAME-VALUE (STRING)

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 NIL))

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-JUSTIFY-LEFT (STRING &OPTIONAL (WIDTH 72) (LEFT-MARGIN 0) (SEPARATORS #( )))

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 LEFT))

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 #'CHAR=))

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 0) (END NIL) (TEST #'CHAR=))

SUFFIX: A sequence. STRING: A sequence. START: The start of the substring of STRING to consider. Default: 0. END: The end of the substring of STRING to consider. Default: NIL. TEST: A function to compare the elements of the strings. RETURN: Whether SUFFIX is a suffix of the (substring STRING START END).

UNSPLIT-STRING (STRING-LIST &OPTIONAL (SEPARATOR ) &KEY (ADJUSTABLE NIL) (FILL-POINTER NIL) (SIZE-INCREMENT 0))

DO: The inverse than split-string. If no separator is provided then a simple space is used. SEPARATOR: (OR NULL 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.

Private

Undocumented

TEST/IMPLODE-EXPLODE

MACRO

Public

DEFTRANSLATION (TABLE TEXT LANGUAGE TRANSLATION &REST LANGS-TRANS)

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

GENERIC-FUNCTION

Public

EXPLODE (OBJECT &OPTIONAL RESULT-TYPE)

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).