14
15
16:- module(chars, [
17 is_digit/1,
18 is_capitalized/1,
19 to_lowercase/2,
20 is_lowercase/1,
21 is_uppercase/1,
22 is_letter/1,
23 is_unused/1,
24 is_sentence_end_symbol/1
25 ]).
46is_capitalized(Token) :-
47 atom(Token),
48 atom_codes(Token, [Code | _]),
49 is_uppercase(Code).
57to_lowercase(TokenIn, TokenOut) :-
58 atom(TokenIn),
59 atom_codes(TokenIn, [Code|CodesRest]),
60 is_uppercase(Code),
61 !,
62 NewCode is Code + 32,
63 atom_codes(TokenOut, [NewCode|CodesRest]).
64
65to_lowercase(Token, Token).
74is_digit(Code) :-
75 48 =< Code, Code =< 57.
87is_lowercase(Code) :-
88 97 =< Code, Code =< 122.
89
91is_lowercase(Code) :-
92 223 =< Code, Code =< 246.
93
95is_lowercase(Code) :-
96 248 =< Code, Code =< 255.
108is_uppercase(Code) :-
109 65 =< Code, Code =< 90.
110
112is_uppercase(Code) :-
113 192 =< Code, Code =< 214.
114
116is_uppercase(Code) :-
117 216 =< Code, Code =< 222.
126is_letter(Code) :-
127 is_lowercase(Code).
128
129is_letter(Code) :-
130 is_uppercase(Code).
141is_unused(Code) :-
142 Code =< 31.
143
144is_unused(Code) :-
145 127 =< Code, Code =< 160.
154is_sentence_end_symbol('.').
155is_sentence_end_symbol('?').
156is_sentence_end_symbol('!')
Characters
Note: SWI has char_type/2 which could be used instead of the predicates defined in this module. But Sicstus does not seem to have anything similar. Note also: char_type/2 does not seem to be good because it does not handle anything beyond ASCII-7. */