SWI-Prolog offers two comprehensive predicates for classifying characters and character-codes. These predicates are defined as built-in predicates to exploit the C-character classification's handling of locale (handling of local character-sets). These predicates are fast, logical and deterministic if applicable.
In addition, there is the library library(ctype)
providing compatibility to some other Prolog systems. The predicates of
this library are defined in terms of code_type/2.
<ctype.h>
primitives.
_
). These are valid C- and Prolog symbol
characters.
_
).
These are valid first characters for C- and Prolog symbols
char_type(X,
digit(6)
yields X = '6'
. Useful for
parsing numbers.
char_type(a, xdigit(X)
yields X = '10'
.
Useful for parsing numbers.
graph
character that is not a letter or digit.
"
, '
, `
).
double_quotes
, atom_chars/2
and atom_codes/2.
There is nothing in the Prolog standard for converting case in textual data. The SWI-Prolog predicates code_type/2 and char_type/2 can be used to test and convert individual characters. We have started some additional support:
This section deals with predicates for language specific string comparison operations.
The predicate collation_key/2 is used by locale_sort/2 from library(sort). Please examine the implementation of locale_sort/2 as an example of using this call.
The Key is an implementation defined and generally unreadable string.