Add remaining files
[juce-lv2.git] / juce / source / src / text / juce_CharacterFunctions.cpp
blobc785f2d1ccbc6b4cc8b01733e443a32991bc0e4f
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../core/juce_StandardHeader.h"
28 #if JUCE_MSVC
29 #pragma warning (push)
30 #pragma warning (disable: 4514 4996)
31 #endif
33 #if ! JUCE_ANDROID
34 #include <cwctype>
35 #endif
37 #include <cctype>
39 BEGIN_JUCE_NAMESPACE
41 #include "juce_String.h"
42 #include "../memory/juce_HeapBlock.h"
44 //==============================================================================
45 juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) noexcept
47 return towupper ((wchar_t) character);
50 juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) noexcept
52 return towlower ((wchar_t) character);
55 bool CharacterFunctions::isUpperCase (const juce_wchar character) noexcept
57 #if JUCE_WINDOWS
58 return iswupper ((wchar_t) character) != 0;
59 #else
60 return toLowerCase (character) != character;
61 #endif
64 bool CharacterFunctions::isLowerCase (const juce_wchar character) noexcept
66 #if JUCE_WINDOWS
67 return iswlower ((wchar_t) character) != 0;
68 #else
69 return toUpperCase (character) != character;
70 #endif
73 #if JUCE_MSVC
74 #pragma warning (pop)
75 #endif
77 //==============================================================================
78 bool CharacterFunctions::isWhitespace (const char character) noexcept
80 return character == ' ' || (character <= 13 && character >= 9);
83 bool CharacterFunctions::isWhitespace (const juce_wchar character) noexcept
85 return iswspace ((wchar_t) character) != 0;
88 bool CharacterFunctions::isDigit (const char character) noexcept
90 return (character >= '0' && character <= '9');
93 bool CharacterFunctions::isDigit (const juce_wchar character) noexcept
95 return iswdigit ((wchar_t) character) != 0;
98 bool CharacterFunctions::isLetter (const char character) noexcept
100 return (character >= 'a' && character <= 'z')
101 || (character >= 'A' && character <= 'Z');
104 bool CharacterFunctions::isLetter (const juce_wchar character) noexcept
106 return iswalpha ((wchar_t) character) != 0;
109 bool CharacterFunctions::isLetterOrDigit (const char character) noexcept
111 return (character >= 'a' && character <= 'z')
112 || (character >= 'A' && character <= 'Z')
113 || (character >= '0' && character <= '9');
116 bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) noexcept
118 return iswalnum ((wchar_t) character) != 0;
121 int CharacterFunctions::getHexDigitValue (const juce_wchar digit) noexcept
123 unsigned int d = digit - '0';
124 if (d < (unsigned int) 10)
125 return (int) d;
127 d += (unsigned int) ('0' - 'a');
128 if (d < (unsigned int) 6)
129 return (int) d + 10;
131 d += (unsigned int) ('a' - 'A');
132 if (d < (unsigned int) 6)
133 return (int) d + 10;
135 return -1;
138 double CharacterFunctions::mulexp10 (const double value, int exponent) noexcept
140 if (exponent == 0)
141 return value;
143 if (value == 0)
144 return 0;
146 const bool negative = (exponent < 0);
147 if (negative)
148 exponent = -exponent;
150 double result = 1.0, power = 10.0;
151 for (int bit = 1; exponent != 0; bit <<= 1)
153 if ((exponent & bit) != 0)
155 exponent ^= bit;
156 result *= power;
157 if (exponent == 0)
158 break;
160 power *= power;
163 return negative ? (value / result) : (value * result);
167 END_JUCE_NAMESPACE