Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / include / rtl / character.hxx
blob87a20c29e68901d3f791d33d51bf1122beabc6f5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_RTL_CHARACTER_HXX
21 #define INCLUDED_RTL_CHARACTER_HXX
23 #include <sal/config.h>
25 #include <cassert>
27 #include <sal/types.h>
29 namespace rtl
32 /** Check for ASCII character.
34 @param code A Unicode code point.
36 @return True if code is an ASCII character (0x00--0x7F).
38 @since LibreOffice 4.1
40 inline bool isAscii(sal_uInt32 code)
42 assert(code <= 0x10FFFF);
43 return code <= 0x7F;
46 /** Check for ASCII lower case character.
48 @param code A Unicode code point.
50 @return True if code is an ASCII lower case alphabetic character (ASCII
51 'a'--'z').
53 @since LibreOffice 4.1
55 inline bool isAsciiLowerCase(sal_uInt32 code)
57 assert(code <= 0x10FFFF);
58 return code >= 'a' && code <= 'z';
61 /** Check for ASCII upper case character.
63 @param code A Unicode code point.
65 @return True if code is an ASCII upper case alphabetic character (ASCII
66 'A'--'Z').
68 @since LibreOffice 4.1
70 inline bool isAsciiUpperCase(sal_uInt32 code)
72 assert(code <= 0x10FFFF);
73 return code >= 'A' && code <= 'Z';
76 /** Check for ASCII alphabetic character.
78 @param code A Unicode code point.
80 @return True if code is an ASCII alphabetic character (ASCII 'A'--'Z' or
81 'a'--'z').
83 @since LibreOffice 4.1
85 inline bool isAsciiAlpha(sal_uInt32 code)
87 assert(code <= 0x10FFFF);
88 return isAsciiLowerCase(code) || isAsciiUpperCase(code);
91 /** Check for ASCII digit character.
93 @param code A Unicode code point.
95 @return True if code is an ASCII (decimal) digit character (ASCII
96 '0'--'9').
98 @since LibreOffice 4.1
100 inline bool isAsciiDigit(sal_uInt32 code)
102 assert(code <= 0x10FFFF);
103 return code >= '0' && code <= '9';
106 /** Check for ASCII alphanumeric character.
108 @param code A Unicode code point.
110 @return True if code is an ASCII alphanumeric character (ASCII '0'--'9',
111 'A'--'Z', or 'a'--'z').
113 @since LibreOffice 4.1
115 inline bool isAsciiAlphanumeric(sal_uInt32 code)
117 assert(code <= 0x10FFFF);
118 return isAsciiDigit(code) || isAsciiAlpha(code);
121 /** Check for ASCII canonic hexadecimal digit character.
123 @param code A Unicode code point.
125 @return True if code is an ASCII canonic (i.e., upper case) hexadecimal
126 digit character (ASCII '0'--'9' or 'A'--'F').
128 @since LibreOffice 4.1
130 inline bool isAsciiCanonicHexDigit(sal_uInt32 code)
132 assert(code <= 0x10FFFF);
133 return isAsciiDigit(code) || (code >= 'A' && code <= 'F');
136 /** Check for ASCII hexadecimal digit character.
138 @param code A Unicode code point.
140 @return True if code is an ASCII hexadecimal digit character (ASCII
141 '0'--'9', 'A'--'F', or 'a'--'f').
143 @since LibreOffice 4.1
145 inline bool isAsciiHexDigit(sal_uInt32 code)
147 assert(code <= 0x10FFFF);
148 return isAsciiCanonicHexDigit(code) || (code >= 'a' && code <= 'f');
151 /** Convert a character, if ASCII, to upper case.
153 @param code A Unicode code point.
155 @return code converted to ASCII upper case.
157 @since LibreOffice 4.2
159 inline sal_uInt32 toAsciiUpperCase(sal_uInt32 code)
161 assert(code <= 0x10FFFF);
162 return isAsciiLowerCase(code) ? code - 32 : code;
165 /** Convert a character, if ASCII, to lower case.
167 @param code A Unicode code point.
169 @return code converted to ASCII lower case.
171 @since LibreOffice 4.2
173 inline sal_uInt32 toAsciiLowerCase(sal_uInt32 code)
175 assert(code <= 0x10FFFF);
176 return isAsciiUpperCase(code) ? code + 32 : code;
179 /** Compare two characters ignoring ASCII case.
181 @param code1 A Unicode code point.
183 @param code2 A unicode code point.
185 @return 0 if both code points are equal,
186 < 0 if code1 is less than code2,
187 > 0 if code1 is greater than code2.
189 @since LibreOffice 4.2
191 inline sal_Int32 compareIgnoreAsciiCase(sal_uInt32 code1, sal_uInt32 code2)
193 assert(code1 <= 0x10FFFF);
194 assert(code2 <= 0x10FFFF);
195 return static_cast<sal_Int32>(toAsciiLowerCase(code1))
196 - static_cast<sal_Int32>(toAsciiLowerCase(code2));
201 #endif
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */