string

File string.str
Author Eelco Visser <visser@acm.org>
Since unknown

This module contains strategies for operating on strings.

In Stratego, strings are primitive terms, separate from charactersand character lists. It is recommended that all strings contain onlyISO-8859-1 (Latin1) characters.




Statistics


General
Lines of code 1270
Stratego
Module number 1 (100% documented)
Constructor number 0
Overlay number 0
Strategy number 103 (89% documented)
Rule number 32 (100% documented)
DynamicRule number 0



Strategy summary


align-helper(ATerm c, ATerm n) n/a string.str
all-lines(Strategy s) Applies a strategy to all lines in a string string.str
case-char(Strategy s) Applies a strategy to the upper-case variants of two characters string.str
cify n/a string.str
conc-strings Concats a tuple of two Strings string.str
concat-strings Concats a list of Strings string.str
copy-char n/a string.str
div2 n/a string.str
double-quote Adds double quotes to the start and end of a string string.str
double-quote-chars Adds double quotes to the start and end of a list of characters string.str
escape Escapes double quotes, backslash and linefeed to C like escape sequences string.str
Escape n/a string.str
escape-chars Escapes double quotes, backslash and linefeed to C like escape sequences string.str
explode-string Explodes a String to a list of chars string.str
get-lines Gets all newline(\n, \r\n or \r)-separated lines in a string string.str
implode-string Implodes a list of chars to a string string.str
indent-text(ATerm n) Indents every line in a string with spaces string.str
is-alpha Succeeds if the character is part of the lowercase or uppercase alphabet string.str
is-alphanum n/a string.str
is-ascii Succeeds if this string only contains printable ASCII characters string.str
is-char Predicate that checks if the supplied term is a printable character string.str
is-double-quoted n/a string.str
is-double-quoted-chars Predicate that checks if a character list is double quoted string.str
is-hexnum Succeeds if applied to a character that is a hexidecimal digit, i string.str
is-lower Succeeds if this character is lower-case string.str
is-num n/a string.str
is-quoted(ATerm c) Predicate that checks if a string is quoted with the given character string.str
is-quoted-chars(ATerm c) Predicate that checks if a list of characters is quoted with the character given by the term argument string.str
is-single-quoted Predicate that checks a string is quoted with single quotes string.str
is-single-quoted-chars Predicate that checks if a character list is single quoted string.str
is-string Predicate that checks if the supplied term is a string string.str
is-substring(Strategy s) Succeeds if the string produced by s is a substring of the argument string string.str
is-upper Succeeds if this character is upper-case string.str
is-whitespace Succeeds if the character is whitespace string.str
left-match Succeeds if the first list of terms starts with the second list of terms string.str
lines Makes one newline-separated string out of a list of strings string.str
lower-case Converts all characters of this string to lower case string.str
lower-case-chars Converts a list of characters to lower case string.str
ltrim-chars(Strategy s) Trims leading characters from a string string.str
new Generates a unique new string of the form 'c_d', where c is one char and d is a positive integer string.str
newname Generates a unique new string with user-defined prefix the form 'sd', where s is a string and d is a positive integer string.str
padd-with(Strategy s) n/a string.str
prefix-lines(ATerm p) Prefixes all lines in a string with a string string.str
quote(Strategy c) n/a string.str
quote-chars(Strategy c) n/a string.str
right-match Succeeds if the first list of terms ends with the second list of terms string.str
rtrim-chars(Strategy s) Trims trailing characters from a string string.str
shuffle-forced n/a string.str
single-quote n/a string.str
single-quote-chars Adds single quotes to the start and end of a list of characters string.str
split-after n/a string.str
split-at-dot n/a string.str
split-at-space Splits a string at each occurrence of a whitespace string.str
split-before n/a string.str
strcasecmp Compares two lists of characters lexicographically, ignoring case string.str
strcat Concats a tuple of two Strings string.str
strcmp n/a string.str
string-as-chars(Strategy s) Wraps a strategy on a list of chars in a strategy on a string string.str
string-ends-with(ATerm end) Succeeds if the first String ends with the second String string.str
string-gt Compares two strings or lists of characters lexicographically and succeeds if the first one is larger than the second, ignoring case string.str
string-length Returns the number of characters in a string string.str
string-lt Compares two strings or lists of characters lexicographically and succeeds if the first one is smaller than the second, ignoring case string.str
string-replace(ATerm old, ATerm new) n/a string.str
string-sort n/a string.str
string-sort-desc Sorts a list of strings lexicographically ignoring case, descending string.str
string-starts-with(ATerm start) Succeeds if the first String starts with the second String string.str
string-tokenize(ATerm sepchars) Breaks a string into tokens string.str
string-tokenize n/a string.str
string-tokenize-keep-all(ATerm sepChars) Splits a string into a list of tokens, keeping the separating elements as 1-char-strings within the results list, *and* also keeping the empty "" tokens string.str
string-tokenize-keep-empty(ATerm sepChars) Splits a string into a list of tokens, including the empty ones string.str
strlen Returns the number of characters in a string string.str
strncmp Compares the n first characters of two character lists, n is given by the last argument string.str
to-lower Ensures that a character is lower-case string.str
to-upper Ensures that a character is upper-case string.str
trim-chars(Strategy s) Trims leading and trailing characters from a string string.str
trim-leading-whitespace Trims all leading whitespace in a (single-line) string string.str
trim-trailing-whitespace Trims all trailing whitespace in a (single-line) string string.str
trim-whitespace Trims all trailing and leading whitespace in a (single-line) string string.str
un-double-quote Removes double quotes from the start and end of a string Fails if the string is not properly quoted string.str
un-double-quote-chars Removes double quotes from the start and end of a list of characters string.str
un-single-quote Removes single quotes from the start and end of a string Fails if the string is not properly quoted string.str
un-single-quote-chars Removes single quotes from the start and end of a list of characters string.str
unescape Unescapes double quotes, backslash, linefeed and tabs string.str
UnEscape n/a string.str
unescape-chars(Strategy s) Unescapes characters using a specified unescape strategy string.str
unescape-chars Unescapes double quotes, backslash, linefeed and tabs string.str
unquote(Strategy s) Removes the first and last character of a string string.str
unquote(Strategy s1, Strategy s2) Removes the first and last character of a string string.str
unquote-chars(Strategy s) Removes the first and last character of a list of characters string.str
unquote-chars(Strategy s1, Strategy s2) Removes the first and last character of a list of characters string.str
upper-case Converts all characters of this string to upper case string.str
upper-case-chars Converts a list of characters to upper case string.str

Rule summary


align-center n/a string.str
align-left n/a string.str
align-right n/a string.str
quote-chars n/a string.str



Strategy details


ATerm align-helper(ATerm c, ATerm n)
File string.str
Author unknown
Since unknown
 
Parameters
ATerm c c Char
ATerm n n Int

No information available.


type String -> String

 
ATerm all-lines(Strategy s)
File string.str
Author unknown
Since 0.9.4
 
Parameters
Strategy s The strategy that should be applied to each line.

Applies a strategy to all lines in a string.

Lines are expected to be separated by a single '\n'.The last line may be ended by a newline, or not. In the former case, thelast line in the resulting string will also be ended by a newline,otherwise not.Initial or intermediate newlines are preserved.The strategy is applied to each line (even the empty ones), *excluding*the newline character. The newline is appended again after application of s


type s string -> string
type string -> string

 
ATerm case-char(Strategy s)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s (Char, Char) -> a

Applies a strategy to the upper-case variants of two characters.

This is useful for doing case-insenstive operations.


type (Char, Char) -> a

 
ATerm cify
File string.str
Author unknown
Since unknown
 

No information available.



 
ATerm conc-strings
File string.str
Author unknown
Since unknown
 

Concats a tuple of two Strings.


type String * String -> String

 
ATerm concat-strings
File string.str
Author unknown
Since unknown
 

Concats a list of Strings


type List(String) -> String

 
ATerm double-quote
File string.str
Author unknown
Since unknown
 

