MPD  0.20.18
CharUtil.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2014 Max Kellermann <max.kellermann@gmail.com>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20  * FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27  * OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef CHAR_UTIL_HXX
31 #define CHAR_UTIL_HXX
32 
33 constexpr
34 static inline bool
35 IsASCII(const unsigned char ch)
36 {
37  return ch < 0x80;
38 }
39 
40 constexpr
41 static inline bool
42 IsASCII(const char ch)
43 {
44  return IsASCII((unsigned char)ch);
45 }
46 
47 constexpr
48 static inline bool
49 IsWhitespaceOrNull(const char ch)
50 {
51  return (unsigned char)ch <= 0x20;
52 }
53 
54 constexpr
55 static inline bool
56 IsWhitespaceNotNull(const char ch)
57 {
58  return ch > 0 && ch <= 0x20;
59 }
60 
67 constexpr
68 static inline bool
69 IsWhitespaceFast(const char ch)
70 {
71  return IsWhitespaceOrNull(ch);
72 }
73 
74 constexpr
75 static inline bool
77 {
78  return (signed char)ch >= 0x20;
79 }
80 
81 constexpr
82 static inline bool
83 IsDigitASCII(char ch)
84 {
85  return ch >= '0' && ch <= '9';
86 }
87 
88 constexpr
89 static inline bool
91 {
92  return ch >= 'A' && ch <= 'Z';
93 }
94 
95 constexpr
96 static inline bool
98 {
99  return ch >= 'a' && ch <= 'z';
100 }
101 
102 constexpr
103 static inline bool
104 IsAlphaASCII(char ch)
105 {
106  return IsUpperAlphaASCII(ch) || IsLowerAlphaASCII(ch);
107 }
108 
109 constexpr
110 static inline bool
112 {
113  return IsAlphaASCII(ch) || IsDigitASCII(ch);
114 }
115 
120 constexpr
121 static inline char
122 ToUpperASCII(char ch)
123 {
124  return ch >= 'a' && ch <= 'z'
125  ? (ch - ('a' - 'A'))
126  : ch;
127 }
128 
133 constexpr
134 static inline char
135 ToLowerASCII(char ch)
136 {
137  return ch >= 'A' && ch <= 'Z'
138  ? (ch + ('a' - 'A'))
139  : ch;
140 }
141 
142 #endif
static constexpr bool IsLowerAlphaASCII(char ch)
Definition: CharUtil.hxx:97
static constexpr bool IsAlphaASCII(char ch)
Definition: CharUtil.hxx:104
static constexpr bool IsDigitASCII(char ch)
Definition: CharUtil.hxx:83
static constexpr bool IsASCII(const unsigned char ch)
Definition: CharUtil.hxx:35
static constexpr bool IsWhitespaceNotNull(const char ch)
Definition: CharUtil.hxx:56
static constexpr bool IsPrintableASCII(char ch)
Definition: CharUtil.hxx:76
static constexpr char ToLowerASCII(char ch)
Convert the specified ASCII character (0x00..0x7f) to lower case.
Definition: CharUtil.hxx:135
static constexpr bool IsAlphaNumericASCII(char ch)
Definition: CharUtil.hxx:111
static constexpr bool IsWhitespaceFast(const char ch)
Is the given character whitespace? This calls the faster one of IsWhitespaceOrNull() or IsWhitespaceN...
Definition: CharUtil.hxx:69
static constexpr bool IsUpperAlphaASCII(char ch)
Definition: CharUtil.hxx:90
static constexpr char ToUpperASCII(char ch)
Convert the specified ASCII character (0x00..0x7f) to upper case.
Definition: CharUtil.hxx:122
static constexpr bool IsWhitespaceOrNull(const char ch)
Definition: CharUtil.hxx:49