Class char_array is the superclass of both class name (for unique textual constants) and class string for editable text. Class char_array defines common behaviour and avoids type-conversions if the receiving method is just interested in the text represented. It is not common for the user to create instances of the class directly.
See also class text_buffer for handling large amounts of text, and class regex for searching in text.
\0’terminated array of
characters.
See also char_array->prefix
and char_array->suffix.
-language
textual constants:
?- new(X, char_array(hello)).
Creates a char_array object from a Prolog atom.
->sort->suffix, char_array->equal
and class regex.->sort->search.->prefix,
char_array<-ensure_suffix
and char_array<-delete_suffix.
<-base64_decode
and char_array<-base64_encode
realise base64 encoding and decoding conform rfc-2045. This encoding
technique is commonly used for transferring 8-bit data over 7-bit or
otherwise restricted channals.
Encoded data contains the characters 0-9, a-z, A-Z, + and / and end
in 0, 1 or 2 _=_ characters. The length of an encode string is always a
multiple of 4. char_array<-base64_decode
fails silently of the input could not be translated due to a format
error.
Base64 encoding is used in transferring E-mail, in the HTTP protocol
and many others. See also date<-rfc_string
and the class httpd from the library(http/httpd).
name 'Name' label_name 'LabelName' 'label name' 'Label name'
See also char_array<-label_name.
Intended to be used together with chain->sort
and vector->sort.
subclasses of char_array The text int, number Decimal representation of the value real _%f_ representation of the value
get(CA?class, instance, CA).
A subclass for which this behaviour does not produce the desired
result should redefine this method. See for example string<-copy.
->prefix),
return a new char_array
object holding the remaining text. See also char_array<-delete_suffix
and char_array->prefix.->suffix,
char_array<-delete_prefix, char_array<-ensure_suffix
and string->ensure_suffix.
Example:
?- get('hello.pl', delete_suffix, '.pl', V).
V = hello
<-append’ed.
Examples:
?- get(hello, ensure_suffix, '.pl', X).
?- get('hello.pl', ensure_suffix, '.pl', X).
both yield hello.pl.
from is
given, the search (forwards for char_array<-index,
backwards for char_array<-rindex)
starts at the given index. Fails silently if the character cannot be
located.<-default_label
to compute a nice looking label from a nice looking identifier in the
host language. It performs the following transformations:
->syntax)
is transformed into a space.
:- pce_extend_class(name).
label_name(Name, Label:name) :<-
( translate(Name, Label)
-> true
; get_class(Name, char_array,
label_name, Label)
).
:- pce_end_class.
<-append,
etc.). The version defined for class char_array
is defined as:
modify(CA, To:char_array, Value:char_array) :<-
get(CA, class, Class),
get(Class, instance, To, Value).
Redefinition may be necessary for subclasses of class char_array. Examples are the PCE/Lisp predefined class lisp_symbol.
open('hello(world).\n', read, Stream),
read(Stream, X),
close(Stream)
--> X = hello(World)
sscanf(3).
For details consult your C-library documentation. On most Unix systems
this is done using the command
man sscanf.
Below is a description of the format string as taken from the SunOs manual.
The control string usually contains conversion specifications, which are used to direct interpretation of input sequences. The control string may contain:
Conversion specifications are introduced by the character % or the
character sequence %digit$. A conversion specification directs the
conversion of the next input field; the result is placed in the variable
pointed to by the corresponding argument, unless assignment suppression
was indicated by _*_. The suppression of assignment provides a way of
describing an input field which is to be skipped. An input field is
defined as a string of non-space characters; it extends to the next
inappropriate character or until the field width, if specified, is
exhausted. For all descriptors except _[_' and c’,
white space leading an input field is ignored.
The conversion character indicates the interpretation of the input field; the corresponding pointer argument must usually be of a restricted type. For a suppressed field, no pointer argument is given. The following conversion characters are legal:
# % A single % is expected in the input at this point; no assignment is done.
The various integer formats (the result is always returned as a PCE int).
_0_' implies octal; a leading _0x_’implies
hexadecimal; otherwise, decimal.
The various floating point formats. The result is passed as an instance of class real.
string_to_decimal(3),
with fortran_conventions zero.
A character. The result is returned as the ASCII (PCE int).
The string formats. The result is a PCE string object.
\0, which will be
added automatically. The input field is terminated by a white space
character.
# [ Indicates string data; the normal skip over leading white space
is suppressed. The left bracket is followed by a set of characters,
which we will call the scanset, and a right bracket; the input field is
the maximal sequence of input characters consisting entirely of
characters in the scanset. The circumflex (^), when it
appears as the first character in the scanset, serves as a complement
operator and redefines the scanset as the set of all characters not
contained in the remainder of the scanset string. There are some
conventions used in the construction of the scanset. A range of
characters may be represented by the construct first-last, thus
[0123456789] may be expressed [0-9]. Using this convention, first must
be lexically less than or equal to last, or else the dash will stand for
itself. The dash will also stand for itself whenever it is the first or
the last character in the scanset. To include the right square bracket
as an element of the scanset, it must appear as the first character
(possibly pre- ceded by a circumflex) of the scanset, and in this case
it will not be syntactically interpreted as the closing bracket. The
corresponding argument must point to a character array large enough to
hold the data field and the terminating \0, which will be
added automatically. At least one character must match for this
conversion to be considered successful.
See also class regex.
separator is given, it is used to separate parts of the
text. If omitted, a non-empty sequence of layout characters is used.
Examples:
?- get_object('foo+bar', split, +, X).
X = chain(foo, bar).
?- get_object('foo bar', split, X).
X = chain(foo, bar).
Please note that -like the other get-methods on class char_array- the returned fragments are of the same class as the receiver. In other words, breaking a name object yields a chain of names and breaking a string object yields a chain of string objects.
See also regex->for_all,
which may be used to realise more complicated breaking of text.
->strip.
char_array<-strip
is commonly used together with class text_item
to canonicalise identifiers entered by the user. See also char_array<-upcase, char_array<-downcase
and string->translate.
start end
end are 0-based indices.
?- get(string("hello"), value, V).
V = hello