34class CharPointer_UTF8 final
37 using CharType = char;
39 explicit CharPointer_UTF8 (
const CharType* rawPointer) noexcept
40 : data (
const_cast<CharType*
> (rawPointer))
44 CharPointer_UTF8 (
const CharPointer_UTF8& other) =
default;
46 CharPointer_UTF8 operator= (CharPointer_UTF8 other)
noexcept
52 CharPointer_UTF8 operator= (
const CharType* text)
noexcept
54 data =
const_cast<CharType*
> (text);
59 bool operator== (CharPointer_UTF8 other)
const noexcept {
return data == other.data; }
60 bool operator!= (
CharPointer_UTF8 other)
const noexcept {
return data != other.data; }
61 bool operator<= (CharPointer_UTF8 other)
const noexcept {
return data <= other.data; }
62 bool operator< (CharPointer_UTF8 other)
const noexcept {
return data < other.data; }
63 bool operator>= (CharPointer_UTF8 other)
const noexcept {
return data >= other.data; }
64 bool operator> (CharPointer_UTF8 other)
const noexcept {
return data > other.data; }
70 operator const CharType*()
const noexcept {
return data; }
73 bool isEmpty() const noexcept {
return *data == 0; }
81 auto byte = (
signed char) *data;
84 return (juce_wchar) (uint8)
byte;
86 uint32 n = (uint32) (uint8) byte;
89 int numExtraValues = 0;
91 while ((n & bit) != 0 && bit > 0x8)
100 for (
int i = 1; i <= numExtraValues; ++i)
102 auto nextByte = (uint32) (uint8) data[i];
104 if ((nextByte & 0xc0) != 0x80)
108 n |= (nextByte & 0x3f);
111 return (juce_wchar) n;
117 jassert (*data != 0);
118 auto n = (
signed char) *data++;
124 while ((
static_cast<uint8
> (n) & bit) != 0 && bit > 0x8)
127 bit =
static_cast<uint8
> (bit >> 1);
139 while ((*--data & 0xc0) == 0x80 && ++count < 4)
149 auto byte = (
signed char) *data++;
152 return (juce_wchar) (uint8)
byte;
154 uint32 n = (uint32) (uint8) byte;
157 int numExtraValues = 0;
159 while ((n & bit) != 0 && bit > 0x8)
168 while (--numExtraValues >= 0)
170 auto nextByte = (uint32) (uint8) *data;
172 if ((nextByte & 0xc0) != 0x80)
177 n |= (nextByte & 0x3f);
180 return (juce_wchar) n;
186 CharPointer_UTF8 temp (*
this);
196 while (++numToSkip <= 0)
201 while (--numToSkip >= 0)
221 CharPointer_UTF8
operator+ (
int numToSkip)
const noexcept
229 CharPointer_UTF8
operator- (
int numToSkip)
const noexcept
244 auto n = (uint32) (uint8) *d++;
248 while ((*d & 0xc0) == 0x80)
261 size_t lengthUpTo (
const size_t maxCharsToCount)
const noexcept
267 size_t lengthUpTo (
const CharPointer_UTF8 end)
const noexcept
277 JUCE_BEGIN_IGNORE_WARNINGS_MSVC (6387)
278 jassert (data !=
nullptr);
279 return strlen (data) + 1;
280 JUCE_END_IGNORE_WARNINGS_MSVC
289 auto c = (uint32) charToWrite;
309 template <
class CharPo
inter>
314 while (
auto n = text.getAndAdvance())
323 return CharPointer_UTF8 (data + strlen (data));
327 void write (
const juce_wchar charToWrite)
noexcept
329 auto c = (uint32) charToWrite;
333 int numExtraBytes = 1;
341 *data++ = (CharType) ((uint32) (0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
343 while (--numExtraBytes >= 0)
344 *data++ = (CharType) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
348 *data++ = (CharType) c;
359 template <
typename CharPo
inter>
366 void writeAll (
const CharPointer_UTF8 src)
noexcept
370 while ((*data = *s) != 0)
381 template <
typename CharPo
inter>
391 template <
typename CharPo
inter>
398 template <
typename CharPo
inter>
399 int compare (
const CharPointer other)
const noexcept
405 template <
typename CharPo
inter>
406 int compareUpTo (
const CharPointer other,
const int maxChars)
const noexcept
412 template <
typename CharPo
inter>
425 template <
typename CharPo
inter>
432 template <
typename CharPo
inter>
433 int indexOf (
const CharPointer stringToFind)
const noexcept
439 int indexOf (
const juce_wchar charToFind)
const noexcept
445 int indexOf (
const juce_wchar charToFind,
const bool ignoreCase)
const noexcept
454 bool isDigit() const noexcept {
const CharType c = *data;
return c >=
'0' && c <=
'9'; }
475 #if JUCE_WINDOWS && ! JUCE_MINGW
476 return _atoi64 (data);
494 return ((uint32) character) < (uint32) 0x10ffff;
500 while (--maxBytesToRead >= 0 && *dataToTest != 0)
502 auto byte = (
signed char) *dataToTest++;
507 int numExtraValues = 0;
509 while ((
byte & bit) != 0)
517 if (bit == 8 && (numExtraValues > maxBytesToRead
518 || *CharPointer_UTF8 (dataToTest - 1) > 0x10ffff))
522 if (numExtraValues == 0)
525 maxBytesToRead -= numExtraValues;
526 if (maxBytesToRead < 0)
529 while (--numExtraValues >= 0)
530 if ((*dataToTest++ & 0xc0) != 0x80)
539 CharPointer_UTF8
atomicSwap (
const CharPointer_UTF8 newValue)
541 return CharPointer_UTF8 (
reinterpret_cast<Atomic<CharType*>&
> (data).exchange (newValue.data));
547 byteOrderMark1 = 0xef,
548 byteOrderMark2 = 0xbb,
549 byteOrderMark3 = 0xbf
557 JUCE_BEGIN_IGNORE_WARNINGS_MSVC (28182)
558 jassert (possibleByteOrder !=
nullptr);
559 auto c =
static_cast<const uint8*
> (possibleByteOrder);
561 return c[0] == (uint8) byteOrderMark1
562 && c[1] == (uint8) byteOrderMark2
563 && c[2] == (uint8) byteOrderMark3;
564 JUCE_END_IGNORE_WARNINGS_MSVC
int compareIgnoreCase(const CharPointer_UTF8 other) const noexcept
int indexOf(const juce_wchar charToFind) const noexcept
int compareUpTo(const CharPointer other, const int maxChars) const noexcept
void writeAll(const CharPointer src) noexcept
CharPointer_UTF8 & operator++() noexcept
CharPointer_UTF8 findTerminatingNull() const noexcept
int compareIgnoreCaseUpTo(const CharPointer other, const int maxChars) const noexcept
static size_t getBytesRequiredFor(CharPointer text) noexcept
void operator+=(int numToSkip) noexcept
bool isLetterOrDigit() const noexcept
juce_wchar operator*() const noexcept
bool isLetter() const noexcept
void incrementToEndOfWhitespace() noexcept
size_t lengthUpTo(const CharPointer_UTF8 end) const noexcept
juce_wchar getAndAdvance() noexcept
size_t writeWithDestByteLimit(const CharPointer src, const size_t maxDestBytes) noexcept
bool isNotEmpty() const noexcept
size_t lengthUpTo(const size_t maxCharsToCount) const noexcept
CharPointer_UTF8 operator-(int numToSkip) const noexcept
void operator-=(int numToSkip) noexcept
double getDoubleValue() const noexcept
size_t sizeInBytes() const noexcept
CharPointer_UTF8 operator--() noexcept
void writeAll(const CharPointer_UTF8 src) noexcept
void writeNull() const noexcept
bool isEmpty() const noexcept
juce_wchar toUpperCase() const noexcept
static size_t getBytesRequiredFor(const juce_wchar charToWrite) noexcept
int indexOf(const CharPointer stringToFind) const noexcept
int64 getIntValue64() const noexcept
static bool canRepresent(juce_wchar character) noexcept
int indexOf(const juce_wchar charToFind, const bool ignoreCase) const noexcept
int getIntValue32() const noexcept
bool isUpperCase() const noexcept
int compareIgnoreCase(const CharPointer other) const noexcept
bool isLowerCase() const noexcept
static bool isByteOrderMark(const void *possibleByteOrder) noexcept
void writeWithCharLimit(const CharPointer src, const int maxChars) noexcept
CharPointer_UTF8 atomicSwap(const CharPointer_UTF8 newValue)
static bool isValidString(const CharType *dataToTest, int maxBytesToRead)
juce_wchar toLowerCase() const noexcept
juce_wchar operator[](int characterIndex) const noexcept
CharPointer_UTF8 operator+(int numToSkip) const noexcept
int compare(const CharPointer other) const noexcept
bool isWhitespace() const noexcept
bool operator==(CharPointer_UTF8 other) const noexcept
CharPointer_UTF8 findEndOfWhitespace() const noexcept
bool isDigit() const noexcept
void write(const juce_wchar charToWrite) noexcept
CharType * getAddress() const noexcept
size_t length() const noexcept
static void incrementToEndOfWhitespace(Type &text) noexcept
static int compare(juce_wchar char1, juce_wchar char2) noexcept
static juce_wchar toLowerCase(juce_wchar character) noexcept
static size_t copyWithDestByteLimit(DestCharPointerType &dest, SrcCharPointerType src, size_t maxBytesToWrite) noexcept
static int indexOfCharIgnoreCase(Type text, juce_wchar charToFind) noexcept
static int compareIgnoreCaseUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
static int indexOfChar(Type text, const juce_wchar charToFind) noexcept
static int compareIgnoreCase(juce_wchar char1, juce_wchar char2) noexcept
static bool isLowerCase(juce_wchar character) noexcept
static bool isLetter(char character) noexcept
static int indexOf(CharPointerType1 textToSearch, const CharPointerType2 substringToLookFor) noexcept
static bool isWhitespace(char character) noexcept
static size_t lengthUpTo(CharPointerType text, const size_t maxCharsToCount) noexcept
static Type findEndOfWhitespace(Type text) noexcept
static void copyWithCharLimit(DestCharPointerType &dest, SrcCharPointerType src, int maxChars) noexcept
static bool isLetterOrDigit(char character) noexcept
static juce_wchar toUpperCase(juce_wchar character) noexcept
static bool isUpperCase(juce_wchar character) noexcept
static double getDoubleValue(CharPointerType text) noexcept
static void copyAll(DestCharPointerType &dest, SrcCharPointerType src) noexcept
static int compareUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept