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.
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
|
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.
|
|
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.
|
|
ATerm
|
cify
|
No information available.
|
|
ATerm
|
conc-strings
|
Concats a tuple of two Strings.
type
|
String * String -> String
|
|
|
ATerm
|
concat-strings
|
Concats a list of Strings
type
|
List(String) -> String
|
|
|
ATerm
|
double-quote
|
Adds double quotes to the start and end of a string.
|
|
ATerm
|
double-quote-chars
|
Adds double quotes to the start and end of a list of characters.
type
|
List(Char) -> List(Char)
|
|
|
ATerm
|
escape
|
Escapes double quotes, backslash and linefeed to C like escape sequences.
|
|
ATerm
|
Escape
|
No information available.
type
|
List(Char) -> List(Char)
|
|
|
ATerm
|
escape-chars
|
Escapes double quotes, backslash and linefeed to C like escape sequences.
type
|
List(Char) -> List(Char)
|
|
|
ATerm
|
explode-string
|
Explodes a String to a list of chars.
type
|
String -> List(Char)
|
|
|
ATerm
|
get-lines
|
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.
|
|
ATerm
|
implode-string
|
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
|
Succeeds if the character is part of the lowercase oruppercase alphabet.
|
|
ATerm
|
is-alphanum
|
No information available.
|
|
ATerm
|
is-ascii
|
Succeeds if this string only contains printable ASCII characters.
The letters 32 through 126, in total 96 characters, are definedas printable.
|
|
ATerm
|
is-char
|
Predicate that checks if the supplied term is a printable character.
|
|
ATerm
|
is-double-quoted-chars
|
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
|
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'.
|
|
ATerm
|
is-lower
|
Succeeds if this character is lower-case.
|
|
ATerm
|
is-num
|
No information available.
|
|
ATerm
|
is-quoted(ATerm c)
|
File
|
string.str
|
Author
|
unknown
|
Since
|
unknown
|
|
Parameters
|
Predicate that checks if a string is quoted with the given character.
The character c is the quotation character to check for.
|
|
ATerm
|
is-quoted-chars(ATerm c)
|
File
|
string.str
|
Author
|
unknown
|
Since
|
unknown
|
|
Parameters
|
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
|
Predicate that checks a string is quoted with single quotes.
|
|
ATerm
|
is-single-quoted-chars
|
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
|
Predicate that checks if the supplied term is a string.
|
|
ATerm
|
is-substring(Strategy s)
|
File
|
string.str
|
Author
|
unknown
|
Since
|
unknown
|
|
Parameters
|
Succeeds if the string produced by s is a substringof the argument string.
|
|
ATerm
|
is-upper
|
Succeeds if this character is upper-case.
|
|
ATerm
|
is-whitespace
|
Succeeds if the character is whitespace.
Whitespace is a space (32), or a tab (9)
|
|
ATerm
|
left-match
|
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
|
Makes one newline-separated string out of a list of strings.
|
|
ATerm
|
lower-case
|
Converts all characters of this string to lower case
|
|
ATerm
|
lower-case-chars
|
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 "
|
|
ATerm
|
new
|
Generates a unique new string of the form 'c_d',where c is one char and d is a positive integer.
|
|
ATerm
|
newname
|
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
|
No information available.
type
|
String * Int -> String
|
|
|
ATerm
|
prefix-lines(ATerm p)
|
File
|
string.str
|
Author
|
unknown
|
Since
|
0.9.4
|
|
Parameters
|
Prefixes all lines in a string with a string.
type
|
p string
|
type
|
string -> string
|
|
|
ATerm
|
right-match
|
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"
|
|
ATerm
|
single-quote
|
No information available.
|
|
ATerm
|
single-quote-chars
|
Adds single quotes to the start and end of a listof characters.
type
|
List(Char) -> List(Char)
|
|
|
ATerm
|
split-at-dot
|
No information available.
|
|
ATerm
|
split-at-space
|
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
|
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
|
Concats a tuple of two Strings.
warning
|
doesn't accept tuples with more than two string.
|
type
|
String * String -> String
|
|
|
ATerm
|
strcmp
|
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.
|
|
ATerm
|
string-ends-with(ATerm end)
|
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"
|
|
ATerm
|
string-gt
|
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
|
Returns the number of characters in a string.
|
|
ATerm
|
string-lt
|
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
|
Sorts a list of strings lexicographically ignoring case, descending.
type
|
List(String) -> List(String)
|
|
|
ATerm
|
string-starts-with(ATerm start)
|
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"
|
|
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
|
Returns the number of characters in a string.
|
|
ATerm
|
strncmp
|
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
|
Ensures that a character is lower-case.
This strategy returns the input character if thischaracter is already lower-case.
|
|
ATerm
|
to-upper
|
Ensures that a character is upper-case.
This strategy returns the input character if thischaracter is already upper-case.
|
|
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"
|
|
ATerm
|
trim-leading-whitespace
|
Trims all leading whitespace in a (single-line) string.
|
|
ATerm
|
trim-trailing-whitespace
|
Trims all trailing whitespace in a (single-line) string.
|
|
ATerm
|
trim-whitespace
|
Trims all trailing and leading whitespace in a (single-line) string.
|
|
ATerm
|
un-double-quote
|
Removes double quotes from the start and end of a string Fails if the string is not properly quoted.
|
|
ATerm
|
un-double-quote-chars
|
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
|
Removes single quotes from the start and end of a string Fails if the string is not properly quoted.
|
|
ATerm
|
un-single-quote-chars
|
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
|
Unescapes double quotes, backslash, linefeed and tabs.
|
|
ATerm
|
UnEscape
|
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
|
Unescapes double quotes, backslash, linefeed and tabs.
type
|
List(Char) -> List(Char)
|
|
|
ATerm
|
unquote(Strategy s)
|
File
|
string.str
|
Author
|
unknown
|
Since
|
unknown
|
|
Parameters
|
Removes the first and last character of a string.The characters must satisfy s.
|
|
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.
|
|
ATerm
|
unquote-chars(Strategy s)
|
File
|
string.str
|
Author
|
unknown
|
Since
|
unknown
|
|
Parameters
|
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
|
Converts all characters of this string to upper case
|
|
ATerm
|
upper-case-chars
|
Converts a list of characters to upper case.
Example: <explode-string ; upper-case-chars ; implode-string> "stratego" => "STRATEGO"
type
|
List(Char) -> List(Char)
|
|
|