Adds double quotes to the start and end of a string.


type String -> String

 
ATerm double-quote-chars
File string.str
Author unknown
Since unknown
 

Adds double quotes to the start and end of a list of characters.


type List(Char) -> List(Char)

 
ATerm escape
File string.str
Author unknown
Since unknown
 

Escapes double quotes, backslash and linefeed to C like escape sequences.


type String -> String

 
ATerm Escape
File string.str
Author unknown
Since unknown
 

No information available.


type List(Char) -> List(Char)

 
ATerm escape-chars
File string.str
Author unknown
Since unknown
 

Escapes double quotes, backslash and linefeed to C like escape sequences.


type List(Char) -> List(Char)

 
ATerm explode-string
File string.str
Author unknown
Since unknown
 

Explodes a String to a list of chars.


type String -> List(Char)

 
ATerm get-lines
File string.str
Author unknown
Since 0.9.4
 

Gets all newline(\n, \r\n or \r)-separated lines in a string.If the string is ended by a newline, the last element of the returned listis the empty string.


type string -> [string]

 
ATerm implode-string
File string.str
Author unknown
Since unknown
 

Implodes a list of chars to a string.


type List(Char) -> String

 
ATerm indent-text(ATerm n)
File string.str
Author unknown
Since 0.9.4
 
Parameters
ATerm n The number of spaces to be put in front of every line.

Indents every line in a string with spaces.


type n int
type string -> string

 
ATerm is-alpha
File string.str
Author unknown
Since unknown
 

Succeeds if the character is part of the lowercase oruppercase alphabet.


type Char -> Char

 
ATerm is-alphanum
File string.str
Author unknown
Since unknown
 

No information available.



 
ATerm is-ascii
File string.str
Author unknown
Since unknown
 

Succeeds if this string only contains printable ASCII characters.

The letters 32 through 126, in total 96 characters, are definedas printable.


type Char -> Char

 
ATerm is-char
File string.str
Author unknown
Since unknown
 

Predicate that checks if the supplied term is a printable character.


type Char -> Char

 
ATerm is-double-quoted-chars
File string.str
Author unknown
Since unknown
 

Predicate that checks if a character list is double quoted. Thatis, if the first and last character are both double quotes.


type List(Char) -> List(Char)

 
ATerm is-hexnum
File string.str
Author unknown
Since unknown
 

Succeeds if applied to a character that is a hexidecimaldigit, i.e. either of the characters in the range '0'-'9'or 'A'-'F' or 'a'-'f'.


type Char -> Char

 
ATerm is-lower
File string.str
Author unknown
Since unknown
 

Succeeds if this character is lower-case.


type Char -> Char

 
ATerm is-num
File string.str
Author unknown
Since unknown
 

No information available.



 
ATerm is-quoted(ATerm c)
File string.str
Author unknown
Since unknown
 
Parameters
ATerm c Char

Predicate that checks if a string is quoted with the given character.

The character c is the quotation character to check for.


type String -> String

 
ATerm is-quoted-chars(ATerm c)
File string.str
Author unknown
Since unknown
 
Parameters
ATerm c Char

Predicate that checks if a list of characters is quoted withthe character given by the term argument. That is, if thefirst and last character of the list are both equal to c.


type List(Char) -> List(Char)

 
ATerm is-single-quoted
File string.str
Author unknown
Since unknown
 

Predicate that checks a string is quoted with single quotes.


type String -> String

 
ATerm is-single-quoted-chars
File string.str
Author unknown
Since unknown
 

Predicate that checks if a character list is single quoted. That is,if the first and last character are both single quotes.


type List(Char) -> List(Char)

 
ATerm is-string
File string.str
Author unknown
Since unknown
 

Predicate that checks if the supplied term is a string.


type String -> String

 
ATerm is-substring(Strategy s)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s _ -> String

Succeeds if the string produced by s is a substringof the argument string.


type String -> _

 
ATerm is-upper
File string.str
Author unknown
Since unknown
 

