CUBRID Engine  latest
chartype.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * chartype.c : character type checking functions
22  */
23 
24 #ident "$Id$"
25 
26 #include "config.h"
27 
28 #include "chartype.h"
29 
30 /*
31  * char_islower() - test for a lower case character
32  * return: non-zero if c is a lower case character,
33  * 0 otherwise.
34  * c (in): the character to be tested
35  */
36 int
37 char_islower (int c)
38 {
39  return ((c) >= 'a' && (c) <= 'z');
40 }
41 
42 /*
43  * char_isupper() - test for a upper case character
44  * return: non-zero if c is a upper case character,
45  * 0 otherwise.
46  * c (in): the character to be tested
47  */
48 int
49 char_isupper (int c)
50 {
51  return ((c) >= 'A' && (c) <= 'Z');
52 }
53 
54 /*
55  * char_isalpha() - test for a alphabetic character
56  * return: non-zero if c is a alphabetic character,
57  * 0 otherwise.
58  * c (in): the character to be tested
59  */
60 int
61 char_isalpha (int c)
62 {
63  return (char_islower ((c)) || char_isupper ((c)));
64 }
65 
66 /*
67  * char_isdigit() - test for a decimal digit character
68  * return: non-zero if c is a decimal digit character,
69  * 0 otherwise.
70  * c (in): the character to be tested
71  */
72 int
73 char_isdigit (int c)
74 {
75  return ((c) >= '0' && (c) <= '9');
76 }
77 
78 /*
79  * char_isxdigit() - test for a hexa decimal digit character
80  * return: non-zero if c is a hexa decimal digit character,
81  * 0 otherwise.
82  * c (in): the character to be tested
83  */
84 int
86 {
87  return (char_isdigit ((c)) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F'));
88 }
89 
90 /*
91  * char_isalnum() - test for a alphanumeric character
92  * return: non-zero if c is a alphanumeric character,
93  * 0 otherwise.
94  * c (in): the character to be tested
95  */
96 int
97 char_isalnum (int c)
98 {
99  return (char_isalpha ((c)) || char_isdigit ((c)));
100 }
101 
102 /*
103  * char_isspace() - test for a white space character
104  * return: non-zero if c is a white space character,
105  * 0 otherwise.
106  * c (in): the character to be tested
107  */
108 int
110 {
111  return ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n' || (c) == '\f' || (c) == '\v');
112 }
113 
114 /*
115  * char_iseol() - test for a end-of-line character
116  * return: non-zero if c is a end-of-line character,
117  * 0 otherwise.
118  * c (in): the character to be tested
119  */
120 int
121 char_iseol (int c)
122 {
123  return ((c) == '\r' || (c) == '\n');
124 }
125 
126 #if defined (ENABLE_UNUSED_FUNCTION)
127 /*
128  * char_isascii() - test for a US-ASCII character
129  * return: non-zero if c is a US-ASCII character,
130  * 0 otherwise.
131  * c (in): the character to be tested
132  */
133 int
134 char_isascii (int c)
135 {
136  return ((c) >= 1 && (c) <= 127);
137 }
138 #endif
139 
140 /*
141  * char_tolower() - convert uppercase character to lowercase
142  * return: lowercase character corresponding to the argument
143  * c (in): the character to be converted
144  */
145 int
147 {
148  return (char_isupper ((c)) ? ((c) - ('A' - 'a')) : (c));
149 }
150 
151 /*
152  * char_toupper() - convert lowercase character to uppercase
153  * return: uppercase character corresponding to the argument
154  * c (in): the character to be converted
155  */
156 int
158 {
159  return (char_islower ((c)) ? ((c) + ('A' - 'a')) : (c));
160 }
161 
162 /* Specialized for ISO 8859-1 */
163 static const int A_GRAVE_ACCENT = 192;
164 static const int MULT_ISO8859 = 215;
165 static const int CAPITAL_THORN = 222;
166 
167 static const int a_GRAVE_ACCENT = 224;
168 static const int DIV_ISO8859 = 247;
169 static const int SMALL_THORN = 254;
170 /*
171  * char_isupper_iso8859() - test for a upper case character for iso-8859
172  * return: non-zero if c is a upper case character,
173  * 0 otherwise.
174  * c (in): the character to be tested
175  */
176 int
178 {
179  return (char_isupper (c) || ((c) >= A_GRAVE_ACCENT && (c) <= CAPITAL_THORN && (c) != MULT_ISO8859));
180 }
181 
182 /*
183  * char_islower_iso8859() - test for a lower case character for iso-8859
184  * return: non-zero if c is a lower case character,
185  * 0 otherwise.
186  * c (in): the character to be tested
187  */
188 int
190 {
191  return (char_islower (c) || ((c) >= a_GRAVE_ACCENT && (c) <= SMALL_THORN && (c) != DIV_ISO8859));
192 }
193 
194 /*
195  * char_tolower_iso8859() - convert uppercase iso-8859 character to lowercase
196  * return: lowercase character corresponding to the argument
197  * c (in): the character to be converted
198  */
199 int
201 {
202  return (char_isupper_iso8859 ((c)) ? ((c) - ('A' - 'a')) : (c));
203 }
204 
205 /*
206  * char_toupper_iso8859() - convert lowercase iso-8859 character to uppercase
207  * return: uppercase character corresponding to the argument
208  * c (in): the character to be converted
209  */
210 int
212 {
213  return (char_islower_iso8859 ((c)) ? ((c) + ('A' - 'a')) : (c));
214 }
int char_isspace(int c)
Definition: chartype.c:109
int char_tolower(int c)
Definition: chartype.c:146
int char_islower(int c)
Definition: chartype.c:37
static const int DIV_ISO8859
Definition: chartype.c:168
int char_isxdigit(int c)
Definition: chartype.c:85
int char_islower_iso8859(int c)
Definition: chartype.c:189
int char_toupper_iso8859(int c)
Definition: chartype.c:211
int char_isdigit(int c)
Definition: chartype.c:73
int char_isupper(int c)
Definition: chartype.c:49
int char_iseol(int c)
Definition: chartype.c:121
static const int CAPITAL_THORN
Definition: chartype.c:165
static const int SMALL_THORN
Definition: chartype.c:169
static const int A_GRAVE_ACCENT
Definition: chartype.c:163
static const int a_GRAVE_ACCENT
Definition: chartype.c:167
int char_tolower_iso8859(int c)
Definition: chartype.c:200
int char_toupper(int c)
Definition: chartype.c:157
int char_isalnum(int c)
Definition: chartype.c:97
int char_isupper_iso8859(int c)
Definition: chartype.c:177
static const int MULT_ISO8859
Definition: chartype.c:164
int char_isalpha(int c)
Definition: chartype.c:61