OpenShot Audio Library | OpenShotAudio: juce_CharPointer_ASCII.h Source File

OpenShot Audio Library | OpenShotAudio 0.6.0

Loading...
Searching...
No Matches
juce_CharPointer_ASCII.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26//==============================================================================
37 class CharPointer_ASCII final
38{
39public:
40 using CharType = char;
41
42 inline explicit CharPointer_ASCII (const CharType* rawPointer) noexcept
43 : data (const_cast<CharType*> (rawPointer))
44 {
45 }
46
47 inline CharPointer_ASCII (const CharPointer_ASCII& other) = default;
48
49 inline CharPointer_ASCII operator= (const CharPointer_ASCII other) noexcept
50 {
51 data = other.data;
52 return *this;
53 }
54
55 inline CharPointer_ASCII operator= (const CharType* text) noexcept
56 {
57 data = const_cast<CharType*> (text);
58 return *this;
59 }
60
62 inline bool operator== (CharPointer_ASCII other) const noexcept { return data == other.data; }
63 inline bool operator!= (CharPointer_ASCII other) const noexcept { return data != other.data; }
64 inline bool operator<= (CharPointer_ASCII other) const noexcept { return data <= other.data; }
65 inline bool operator< (CharPointer_ASCII other) const noexcept { return data < other.data; }
66 inline bool operator>= (CharPointer_ASCII other) const noexcept { return data >= other.data; }
67 inline bool operator> (CharPointer_ASCII other) const noexcept { return data > other.data; }
68
70 inline CharType* getAddress() const noexcept { return data; }
71
73 inline operator const CharType*() const noexcept { return data; }
74
76 inline bool isEmpty() const noexcept { return *data == 0; }
77
79 inline bool isNotEmpty() const noexcept { return *data != 0; }
80
82 inline juce_wchar operator*() const noexcept { return (juce_wchar) (uint8) *data; }
83
85 inline CharPointer_ASCII operator++() noexcept
86 {
87 ++data;
88 return *this;
89 }
90
92 inline CharPointer_ASCII operator--() noexcept
93 {
94 --data;
95 return *this;
96 }
97
100 inline juce_wchar getAndAdvance() noexcept { return (juce_wchar) (uint8) *data++; }
101
103 CharPointer_ASCII operator++ (int) noexcept
104 {
105 auto temp (*this);
106 ++data;
107 return temp;
108 }
109
111 inline void operator+= (const int numToSkip) noexcept
112 {
113 data += numToSkip;
114 }
115
116 inline void operator-= (const int numToSkip) noexcept
117 {
118 data -= numToSkip;
119 }
120
122 inline juce_wchar operator[] (const int characterIndex) const noexcept
123 {
124 return (juce_wchar) (uint8) data [characterIndex];
125 }
126
128 CharPointer_ASCII operator+ (const int numToSkip) const noexcept
129 {
130 return CharPointer_ASCII (data + numToSkip);
131 }
132
134 CharPointer_ASCII operator- (const int numToSkip) const noexcept
135 {
136 return CharPointer_ASCII (data - numToSkip);
137 }
138
140 inline void write (const juce_wchar charToWrite) noexcept
141 {
142 *data++ = (char) charToWrite;
143 }
144
145 inline void replaceChar (const juce_wchar newChar) noexcept
146 {
147 *data = (char) newChar;
148 }
149
151 inline void writeNull() const noexcept
152 {
153 *data = 0;
154 }
155
157 size_t length() const noexcept
158 {
159 return (size_t) strlen (data);
160 }
161
163 size_t lengthUpTo (const size_t maxCharsToCount) const noexcept
164 {
165 return CharacterFunctions::lengthUpTo (*this, maxCharsToCount);
166 }
167
169 size_t lengthUpTo (const CharPointer_ASCII end) const noexcept
170 {
171 return CharacterFunctions::lengthUpTo (*this, end);
172 }
173
177 size_t sizeInBytes() const noexcept
178 {
179 return length() + 1;
180 }
181
185 static size_t getBytesRequiredFor (const juce_wchar) noexcept
186 {
187 return 1;
188 }
189
194 template <class CharPointer>
195 static size_t getBytesRequiredFor (const CharPointer text) noexcept
196 {
197 return text.length();
198 }
199
201 CharPointer_ASCII findTerminatingNull() const noexcept
202 {
203 return CharPointer_ASCII (data + length());
204 }
205
207 template <typename CharPointer>
208 void writeAll (const CharPointer src) noexcept
209 {
210 CharacterFunctions::copyAll (*this, src);
211 }
212
217 template <typename CharPointer>
218 size_t writeWithDestByteLimit (const CharPointer src, const size_t maxDestBytes) noexcept
219 {
220 return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes);
221 }
222
227 template <typename CharPointer>
228 void writeWithCharLimit (const CharPointer src, const int maxChars) noexcept
229 {
230 CharacterFunctions::copyWithCharLimit (*this, src, maxChars);
231 }
232
234 template <typename CharPointer>
235 int compare (const CharPointer other) const noexcept
236 {
237 return CharacterFunctions::compare (*this, other);
238 }
239
241 int compare (const CharPointer_ASCII other) const noexcept
242 {
243 return strcmp (data, other.data);
244 }
245
247 template <typename CharPointer>
248 int compareUpTo (const CharPointer other, const int maxChars) const noexcept
249 {
250 return CharacterFunctions::compareUpTo (*this, other, maxChars);
251 }
252
254 int compareUpTo (const CharPointer_ASCII other, const int maxChars) const noexcept
255 {
256 return strncmp (data, other.data, (size_t) maxChars);
257 }
258
260 template <typename CharPointer>
261 int compareIgnoreCase (const CharPointer other) const
262 {
263 return CharacterFunctions::compareIgnoreCase (*this, other);
264 }
265
266 int compareIgnoreCase (const CharPointer_ASCII other) const
267 {
268 #if JUCE_MINGW || (JUCE_WINDOWS && JUCE_CLANG)
269 return CharacterFunctions::compareIgnoreCase (*this, other);
270 #elif JUCE_WINDOWS
271 return stricmp (data, other.data);
272 #else
273 return strcasecmp (data, other.data);
274 #endif
275 }
276
278 template <typename CharPointer>
279 int compareIgnoreCaseUpTo (const CharPointer other, const int maxChars) const noexcept
280 {
281 return CharacterFunctions::compareIgnoreCaseUpTo (*this, other, maxChars);
282 }
283
285 template <typename CharPointer>
286 int indexOf (const CharPointer stringToFind) const noexcept
287 {
288 return CharacterFunctions::indexOf (*this, stringToFind);
289 }
290
292 int indexOf (const juce_wchar charToFind) const noexcept
293 {
294 int i = 0;
295
296 while (data[i] != 0)
297 {
298 if (data[i] == (char) charToFind)
299 return i;
300
301 ++i;
302 }
303
304 return -1;
305 }
306
308 int indexOf (const juce_wchar charToFind, const bool ignoreCase) const noexcept
309 {
310 return ignoreCase ? CharacterFunctions::indexOfCharIgnoreCase (*this, charToFind)
311 : CharacterFunctions::indexOfChar (*this, charToFind);
312 }
313
315 bool isWhitespace() const { return CharacterFunctions::isWhitespace (*data) != 0; }
317 bool isDigit() const { return CharacterFunctions::isDigit (*data) != 0; }
319 bool isLetter() const { return CharacterFunctions::isLetter (*data) != 0; }
321 bool isLetterOrDigit() const { return CharacterFunctions::isLetterOrDigit (*data) != 0; }
323 bool isUpperCase() const { return CharacterFunctions::isUpperCase ((juce_wchar) (uint8) *data) != 0; }
325 bool isLowerCase() const { return CharacterFunctions::isLowerCase ((juce_wchar) (uint8) *data) != 0; }
326
328 juce_wchar toUpperCase() const noexcept { return CharacterFunctions::toUpperCase ((juce_wchar) (uint8) *data); }
330 juce_wchar toLowerCase() const noexcept { return CharacterFunctions::toLowerCase ((juce_wchar) (uint8) *data); }
331
333 int getIntValue32() const noexcept { return atoi (data); }
334
336 int64 getIntValue64() const noexcept
337 {
338 #if JUCE_LINUX || JUCE_BSD || JUCE_ANDROID || JUCE_MINGW
339 return atoll (data);
340 #elif JUCE_WINDOWS
341 return _atoi64 (data);
342 #else
343 return CharacterFunctions::getIntValue <int64, CharPointer_ASCII> (*this);
344 #endif
345 }
346
348 double getDoubleValue() const noexcept { return CharacterFunctions::getDoubleValue (*this); }
349
351 CharPointer_ASCII findEndOfWhitespace() const noexcept { return CharacterFunctions::findEndOfWhitespace (*this); }
352
354 void incrementToEndOfWhitespace() noexcept { CharacterFunctions::incrementToEndOfWhitespace (*this); }
355
357 static bool canRepresent (juce_wchar character) noexcept
358 {
359 return ((unsigned int) character) < (unsigned int) 128;
360 }
361
363 static bool isValidString (const CharType* dataToTest, int maxBytesToRead)
364 {
365 while (--maxBytesToRead >= 0)
366 {
367 if (((signed char) *dataToTest) <= 0)
368 return *dataToTest == 0;
369
370 ++dataToTest;
371 }
372
373 return true;
374 }
375
376private:
377 CharType* data;
378};
379
380} // namespace juce
juce::CharPointer_ASCII
Definition juce_CharPointer_ASCII.h:38
juce::CharPointer_ASCII::getIntValue32
int getIntValue32() const noexcept
Definition juce_CharPointer_ASCII.h:333
juce::CharPointer_ASCII::getDoubleValue
double getDoubleValue() const noexcept
Definition juce_CharPointer_ASCII.h:348
juce::CharPointer_ASCII::isLetter
bool isLetter() const
Definition juce_CharPointer_ASCII.h:319
juce::CharPointer_ASCII::length
size_t length() const noexcept
Definition juce_CharPointer_ASCII.h:157
juce::CharPointer_ASCII::isValidString
static bool isValidString(const CharType *dataToTest, int maxBytesToRead)
Definition juce_CharPointer_ASCII.h:363
juce::CharPointer_ASCII::sizeInBytes
size_t sizeInBytes() const noexcept
Definition juce_CharPointer_ASCII.h:177
juce::CharPointer_ASCII::operator+
CharPointer_ASCII operator+(const int numToSkip) const noexcept
Definition juce_CharPointer_ASCII.h:128
juce::CharPointer_ASCII::lengthUpTo
size_t lengthUpTo(const CharPointer_ASCII end) const noexcept
Definition juce_CharPointer_ASCII.h:169
juce::CharPointer_ASCII::isNotEmpty
bool isNotEmpty() const noexcept
Definition juce_CharPointer_ASCII.h:79
juce::CharPointer_ASCII::writeAll
void writeAll(const CharPointer src) noexcept
Definition juce_CharPointer_ASCII.h:208
juce::CharPointer_ASCII::getBytesRequiredFor
static size_t getBytesRequiredFor(const juce_wchar) noexcept
Definition juce_CharPointer_ASCII.h:185
juce::CharPointer_ASCII::compareIgnoreCaseUpTo
int compareIgnoreCaseUpTo(const CharPointer other, const int maxChars) const noexcept
Definition juce_CharPointer_ASCII.h:279
juce::CharPointer_ASCII::operator++
CharPointer_ASCII operator++() noexcept
Definition juce_CharPointer_ASCII.h:85
juce::CharPointer_ASCII::isWhitespace
bool isWhitespace() const
Definition juce_CharPointer_ASCII.h:315
juce::CharPointer_ASCII::incrementToEndOfWhitespace
void incrementToEndOfWhitespace() noexcept
Definition juce_CharPointer_ASCII.h:354
juce::CharPointer_ASCII::compareIgnoreCase
int compareIgnoreCase(const CharPointer other) const
Definition juce_CharPointer_ASCII.h:261
juce::CharPointer_ASCII::operator--
CharPointer_ASCII operator--() noexcept
Definition juce_CharPointer_ASCII.h:92
juce::CharPointer_ASCII::isLetterOrDigit
bool isLetterOrDigit() const
Definition juce_CharPointer_ASCII.h:321
juce::CharPointer_ASCII::getBytesRequiredFor
static size_t getBytesRequiredFor(const CharPointer text) noexcept
Definition juce_CharPointer_ASCII.h:195
juce::CharPointer_ASCII::getAddress
CharType * getAddress() const noexcept
Definition juce_CharPointer_ASCII.h:70
juce::CharPointer_ASCII::toUpperCase
juce_wchar toUpperCase() const noexcept
Definition juce_CharPointer_ASCII.h:328
juce::CharPointer_ASCII::compareUpTo
int compareUpTo(const CharPointer_ASCII other, const int maxChars) const noexcept
Definition juce_CharPointer_ASCII.h:254
juce::CharPointer_ASCII::compare
int compare(const CharPointer_ASCII other) const noexcept
Definition juce_CharPointer_ASCII.h:241
juce::CharPointer_ASCII::isLowerCase
bool isLowerCase() const
Definition juce_CharPointer_ASCII.h:325
juce::CharPointer_ASCII::toLowerCase
juce_wchar toLowerCase() const noexcept
Definition juce_CharPointer_ASCII.h:330
juce::CharPointer_ASCII::indexOf
int indexOf(const juce_wchar charToFind, const bool ignoreCase) const noexcept
Definition juce_CharPointer_ASCII.h:308
juce::CharPointer_ASCII::writeNull
void writeNull() const noexcept
Definition juce_CharPointer_ASCII.h:151
juce::CharPointer_ASCII::write
void write(const juce_wchar charToWrite) noexcept
Definition juce_CharPointer_ASCII.h:140
juce::CharPointer_ASCII::canRepresent
static bool canRepresent(juce_wchar character) noexcept
Definition juce_CharPointer_ASCII.h:357
juce::CharPointer_ASCII::isUpperCase
bool isUpperCase() const
Definition juce_CharPointer_ASCII.h:323
juce::CharPointer_ASCII::operator[]
juce_wchar operator[](const int characterIndex) const noexcept
Definition juce_CharPointer_ASCII.h:122
juce::CharPointer_ASCII::operator-
CharPointer_ASCII operator-(const int numToSkip) const noexcept
Definition juce_CharPointer_ASCII.h:134
juce::CharPointer_ASCII::indexOf
int indexOf(const CharPointer stringToFind) const noexcept
Definition juce_CharPointer_ASCII.h:286
juce::CharPointer_ASCII::findEndOfWhitespace
CharPointer_ASCII findEndOfWhitespace() const noexcept
Definition juce_CharPointer_ASCII.h:351
juce::CharPointer_ASCII::operator*
juce_wchar operator*() const noexcept
Definition juce_CharPointer_ASCII.h:82
juce::CharPointer_ASCII::operator+=
void operator+=(const int numToSkip) noexcept
Definition juce_CharPointer_ASCII.h:111
juce::CharPointer_ASCII::compare
int compare(const CharPointer other) const noexcept
Definition juce_CharPointer_ASCII.h:235
juce::CharPointer_ASCII::indexOf
int indexOf(const juce_wchar charToFind) const noexcept
Definition juce_CharPointer_ASCII.h:292
juce::CharPointer_ASCII::isEmpty
bool isEmpty() const noexcept
Definition juce_CharPointer_ASCII.h:76
juce::CharPointer_ASCII::getAndAdvance
juce_wchar getAndAdvance() noexcept
Definition juce_CharPointer_ASCII.h:100
juce::CharPointer_ASCII::writeWithCharLimit
void writeWithCharLimit(const CharPointer src, const int maxChars) noexcept
Definition juce_CharPointer_ASCII.h:228
juce::CharPointer_ASCII::writeWithDestByteLimit
size_t writeWithDestByteLimit(const CharPointer src, const size_t maxDestBytes) noexcept
Definition juce_CharPointer_ASCII.h:218
juce::CharPointer_ASCII::operator==
bool operator==(CharPointer_ASCII other) const noexcept
Definition juce_CharPointer_ASCII.h:62
juce::CharPointer_ASCII::compareUpTo
int compareUpTo(const CharPointer other, const int maxChars) const noexcept
Definition juce_CharPointer_ASCII.h:248
juce::CharPointer_ASCII::getIntValue64
int64 getIntValue64() const noexcept
Definition juce_CharPointer_ASCII.h:336
juce::CharPointer_ASCII::findTerminatingNull
CharPointer_ASCII findTerminatingNull() const noexcept
Definition juce_CharPointer_ASCII.h:201
juce::CharPointer_ASCII::lengthUpTo
size_t lengthUpTo(const size_t maxCharsToCount) const noexcept
Definition juce_CharPointer_ASCII.h:163
juce::CharPointer_ASCII::isDigit
bool isDigit() const
Definition juce_CharPointer_ASCII.h:317
juce::CharacterFunctions::incrementToEndOfWhitespace
static void incrementToEndOfWhitespace(Type &text) noexcept
Definition juce_CharacterFunctions.h:807
juce::CharacterFunctions::compare
static int compare(juce_wchar char1, juce_wchar char2) noexcept
Definition juce_CharacterFunctions.h:596
juce::CharacterFunctions::toLowerCase
static juce_wchar toLowerCase(juce_wchar character) noexcept
Definition juce_CharacterFunctions.cpp:33
juce::CharacterFunctions::copyWithDestByteLimit
static size_t copyWithDestByteLimit(DestCharPointerType &dest, SrcCharPointerType src, size_t maxBytesToWrite) noexcept
Definition juce_CharacterFunctions.h:553
juce::CharacterFunctions::indexOfCharIgnoreCase
static int indexOfCharIgnoreCase(Type text, juce_wchar charToFind) noexcept
Definition juce_CharacterFunctions.h:783
juce::CharacterFunctions::isDigit
static bool isDigit(char character) noexcept
Definition juce_CharacterFunctions.cpp:69
juce::CharacterFunctions::getIntValue
static IntType getIntValue(const CharPointerType text) noexcept
Definition juce_CharacterFunctions.h:465
juce::CharacterFunctions::compareIgnoreCaseUpTo
static int compareIgnoreCaseUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Definition juce_CharacterFunctions.h:666
juce::CharacterFunctions::indexOfChar
static int indexOfChar(Type text, const juce_wchar charToFind) noexcept
Definition juce_CharacterFunctions.h:763
juce::CharacterFunctions::compareIgnoreCase
static int compareIgnoreCase(juce_wchar char1, juce_wchar char2) noexcept
Definition juce_CharacterFunctions.h:641
juce::CharacterFunctions::isLowerCase
static bool isLowerCase(juce_wchar character) noexcept
Definition juce_CharacterFunctions.cpp:47
juce::CharacterFunctions::isLetter
static bool isLetter(char character) noexcept
Definition juce_CharacterFunctions.cpp:79
juce::CharacterFunctions::indexOf
static int indexOf(CharPointerType1 textToSearch, const CharPointerType2 substringToLookFor) noexcept
Definition juce_CharacterFunctions.h:686
juce::CharacterFunctions::isWhitespace
static bool isWhitespace(char character) noexcept
Definition juce_CharacterFunctions.cpp:59
juce::CharacterFunctions::lengthUpTo
static size_t lengthUpTo(CharPointerType text, const size_t maxCharsToCount) noexcept
Definition juce_CharacterFunctions.h:517
juce::CharacterFunctions::findEndOfWhitespace
static Type findEndOfWhitespace(Type text) noexcept
Definition juce_CharacterFunctions.h:818
juce::CharacterFunctions::copyWithCharLimit
static void copyWithCharLimit(DestCharPointerType &dest, SrcCharPointerType src, int maxChars) noexcept
Definition juce_CharacterFunctions.h:580
juce::CharacterFunctions::isLetterOrDigit
static bool isLetterOrDigit(char character) noexcept
Definition juce_CharacterFunctions.cpp:90
juce::CharacterFunctions::toUpperCase
static juce_wchar toUpperCase(juce_wchar character) noexcept
Definition juce_CharacterFunctions.cpp:28
juce::CharacterFunctions::isUpperCase
static bool isUpperCase(juce_wchar character) noexcept
Definition juce_CharacterFunctions.cpp:38
juce::CharacterFunctions::getDoubleValue
static double getDoubleValue(CharPointerType text) noexcept
Definition juce_CharacterFunctions.h:457
juce::CharacterFunctions::copyAll
static void copyAll(DestCharPointerType &dest, SrcCharPointerType src) noexcept
Definition juce_CharacterFunctions.h:542
juce::CharacterFunctions::compareUpTo
static int compareUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Definition juce_CharacterFunctions.h:624