root/trunk/library/character.lgt

Revision 4493, 2.2 KB (checked in by pmoura, 7 weeks ago)

Added predicates is_ascii/1, is_white_space/1, is_quote/1, is_period/1, is_punctation/1, and parenthesis/2 to the library entities "characterp" and "character".

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- object(character,
3    implements(characterp),
4    extends(atom)).
5
6    :- info([
7        version is 1.1,
8        author is 'Paulo Moura',
9        date is 2008/10/7,
10        comment is 'Character predicates.']).
11
12    is_ascii(Char) :-
13        char_code(Char, Code),
14        Code >= 0,
15        Code =< 127.
16
17    is_alpha('_').
18    is_alpha(Char) :-
19        is_letter(Char).
20
21    is_letter(Char) :-
22        is_lower_case(Char).
23    is_letter(Char) :-
24        is_upper_case(Char).
25
26    is_alphanumeric(Char) :-
27        is_alpha(Char).
28    is_alphanumeric(Char) :-
29        is_dec_digit(Char).
30
31    is_bin_digit(0).
32    is_bin_digit(1).
33
34    is_octal_digit(Digit) :-
35        Digit @>= 0,
36        Digit @=< 7.
37
38    is_dec_digit(Digit) :-
39        Digit @>= 0,
40        Digit @=< 9.
41
42    is_hex_digit(Digit) :-
43        Digit @>= 0,
44        Digit @=< 9.
45    is_hex_digit(Digit) :-
46        Digit @>= 'A',
47        Digit @=< 'F'.
48    is_hex_digit(Digit) :-
49        Digit @>= a,
50        Digit @=< f.
51
52    is_lower_case(Char) :-
53        Char @>= a,
54        Char @=< z.
55
56    is_upper_case(Char) :-
57        Char @>= 'A',
58        Char @=< 'Z'.
59
60    is_vowel(a).
61    is_vowel(e).
62    is_vowel(i).
63    is_vowel(o).
64    is_vowel(u).
65    is_vowel('A').
66    is_vowel('E').
67    is_vowel('I').
68    is_vowel('O').
69    is_vowel('U').
70
71    is_white_space(' ').
72    is_white_space('\t').
73
74    is_layout(' ').
75    is_layout('\t').
76    is_layout('\f').
77    is_layout('\r').
78    is_layout('\n').
79    is_layout('\v').
80
81    is_quote('''').
82    is_quote('"').
83    is_quote('`').
84
85    is_punctation(',').
86    is_punctation(';').
87    is_punctation(':').
88    is_punctation('.').
89    is_punctation('?').
90    is_punctation('!').
91
92    is_period('.').
93    is_period('?').
94    is_period('!').
95
96    parenthesis('(', ')').
97    parenthesis('[', ']').
98    parenthesis('{', '}').
99
100    lower_upper(a, 'A').
101    lower_upper(b, 'B').
102    lower_upper(c, 'C').
103    lower_upper(d, 'D').
104    lower_upper(e, 'E').
105    lower_upper(f, 'F').
106    lower_upper(g, 'G').
107    lower_upper(h, 'H').
108    lower_upper(i, 'I').
109    lower_upper(j, 'J').
110    lower_upper(k, 'K').
111    lower_upper(l, 'L').
112    lower_upper(m, 'M').
113    lower_upper(n, 'N').
114    lower_upper(o, 'O').
115    lower_upper(p, 'P').
116    lower_upper(q, 'Q').
117    lower_upper(r, 'R').
118    lower_upper(s, 'S').
119    lower_upper(t, 'T').
120    lower_upper(u, 'U').
121    lower_upper(v, 'V').
122    lower_upper(w, 'W').
123    lower_upper(x, 'X').
124    lower_upper(y, 'Y').
125    lower_upper(z, 'Z').
126    lower_upper(Char, Char) :-
127        \+ (Char @>= a, Char @=< z),
128        \+ (Char @>= 'A', Char @=< 'Z').
129
130    valid(Character) :-
131        atom(Character),
132        atom_length(Character, 1).
133
134:- end_object.
Note: See TracBrowser for help on using the browser.