LMMS
Loading...
Searching...
No Matches
CharacterFunctions.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the Water library.
5 Copyright (c) 2016 ROLI Ltd.
6 Copyright (C) 2017 Filipe Coelho <falktx@falktx.com>
7
8 Permission is granted to use this software under the terms of the ISC license
9 http://www.isc.org/downloads/software-support-policy/isc-license/
10
11 Permission to use, copy, modify, and/or distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
14
15 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
16 TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
18 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 OF THIS SOFTWARE.
22
23 ==============================================================================
24*/
25
26#include "CharacterFunctions.h"
27
28#include <locale>
29
30namespace water {
31
32//==============================================================================
33
35{
36 return (water_uchar) towupper ((wint_t) character);
37}
38
40{
41 return (water_uchar) towlower ((wint_t) character);
42}
43
44bool CharacterFunctions::isUpperCase (const water_uchar character) noexcept
45{
46 #ifdef CARLA_OS_WIN
47 return iswupper ((wint_t) character) != 0;
48 #else
49 return toLowerCase (character) != character;
50 #endif
51}
52
53bool CharacterFunctions::isLowerCase (const water_uchar character) noexcept
54{
55 #ifdef CARLA_OS_WIN
56 return iswlower ((wint_t) character) != 0;
57 #else
58 return toUpperCase (character) != character;
59 #endif
60}
61
62//==============================================================================
63bool CharacterFunctions::isWhitespace (const char character) noexcept
64{
65 return character == ' ' || (character <= 13 && character >= 9);
66}
67
68bool CharacterFunctions::isWhitespace (const water_uchar character) noexcept
69{
70 return iswspace ((wint_t) character) != 0;
71}
72
73bool CharacterFunctions::isDigit (const char character) noexcept
74{
75 return (character >= '0' && character <= '9');
76}
77
78bool CharacterFunctions::isDigit (const water_uchar character) noexcept
79{
80 return iswdigit ((wint_t) character) != 0;
81}
82
83bool CharacterFunctions::isLetter (const char character) noexcept
84{
85 return (character >= 'a' && character <= 'z')
86 || (character >= 'A' && character <= 'Z');
87}
88
89bool CharacterFunctions::isLetter (const water_uchar character) noexcept
90{
91 return iswalpha ((wint_t) character) != 0;
92}
93
94bool CharacterFunctions::isLetterOrDigit (const char character) noexcept
95{
96 return (character >= 'a' && character <= 'z')
97 || (character >= 'A' && character <= 'Z')
98 || (character >= '0' && character <= '9');
99}
100
102{
103 return iswalnum ((wint_t) character) != 0;
104}
105
106bool CharacterFunctions::isPrintable (const char character) noexcept
107{
108 return (character >= ' ' && character <= '~');
109}
110
111bool CharacterFunctions::isPrintable (const water_uchar character) noexcept
112{
113 return iswprint ((wint_t) character) != 0;
114}
115
117{
118 unsigned int d = (unsigned int) digit - '0';
119 if (d < (unsigned int) 10)
120 return (int) d;
121
122 d += (unsigned int) ('0' - 'a');
123 if (d < (unsigned int) 6)
124 return (int) d + 10;
125
126 d += (unsigned int) ('a' - 'A');
127 if (d < (unsigned int) 6)
128 return (int) d + 10;
129
130 return -1;
131}
132
133double CharacterFunctions::mulexp10 (const double value, int exponent) noexcept
134{
135 if (exponent == 0)
136 return value;
137
138 if (value == 0)
139 return 0;
140
141 const bool negative = (exponent < 0);
142 if (negative)
143 exponent = -exponent;
144
145 double result = 1.0, power = 10.0;
146 for (int bit = 1; exponent != 0; bit <<= 1)
147 {
148 if ((exponent & bit) != 0)
149 {
150 exponent ^= bit;
151 result *= power;
152 if (exponent == 0)
153 break;
154 }
155 power *= power;
156 }
157
158 return negative ? (value / result) : (value * result);
159}
160
162{
163 if (c < 0x80 || c >= 0xa0)
164 return (water_uchar) c;
165
166 static const uint16 lookup[] = { 0x20AC, 0x0007, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
167 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0007, 0x017D, 0x0007,
168 0x0007, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
169 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0007, 0x017E, 0x0178 };
170
171 return (water_uchar) lookup[c - 0x80];
172}
173
174}
static water_uchar toUpperCase(water_uchar character) noexcept
Definition CharacterFunctions.cpp:34
static int getHexDigitValue(water_uchar digit) noexcept
Definition CharacterFunctions.cpp:116
static bool isLetterOrDigit(char character) noexcept
Definition CharacterFunctions.cpp:94
static bool isDigit(char character) noexcept
Definition CharacterFunctions.cpp:73
static bool isLetter(char character) noexcept
Definition CharacterFunctions.cpp:83
static bool isPrintable(char character) noexcept
Definition CharacterFunctions.cpp:106
static water_uchar toLowerCase(water_uchar character) noexcept
Definition CharacterFunctions.cpp:39
static bool isLowerCase(water_uchar character) noexcept
Definition CharacterFunctions.cpp:53
static bool isUpperCase(water_uchar character) noexcept
Definition CharacterFunctions.cpp:44
static double mulexp10(const double value, int exponent) noexcept
Definition CharacterFunctions.cpp:133
static bool isWhitespace(char character) noexcept
Definition CharacterFunctions.cpp:63
static water_uchar getUnicodeCharFromWindows1252Codepage(uint8 windows1252Char) noexcept
Definition CharacterFunctions.cpp:161
unsigned d
Definition inflate.c:940
static PuglViewHint int value
Definition pugl.h:1708
Definition AudioSampleBuffer.h:33
unsigned short uint16
Definition water.h:94
unsigned char uint8
Definition water.h:90
uint32 water_uchar
Definition CharacterFunctions.h:38
return c
Definition crypt.c:175
int result
Definition process.c:1455
typedef int(UZ_EXP MsgFn)()
int negative
Definition zipinfo.c:455