Subversion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
svn_ctype.h
Go to the documentation of this file.
1 /**
2  * @copyright
3  * ====================================================================
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  * ====================================================================
21  * @endcopyright
22  *
23  * @file svn_ctype.h
24  * @brief Character classification routines
25  * @since New in 1.2.
26  */
27 
28 
29 #ifndef SVN_CTYPE_H
30 #define SVN_CTYPE_H
31 
32 #include <apr.h>
33 
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38 
39 
40 /** Table of flags for character classification. */
41 extern const apr_uint32_t *const svn_ctype_table;
42 
43 
44 /** Check if @a c is in the character class described by @a flags.
45  * The @a flags is a bitwise-or combination of @c SVN_CTYPE_*
46  * constants. Uses #svn_ctype_table.
47  */
48 #define svn_ctype_test(c, flags) \
49  (0 != (svn_ctype_table[(unsigned char)(c)] & (flags)))
50 
51 
52 /**
53  * @defgroup ctype_basic Basic character classification - 7-bit ASCII only
54  * @{
55  */
56 
57 /* Basic character classes */
58 #define SVN_CTYPE_CNTRL 0x0001 /**< Control character */
59 #define SVN_CTYPE_SPACE 0x0002 /**< Whitespace */
60 #define SVN_CTYPE_DIGIT 0x0004 /**< Decimal digit */
61 #define SVN_CTYPE_UPPER 0x0008 /**< Uppercase letter */
62 #define SVN_CTYPE_LOWER 0x0010 /**< Lowercase letter */
63 #define SVN_CTYPE_PUNCT 0x0020 /**< Punctuation mark */
64 #define SVN_CTYPE_XALPHA 0x0040 /**< Hexadecimal digits A to F */
65 #define SVN_CTYPE_ASCII 0x0080 /**< ASCII subset*/
66 
67 /* Derived character classes */
68 /** ASCII letter */
69 #define SVN_CTYPE_ALPHA (SVN_CTYPE_LOWER | SVN_CTYPE_UPPER)
70 /** ASCII letter or decimal digit */
71 #define SVN_CTYPE_ALNUM (SVN_CTYPE_ALPHA | SVN_CTYPE_DIGIT)
72 /** ASCII hexadecimal digit */
73 #define SVN_CTYPE_XDIGIT (SVN_CTYPE_DIGIT | SVN_CTYPE_XALPHA)
74 /** Printable ASCII except space */
75 #define SVN_CTYPE_GRAPH (SVN_CTYPE_PUNCT | SVN_CTYPE_ALNUM)
76 /** All printable ASCII */
77 #define SVN_CTYPE_PRINT (SVN_CTYPE_GRAPH | SVN_CTYPE_SPACE)
78 
79 
80 /** Check if @a c is an ASCII control character. */
81 #define svn_ctype_iscntrl(c) svn_ctype_test((c), SVN_CTYPE_CNTRL)
82 
83 /** Check if @a c is an ASCII whitespace character. */
84 #define svn_ctype_isspace(c) svn_ctype_test((c), SVN_CTYPE_SPACE)
85 
86 /** Check if @a c is an ASCII digit. */
87 #define svn_ctype_isdigit(c) svn_ctype_test((c), SVN_CTYPE_DIGIT)
88 
89 /** Check if @a c is an ASCII uppercase letter. */
90 #define svn_ctype_isupper(c) svn_ctype_test((c), SVN_CTYPE_UPPER)
91 
92 /** Check if @a c is an ASCII lowercase letter. */
93 #define svn_ctype_islower(c) svn_ctype_test((c), SVN_CTYPE_LOWER)
94 
95 /** Check if @a c is an ASCII punctuation mark. */
96 #define svn_ctype_ispunct(c) svn_ctype_test((c), SVN_CTYPE_PUNCT)
97 
98 /** Check if @a c is an ASCII character. */
99 #define svn_ctype_isascii(c) svn_ctype_test((c), SVN_CTYPE_ASCII)
100 
101 /** Check if @a c is an ASCII letter. */
102 #define svn_ctype_isalpha(c) svn_ctype_test((c), SVN_CTYPE_ALPHA)
103 
104 /** Check if @a c is an ASCII letter or decimal digit. */
105 #define svn_ctype_isalnum(c) svn_ctype_test((c), SVN_CTYPE_ALNUM)
106 
107 /** Check if @a c is an ASCII hexadecimal digit. */
108 #define svn_ctype_isxdigit(c) svn_ctype_test((c), SVN_CTYPE_XDIGIT)
109 
110 /** Check if @a c is an ASCII graphical (visible printable) character. */
111 #define svn_ctype_isgraph(c) svn_ctype_test((c), SVN_CTYPE_GRAPH)
112 
113 /** Check if @a c is an ASCII printable character. */
114 #define svn_ctype_isprint(c) svn_ctype_test((c), SVN_CTYPE_PRINT)
115 
116 /** @} */
117 
118 /**
119  * @defgroup ctype_extra Extended character classification
120  * @{
121  */
122 
123 /* Basic extended character classes */
124 #define SVN_CTYPE_UTF8LEAD 0x0100 /**< UTF-8 multibyte lead byte */
125 #define SVN_CTYPE_UTF8CONT 0x0200 /**< UTF-8 multibyte non-lead byte */
126 /* ### TBD
127 #define SVN_CTYPE_XMLNAME 0x0400
128 #define SVN_CTYPE_URISAFE 0x0800
129 */
130 
131 /* Derived extended character classes */
132 /** Part of a UTF-8 multibyte character. */
133 #define SVN_CTYPE_UTF8MBC (SVN_CTYPE_UTF8LEAD | SVN_CTYPE_UTF8CONT)
134 /** All valid UTF-8 bytes. */
135 #define SVN_CTYPE_UTF8 (SVN_CTYPE_ASCII | SVN_CTYPE_UTF8MBC)
136 
137 /** Check if @a c is a UTF-8 multibyte lead byte. */
138 #define svn_ctype_isutf8lead(c) svn_ctype_test((c), SVN_CTYPE_UTF8LEAD)
139 
140 /** Check if @a c is a UTF-8 multibyte continuation (non-lead) byte. */
141 #define svn_ctype_isutf8cont(c) svn_ctype_test((c), SVN_CTYLE_UTF8CONT)
142 
143 /** Check if @a c is part of a UTF-8 multibyte character. */
144 #define svn_ctype_isutf8mbc(c) svn_ctype_test((c), SVN_CTYPE_UTF8MBC)
145 
146 /** Check if @a c is valid in UTF-8. */
147 #define svn_ctype_isutf8(c) svn_ctype_test((c), SVN_CTYPE_UTF8)
148 
149 /** @} */
150 
151 /**
152  * @defgroup ctype_ascii ASCII character value constants
153  * @{
154  */
155 
156 #define SVN_CTYPE_ASCII_MINUS 45 /**< ASCII value of '-' */
157 #define SVN_CTYPE_ASCII_DOT 46 /**< ASCII value of '.' */
158 #define SVN_CTYPE_ASCII_COLON 58 /**< ASCII value of ':' */
159 #define SVN_CTYPE_ASCII_UNDERSCORE 95 /**< ASCII value of '_' */
160 #define SVN_CTYPE_ASCII_TAB 9 /**< ASCII value of a tab */
161 #define SVN_CTYPE_ASCII_LINEFEED 10 /**< ASCII value of a line feed */
162 #define SVN_CTYPE_ASCII_CARRIAGERETURN 13
163  /**< ASCII value of a carriage return */
164 #define SVN_CTYPE_ASCII_DELETE 127
165  /**< ASCII value of a delete character */
166 
167 
168 /** @} */
169 
170 /**
171  * @defgroup ctype_case ASCII-subset case folding
172  * @{
173  */
174 
175 /**
176  * Compare two characters @a a and @a b, treating case-equivalent
177  * unaccented Latin (ASCII subset) letters as equal.
178  *
179  * Returns in integer greater than, equal to, or less than 0,
180  * according to whether @a a is considered greater than, equal to,
181  * or less than @a b.
182  *
183  * @since New in 1.5.
184  */
185 int
186 svn_ctype_casecmp(int a,
187  int b);
188 
189 
190 /** @} */
191 
192 #ifdef __cplusplus
193 }
194 #endif /* __cplusplus */
195 
196 #endif /* SVN_CTYPE_H */
const apr_uint32_t *const svn_ctype_table
Table of flags for character classification.
int svn_ctype_casecmp(int a, int b)
Compare two characters a and b, treating case-equivalent unaccented Latin (ASCII subset) letters as e...