35
36:- module(ctypes,
37 [ is_alnum/1,
38 is_alpha/1,
39 is_ascii/1,
40 is_cntrl/1,
41 is_csym/1,
42 is_csymf/1,
43 is_digit/1,
44 is_digit/3,
45 is_endfile/1,
46 is_endline/1,
47 is_graph/1,
48 is_lower/1,
49 is_newline/1,
50 is_newpage/1,
51 is_paren/2,
52 is_period/1,
53 is_print/1,
54 is_punct/1,
55 is_quote/1,
56 is_space/1,
57 is_upper/1,
58 is_white/1,
59 to_lower/2,
60 to_upper/2,
61 upper_lower/2
62 ]).
74is_alnum(C) :- code_type(C, alnum).
75is_alpha(C) :- code_type(C, alpha).
76is_ascii(C) :- code_type(C, ascii).
77is_cntrl(C) :- code_type(C, cntrl).
78is_csym(C) :- code_type(C, csym).
79is_csymf(C) :- code_type(C, csymf).
80is_digit(C) :- code_type(C, digit).
81is_graph(C) :- code_type(C, graph).
82is_lower(C) :- code_type(C, lower).
83is_upper(C) :- code_type(C, upper).
84is_period(C) :- code_type(C, period).
85is_endline(C) :- code_type(C, end_of_line).
86is_print(C) :- is_graph(C).
87is_punct(C) :- code_type(C, punct).
88is_quote(C) :- code_type(C, quote).
89is_space(C) :- code_type(C, space).
90is_white(C) :- code_type(C, white).
91
92is_endfile(-1).
93is_newpage(12). 94is_newline(10).
100is_paren(0'(, 0')). 101is_paren(0'[, 0']).
102is_paren(0'{, 0'}).
110to_lower(U, L) :-
111 code_type(L, to_lower(U)).
119to_upper(L, U) :-
120 code_type(U, to_upper(L)).
128upper_lower(Upper, Lower) :-
129 nonvar(Upper),
130 !,
131 code_type(Lower, lower(Upper)).
132upper_lower(Upper, Lower) :-
133 code_type(Upper, upper(Lower)).
142is_digit(C, Base, Weight) :-
143 Base == 10,
144 !,
145 code_type(C, digit(Weight)).
146is_digit(C, Base, Weight) :-
147 between(2, 36, Base),
148 succ(X, Base),
149 between(0, X, Weight),
150 is_digit(C, Weight).
151
152is_digit(C, Weight) :-
153 Weight < 10,
154 !,
155 plus(Weight, 0'0, C).
156is_digit(C, Weight) :-
157 plus(Weight, 87, C),
158 !. 159is_digit(C, Weight) :-
160 plus(Weight, 55, C).
Character code classification
This file implements the functionality of the corresponding Quintus library based on SWI-Prolog's code_type/2 predicate. Please check the documentation of this predicate to find the definitions of the classes.