Succeeds if this character is upper-case.


type Char -> Char

 
ATerm is-whitespace
File string.str
Author unknown
Since 0.9.5
 

Succeeds if the character is whitespace.

Whitespace is a space (32), or a tab (9)


type Char -> Char

 
ATerm left-match
File string.str
Author unknown
Since unknown
 

Succeeds if the first list of terms starts with the second list of terms.

Returns the suffix of the first list that is not matched.


type (List(a), List(a)) -> List(a)

 
ATerm lines
File string.str
Author unknown
Since 0.9.4
 

Makes one newline-separated string out of a list of strings.



 
ATerm lower-case
File string.str
Author unknown
Since unknown
 

Converts all characters of this string to lower case


type String -> String

 
ATerm lower-case-chars
File string.str
Author unknown
Since unknown
 

Converts a list of characters to lower case.

Example: <explode-string ; lower-case-char ; implode-string> "STRATEGO" => "stratego"


type List(Char) -> List(Char)

 
ATerm ltrim-chars(Strategy s)
File string.str
Author unknown
Since 0.9.5
 
Parameters
Strategy s should match all characters to be removed

Trims leading characters from a string. The characters to to trim are given by the strategy argument.

Removes from the left-hand side all characters matched bystrategy s.

Example: <ltrim-chars(?' ')> " fred " => "fred "


type String -> String

 
ATerm new
File string.str
Author unknown
Since unknown
 

Generates a unique new string of the form 'c_d',where c is one char and d is a positive integer.



 
ATerm newname
File string.str
Author unknown
Since unknown
 

Generates a unique new string with user-defined prefixthe form 'sd', where s is a string and d is a positive integer.The produced string is *always* unique across a program run.

The prefix comes in front of an increasing number, which isseparately maintained and started at 0 for each prefix.

Examples (results are shown in comment)<newname; debug> "a" // produces "a0"; <newname; debug> "a" // produces "a1"; <newname; debug> "a" // produces "a2"; <newname; debug> "b" // produces "b0"; <newname; debug> "b" // produces "b1"; <newname; debug> "b_2" // produces "b_20"; <newname; debug> "b_2" // produces "b_21"; <newname; debug> "b_a" // produces "b_a0"; <newname; debug> "b_a" // produces "b_a1"; <newname; debug> "a_" // produces "a_0"; <newname; debug> "a_1" // produces "a_10"



 
ATerm padd-with(Strategy s)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s s () -> Char

No information available.


type String * Int -> String

 
ATerm prefix-lines(ATerm p)
File string.str
Author unknown
Since 0.9.4
 
Parameters
ATerm p The prefix.

Prefixes all lines in a string with a string.


type p string
type string -> string

 
ATerm right-match
File string.str
Author unknown
Since unknown
 

Succeeds if the first list of terms ends with the second list of terms.

Returns the prefix of the first list that is not matched.


type (List(a), List(a)) -> List(a)

 
ATerm rtrim-chars(Strategy s)
File string.str
Author unknown
Since 0.9.5
 
Parameters
Strategy s should match on all characters to be removed

Trims trailing characters from a string.

Removes from the right-hand side all characters matched bystrategy s.

Example: <rtrim-chars(?' ')> " fred " => " fred"


type String -> String

 
ATerm single-quote
File string.str
Author unknown
Since unknown
 

No information available.



 
ATerm single-quote-chars
File string.str
Author unknown
Since unknown
 

Adds single quotes to the start and end of a listof characters.


type List(Char) -> List(Char)

 
ATerm split-at-dot
File string.str
Author unknown
Since unknown
 

No information available.



 
ATerm split-at-space
File string.str
Author unknown
Since unknown
 

Splits a string at each occurrence of a whitespace. Theresulting list of string does not contain any of thewhitespaces. Two adjacent whitespaces will result inan empty string in the result.

Example: <split-at-space> "foo bar" => ["foo", "", "bar"]


type String -> List(String)

 
ATerm strcasecmp
File string.str
Author unknown
Since unknown
 

Compares two lists of characters lexicographically, ignoring case.

