String processing
Author(s): Daniel Cabeza.
This module provides predicates for doing input/output with strings (character code lists) and for including in grammars defining strings.
Usage and interface
- Library usage:
:- use_module(library(strings)). - Exports:
- Predicates:
get_line/2, get_line/1, write_string/2, write_string/1, whitespace/2, whitespace0/2, string/3. - Regular Types:
line/1.
- Predicates:
- Imports:
- Packages:
prelude, nonpure, dcg, assertions, isomodes.
- Packages:
Documentation on exports
Reads from Stream a line of text and unifies Line with it. The end of the line can have UNIX [10] or MS-DOS [13 10] termination, which is not included in Line. At EOF, the term end_of_file is returned.
Usage:get_line(S,L)
- The following properties should hold at call time:
(streams_basic:stream/1)S is an open stream. - The following properties should hold upon exit:
(strings:line/1)strings:line(L)
Behaves like current_input(S), get_line(S,Line).
Usage:get_line(L)
- The following properties should hold upon exit:
(strings:line/1)strings:line(L)
Writes String onto Stream.
Usage:write_string(Stream,String)
- The following properties should hold at call time:
(streams_basic:stream/1)Stream is an open stream.
(basic_props:string/1)String is a string (a list of character codes).
Behaves like current_input(S), write_string(S, String).
Usage:write_string(String)
- The following properties should hold at call time:
(basic_props:string/1)String is a string (a list of character codes).
In a grammar rule, as whitespace/0, represents whitespace (a positive number of space (32), tab (9), newline (10) or return (13) characters). Thus, Rest is a proper suffix of String with one or more whitespace characters removed. An example of use would be:
attrs([]) --> "" attrs([N|Ns]) --> whitespace, attr(N), attrs(Ns).
Usage:whitespace(S1,S2)
- The following properties should hold at call time:
(basic_props:string/1)S1 is a string (a list of character codes). - The following properties should hold upon exit:
(basic_props:string/1)S2 is a string (a list of character codes).
In a grammar rule, as whitespace0/0, represents possible whitespace (any number of space (32), tab (9), newline (10) or return (13) characters). Thus, Rest is String or a proper suffix of String with one or more whitespace characters removed. An example of use would be:
assignment(N,V) --> variable_name(N), whitespace0, "=", whitespace0, value(V).
Usage:whitespace0(S1,S2)
- The following properties should hold at call time:
(basic_props:string/1)S1 is a string (a list of character codes). - The following properties should hold upon exit:
(basic_props:string/1)S2 is a string (a list of character codes).
In a grammar rule, as string/1, represents literally String. An example of use would be:
double(A) --> string(A), string(A).
Usage 1:
- Call and exit should be compatible with:
(basic_props:string/1)String is a string (a list of character codes).
(basic_props:string/1)Head is a string (a list of character codes).
(basic_props:string/1)Tail is a string (a list of character codes). - The following properties should hold upon exit:
(basic_props:string/1)String is a string (a list of character codes).
(basic_props:string/1)Head is a string (a list of character codes).
(basic_props:string/1)Tail is a string (a list of character codes).
Usage 2:string(A,B,C)
- The following properties should hold at call time:
(basic_props:list/1)C is a list. - The following properties should hold upon exit:
(basic_props:list/1)A is a list.
(basic_props:list/1)B is a list.