LibreOffice
LibreOffice 4.2 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
character.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_RTL_CHARACTER_HXX
21 #define INCLUDED_RTL_CHARACTER_HXX
22 
23 #include <sal/config.h>
24 
25 #include <cassert>
26 
27 #include <sal/types.h>
28 
29 namespace rtl
30 {
31 
40 inline bool isAscii(sal_uInt32 code)
41 {
42  assert(code <= 0x10FFFF);
43  return code <= 0x7F;
44 }
45 
55 inline bool isAsciiLowerCase(sal_uInt32 code)
56 {
57  assert(code <= 0x10FFFF);
58  return code >= 'a' && code <= 'z';
59 }
60 
70 inline bool isAsciiUpperCase(sal_uInt32 code)
71 {
72  assert(code <= 0x10FFFF);
73  return code >= 'A' && code <= 'Z';
74 }
75 
85 inline bool isAsciiAlpha(sal_uInt32 code)
86 {
87  assert(code <= 0x10FFFF);
88  return isAsciiLowerCase(code) || isAsciiUpperCase(code);
89 }
90 
100 inline bool isAsciiDigit(sal_uInt32 code)
101 {
102  assert(code <= 0x10FFFF);
103  return code >= '0' && code <= '9';
104 }
105 
115 inline bool isAsciiAlphanumeric(sal_uInt32 code)
116 {
117  assert(code <= 0x10FFFF);
118  return isAsciiDigit(code) || isAsciiAlpha(code);
119 }
120 
130 inline bool isAsciiCanonicHexDigit(sal_uInt32 code)
131 {
132  assert(code <= 0x10FFFF);
133  return isAsciiDigit(code) || (code >= 'A' && code <= 'F');
134 }
135 
145 inline bool isAsciiHexDigit(sal_uInt32 code)
146 {
147  assert(code <= 0x10FFFF);
148  return isAsciiCanonicHexDigit(code) || (code >= 'a' && code <= 'f');
149 }
150 
159 inline sal_uInt32 toAsciiUpperCase(sal_uInt32 code)
160 {
161  assert(code <= 0x10FFFF);
162  return isAsciiLowerCase(code) ? code - 32 : code;
163 }
164 
173 inline sal_uInt32 toAsciiLowerCase(sal_uInt32 code)
174 {
175  assert(code <= 0x10FFFF);
176  return isAsciiUpperCase(code) ? code + 32 : code;
177 }
178 
191 inline sal_Int32 compareIgnoreAsciiCase(sal_uInt32 code1, sal_uInt32 code2)
192 {
193  assert(code1 <= 0x10FFFF);
194  assert(code2 <= 0x10FFFF);
195  return static_cast<sal_Int32>(toAsciiLowerCase(code1))
196  - static_cast<sal_Int32>(toAsciiLowerCase(code2));
197 }
198 
199 }
200 
201 #endif
202 
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 compareIgnoreAsciiCase(sal_uInt32 code1, sal_uInt32 code2)
Compare two characters ignoring ASCII case.
Definition: character.hxx:191
bool isAsciiAlphanumeric(sal_uInt32 code)
Check for ASCII alphanumeric character.
Definition: character.hxx:115
sal_uInt32 toAsciiLowerCase(sal_uInt32 code)
Convert a character, if ASCII, to lower case.
Definition: character.hxx:173
bool isAsciiHexDigit(sal_uInt32 code)
Check for ASCII hexadecimal digit character.
Definition: character.hxx:145
bool isAsciiDigit(sal_uInt32 code)
Check for ASCII digit character.
Definition: character.hxx:100
bool isAsciiCanonicHexDigit(sal_uInt32 code)
Check for ASCII canonic hexadecimal digit character.
Definition: character.hxx:130
bool isAsciiAlpha(sal_uInt32 code)
Check for ASCII alphabetic character.
Definition: character.hxx:85
sal_uInt32 toAsciiUpperCase(sal_uInt32 code)
Convert a character, if ASCII, to upper case.
Definition: character.hxx:159
bool isAscii(sal_uInt32 code)
Check for ASCII character.
Definition: character.hxx:40
bool isAsciiLowerCase(sal_uInt32 code)
Check for ASCII lower case character.
Definition: character.hxx:55
bool isAsciiUpperCase(sal_uInt32 code)
Check for ASCII upper case character.
Definition: character.hxx:70