Returns:-1 if first is smaller than the second.0 if the strings are equal.1 if the first is larger than the second.


type (List(Char), List(Char)) -> -1, 0,1 or -1.

 
ATerm strcat
File string.str
Author unknown
Since unknown
 

Concats a tuple of two Strings.


warning doesn't accept tuples with more than two string.
type String * String -> String

 
ATerm strcmp
File string.str
Author unknown
Since unknown
 

No information available.



 
ATerm string-as-chars(Strategy s)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s List(Char) -> List(Char)

Wraps a strategy on a list of chars in a strategy on a string.


type String -> String

 
ATerm string-ends-with(ATerm end)
File string.str
Author unknown
Since unknown
 

Succeeds if the first String ends with the second String.

If the strategy succeeds, the current term is left untouched.

Example: <string-ends-with(|"bar")> "foobar"


type String -> String

 
ATerm string-gt
File string.str
Author unknown
Since unknown
 

Compares two strings or lists of characters lexicographically and succeeds ifthe first one is larger than the second, ignoring case.


type (List(Char), List(Char)) -> 1
type (String, String) -> 1

 
ATerm string-length
File string.str
Author unknown
Since unknown
 

Returns the number of characters in a string.


type String -> Int

 
ATerm string-lt
File string.str
Author unknown
Since unknown
 

Compares two strings or lists of characters lexicographically and succeeds ifthe first one is smaller than the second, ignoring case.


type (List(Char), List(Char)) -> 1
type (String, String) -> 1

 
ATerm string-sort-desc
File string.str
Author unknown
Since unknown
 

Sorts a list of strings lexicographically ignoring case, descending.


type List(String) -> List(String)

 
ATerm string-starts-with(ATerm start)
File string.str
Author unknown
Since unknown
 

Succeeds if the first String starts with the second String.

If the strategy succeeds, the current term is left untouched.

Example: <string-starts-with(|"foo")> "foobar"


type String -> String

 
ATerm string-tokenize(ATerm sepchars)
File string.str
Author unknown
Since unknown
 
Parameters
ATerm sepchars List of separate characters

Breaks a string into tokens.

Given a list of possible delimiters (characters thatseparate tokens), string-tokenize returns a list oftokens for a given string.


type String -> List(String)

 
ATerm string-tokenize-keep-all(ATerm sepChars)
File string.str
Author unknown
Since 0.9.5
 
Parameters
ATerm sepChars The list of characters that may separate two tokens.

Splits a string into a list of tokens, keeping the separating elements as1-char-strings within the results list, *and* also keeping the empty"" tokens.

Example:<string-tokenize-keep-all(|['\n'])> "fu\n\nbar\n" => ["fu","\n","","\n","bar","\n",""]


type sepChars [char]
type string -> [string]

 
ATerm string-tokenize-keep-empty(ATerm sepChars)
File string.str
Author unknown
Since 0.9.5
 
Parameters
ATerm sepChars The list of characters that may separate two tokens.

Splits a string into a list of tokens, including the empty ones.

This strategy differs from string-tokenize in that it produces an empty ""token when two separator chars are encountered, or after a final separator.

Example:<string-tokenize-keep-empty(|['\n'])> "fu\n\nbar\n" => ["fu","","bar",""]


type sepChars [char]
type string -> [string]

 
ATerm strlen
File string.str
Author unknown
Since unknown
 

Returns the number of characters in a string.


type String -> Int

 
ATerm strncmp
File string.str
Author unknown
Since unknown
 

Compares the n first characters of two character lists, nis given by the last argument. If the two lists are identical,the integer 0 is returned, otherwise the integer 1 is returned.


type List(Char) * List(Char) * Int -> Int

 
ATerm to-lower
File string.str
Author unknown
Since unknown
 

Ensures that a character is lower-case.

This strategy returns the input character if thischaracter is already lower-case.


type Char -> Char

 
ATerm to-upper
File string.str
Author unknown
Since unknown
 

Ensures that a character is upper-case.

This strategy returns the input character if thischaracter is already upper-case.


type Char -> Char

 
ATerm trim-chars(Strategy s)
File string.str
Author unknown
Since 0.9.5
 
Parameters
Strategy s should match all characters to be removed

Trims leading and trailing characters from a string. Thecharacters to trim is given by the strategy argument.

Removes from both ends all characters matched by strategys.

Example: <trim-chars(?' ')> " fred " => "fred"


type String -> String

 
ATerm trim-leading-whitespace
File string.str
Author unknown
Since 0.9.5
 

Trims all leading whitespace in a (single-line) string.


type String -> String

 
ATerm trim-trailing-whitespace
File string.str
Author unknown
Since 0.9.5
 

Trims all trailing whitespace in a (single-line) string.


type String -> String

 
ATerm trim-whitespace
File string.str
Author unknown
Since 0.9.5
 

Trims all trailing and leading whitespace in a (single-line) string.


type String -> String

 
ATerm un-double-quote
File string.str
Author unknown
Since unknown
 

Removes double quotes from the start and end of a string Fails if the string is not properly quoted.


type String -> String

 
ATerm un-double-quote-chars
File string.str
Author unknown
Since unknown
 

Removes double quotes from the start and end of a list of characters. Fails if the list is not properlyquoted.


type List(Char) -> List(Char)

 
ATerm un-single-quote
File string.str
Author unknown
Since unknown
 

Removes single quotes from the start and end of a string Fails if the string is not properly quoted.


type String -> String

 
ATerm un-single-quote-chars
File string.str
Author unknown
Since unknown
 

Removes single quotes from the start and end of a list of characters. Fails if the list is not properlyquoted.


type List(Char) -> List(Char)

 
ATerm unescape
File string.str
Author unknown
Since unknown
 

Unescapes double quotes, backslash, linefeed and tabs.


type String -> String

 
ATerm UnEscape
File string.str
Author unknown
Since unknown
 

No information available.


type List(Char) -> List(Char)

 
ATerm unescape-chars(Strategy s)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s List(Char) -> List(Char)

Unescapes characters using a specified unescape strategy.


type List(Char) -> List(Char)

 
ATerm unescape-chars
File string.str
Author unknown
Since unknown
 

Unescapes double quotes, backslash, linefeed and tabs.


type List(Char) -> List(Char)

 
ATerm unquote(Strategy s)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s Char ->? _

Removes the first and last character of a string.The characters must satisfy s.


type String -> String

 
ATerm unquote(Strategy s1, Strategy s2)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s1 Char ->? _
Strategy s2 Char ->? _

Removes the first and last character of a string.The first character must satisfy s1.The last character must satisfy s2.


type String -> String

 
ATerm unquote-chars(Strategy s)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s Char ->? _

Removes the first and last character of a list of characters.The characters must satisfy s.


type List(Char) -> List(Char)

 
ATerm unquote-chars(Strategy s1, Strategy s2)
File string.str
Author unknown
Since unknown
 
Parameters
Strategy s1 Char ->? _
Strategy s2 Char ->? _

Removes the first and last character of a list of characters.The first character must satisfy s1.The last character must satisfy s2.


type List(Char) -> List(Char)

 
ATerm upper-case
File string.str
Author unknown
Since unknown
 

Converts all characters of this string to upper case



 
ATerm upper-case-chars
File string.str
Author unknown
Since unknown
 

Converts a list of characters to upper case.

Example: <explode-string ; upper-case-chars ; implode-string> "stratego" => "STRATEGO"


type List(Char) -> List(Char)

 

Rule details


ATerm align-center
File string.str
Author unknown
Since unknown
 

No information available.


type Char * String * Int -> String

 
ATerm align-left
File string.str
Author unknown
Since unknown
 

No information available.


type Char * String * Int -> String

 
ATerm align-right
File string.str
Author unknown
Since unknown
 

No information available.


type Char * String * Int -> String

 
ATerm quote-chars
File string.str
Author unknown
Since unknown
 

No information available.


type Char * List(Char) -> List(Char)