Makefile: remove spurious tab
[xcsoar.git] / src / Util / CharUtil.hpp
blob8ff3fd907442e40106a7e2379c4dc6a4bd1688a4
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_CHAR_UTIL_HPP
25 #define XCSOAR_CHAR_UTIL_HPP
27 #ifdef _UNICODE
28 #include <tchar.h>
29 #endif
31 constexpr
32 static inline bool
33 IsASCII(const unsigned char ch)
35 return ch < 0x80;
38 constexpr
39 static inline bool
40 IsASCII(const char ch)
42 return IsASCII((unsigned char)ch);
45 #ifdef _UNICODE
46 constexpr
47 static inline bool
48 IsASCII(const TCHAR ch)
50 return (ch & ~0x7f) == 0;
52 #endif
54 static inline bool
55 IsWhitespaceOrNull(const char ch)
57 return (unsigned char)ch <= 0x20;
60 static inline bool
61 IsWhitespaceNotNull(const char ch)
63 return ch > 0 && ch <= 0x20;
66 #ifdef _UNICODE
68 static inline bool
69 IsWhitespaceOrNull(const TCHAR ch)
71 return (unsigned)ch <= 0x20;
74 static inline bool
75 IsWhitespaceNotNull(const TCHAR ch)
77 return ch > 0 && ch <= 0x20;
80 #endif /* _UNICODE */
82 constexpr
83 static inline bool
84 IsPrintableASCII(char ch)
86 return (signed char)ch >= 0x20;
89 #ifdef _UNICODE
90 constexpr
91 static inline bool
92 IsPrintableASCII(TCHAR ch)
94 return IsASCII(ch) && ch >= 0x20;
96 #endif
98 constexpr
99 static inline bool
100 IsDigitASCII(char ch)
102 return ch >= '0' && ch <= '9';
105 constexpr
106 static inline bool
107 IsUpperAlphaASCII(char ch)
109 return ch >= 'A' && ch <= 'Z';
112 constexpr
113 static inline bool
114 IsLowerAlphaASCII(char ch)
116 return ch >= 'a' && ch <= 'z';
119 constexpr
120 static inline bool
121 IsAlphaASCII(char ch)
123 return IsUpperAlphaASCII(ch) || IsLowerAlphaASCII(ch);
126 constexpr
127 static inline bool
128 IsAlphaNumericASCII(char ch)
130 return IsAlphaASCII(ch) || IsDigitASCII(ch);
133 #ifdef _UNICODE
135 constexpr
136 static inline bool
137 IsDigitASCII(TCHAR ch)
139 return ch >= _T('0') && ch <= _T('9');
142 constexpr
143 static inline bool
144 IsUpperAlphaASCII(TCHAR ch)
146 return ch >= _T('A') && ch <= _T('Z');
149 constexpr
150 static inline bool
151 IsLowerAlphaASCII(TCHAR ch)
153 return ch >= _T('a') && ch <= _T('z');
156 constexpr
157 static inline bool
158 IsAlphaASCII(TCHAR ch)
160 return IsUpperAlphaASCII(ch) || IsLowerAlphaASCII(ch);
163 constexpr
164 static inline bool
165 IsAlphaNumericASCII(TCHAR ch)
167 return IsAlphaASCII(ch) || IsDigitASCII(ch);
170 #endif
173 * Convert the specified ASCII character (0x00..0x7f) to upper case.
174 * Unlike toupper(), it ignores the system locale.
176 constexpr
177 static inline char
178 ToUpperASCII(char ch)
180 return ch >= 'a' && ch <= 'z'
181 ? (ch - ('a' - 'A'))
182 : ch;
185 #endif