| Line 44: | Line 44: | ||
=== LibraryStrings === | === LibraryStrings === | ||
<tt>LibraryStrings.def</tt> | You can obtain the definitions of this library by putting the following into your DEFINITIONS clause: | ||
`DEFINITIONS "LibraryStrings.def"` | |||
The file <tt>LibraryStrings.def</tt> is bundled with ProB and can be found in the <tt>stdlib<\tt> folder. | |||
You can also include the machine <tt>LibraryStrings.mch<\tt> instead of the definition file; | |||
the machine defines some of the functions below as proper B functions (i.e., functions | |||
for which you can compute the domain and use constructs such as | |||
relational image). | |||
Below are a few of the provided external functions along with some example uses: | |||
* <tt>STRING_APPEND</tt> takes two strings and concatenates them: | |||
STRING_APPEND("abc","abc") | |||
"abcabc" | |||
* <tt>STRING_LENGTH</tt> takes a string and returns the length: | |||
STRING_LENGTH("abc") | |||
3 | |||
* <tt>STRING_SPLIT</tt> takes two strings and separates the first string | |||
according to the separator specified by the second string: | |||
STRING_SPLIT("usr/local/lib","/") | |||
{(1↦"usr"),(2↦"local"),(3↦"lib")} | |||
* <tt>STRING_JOIN</tt> takes a sequence of strings and a separator string | |||
and joins the strings together inserting the separators as often as needed. | |||
It is the inverse of the <tt>STRING_SPLIT</tt> function. | |||
STRING_JOIN(["usr","local","lib"],"/") | |||
"usr/local/lib" | |||
* <tt>STRING_CHARS</tt> takes a strings splits it into a sequence | |||
of the individual characters. Each character is represented by a string. | |||
* <tt>STRING_CODES</tt> takes a string and splits it into a sequence | |||
of the individual characters. Each character is represented by a natural number | |||
(the ASCII or Unicode representation of the character). | |||
* <tt>CODES_TO_STRING</tt> is the inverse of the <tt>STRING_CODES</tt> function above | |||
CODES_TO_STRING([65,66,67]) | |||
"ABC" | |||
* <tt>STRING_TO_UPPER</tt> converts a string to upper-case letters. It currently converts also diacritical marks (this behaviour may in future be controlled by an additional flag or option). | |||
* <tt>STRING_TO_LOWER</tt> converts a string to lower-case letters. It currently converts also diacritical marks (this behaviour may in future be controlled by an additional flag or option). | |||
* <tt>STRING_EQUAL_CASE_INSENSITIVE</tt> compares two strings ignoring lower/upper case distinctions and diacritical marks. It works as if converting the strings using <tt>STRING_TO_UPPER</tt> before comparing. | |||
* <tt>INT_TO_STRING</tt>,... | |||
=== LibraryRegex === | === LibraryRegex === | ||
<tt>LibraryRegex.def</tt>: providing access to regular expression operators on strings (<tt>REGEX_MATCH</tt>, <tt>REGEX_REPLACE</tt>, <tt>REGEX_SEARCH</tt>,...) | <tt>LibraryRegex.def</tt>: providing access to regular expression operators on strings (<tt>REGEX_MATCH</tt>, <tt>REGEX_REPLACE</tt>, <tt>REGEX_SEARCH</tt>,...) | ||
ProB supports the STRING data type also provided by Atelier-B. However, ProB provides considerable additional features described below.
"astring" a specific (single-line) string value
'''astring''' an alternate way of writing (multi-line) strings, no need to escape "
```tstring``` template strings, where ${Expr} or $«Expr» parts are evaluated and converted to string,
you can provide options separated by commas in square brackets like $[2f]{Expr}.
Valid options are: Nf (for floats/reals), Nd (for integer), Np (padding),
ascii (can be abbreviated to a), unicode (can be abbreviated to u).
ProB supports the following escape sequences within strings:
\n newline (ASCII character 13) \r carriage return (ASCII 10) \t tab (ASCII 9) \" the double quote symbol " \' the single quote symbol ' \\ the backslash symbol
Within single-line string literals, you do not need to escape '. Within multi-line string literals, you do not need to escape " and you can use tabs and newlines.
ProB assumes that all B machines and strings use the UTF-8 encoding.
Atelier-B does not support any operations on strings, apart from equality and disequality. In ProB, however, some of the sequence operators work also on strings:
size(s) the length of a string s rev(s) the reverse of a string s s ^ t the concatenation of two strings conc(ss) the concatenation of a sequence of strings
You can turn this support off using the STRING_AS_SEQUENCE preference.
ProB provides various external functions to manipulate strings.
You can obtain the definitions of this library by putting the following into your DEFINITIONS clause:
`DEFINITIONS "LibraryStrings.def"`
The file LibraryStrings.def is bundled with ProB and can be found in the stdlib<\tt> folder. You can also include the machine LibraryStrings.mch<\tt> instead of the definition file;
the machine defines some of the functions below as proper B functions (i.e., functions for which you can compute the domain and use constructs such as relational image).
Below are a few of the provided external functions along with some example uses:
STRING_APPEND("abc","abc")
"abcabc"
STRING_LENGTH("abc")
3
according to the separator specified by the second string:
STRING_SPLIT("usr/local/lib","/")
{(1↦"usr"),(2↦"local"),(3↦"lib")}
and joins the strings together inserting the separators as often as needed.
It is the inverse of the STRING_SPLIT function.
STRING_JOIN(["usr","local","lib"],"/") "usr/local/lib"
of the individual characters. Each character is represented by a string.
of the individual characters. Each character is represented by a natural number
(the ASCII or Unicode representation of the character).
CODES_TO_STRING([65,66,67]) "ABC"
LibraryRegex.def: providing access to regular expression operators on strings (REGEX_MATCH, REGEX_REPLACE, REGEX_SEARCH,...)