41 #if JUCE_NATIVE_WCHAR_IS_UTF16 42 using CharType = wchar_t;
44 using CharType = int16;
48 : data (const_cast<CharType*> (rawPointer))
62 data =
const_cast<CharType*
> (text);
68 inline bool operator!= (
CharPointer_UTF16 other)
const noexcept {
return data != other.data; }
69 inline bool operator<= (
CharPointer_UTF16 other)
const noexcept {
return data <= other.data; }
70 inline bool operator< (
CharPointer_UTF16 other)
const noexcept {
return data < other.data; }
71 inline bool operator>= (
CharPointer_UTF16 other)
const noexcept {
return data >= other.data; }
72 inline bool operator> (
CharPointer_UTF16 other)
const noexcept {
return data > other.data; }
75 inline CharType*
getAddress() const noexcept {
return data; }
78 inline operator const CharType*()
const noexcept {
return data; }
81 inline bool isEmpty() const noexcept {
return *data == 0; }
84 inline bool isNotEmpty() const noexcept {
return *data != 0; }
89 auto n = (uint32) (uint16) *data;
91 if (n >= 0xd800 && n <= 0xdfff && ((uint32) (uint16) data[1]) >= 0xdc00)
92 n = 0x10000 + (((n - 0xd800) << 10) | (((uint32) (uint16) data[1]) - 0xdc00));
94 return (juce_wchar) n;
100 auto n = (uint32) (uint16) *data++;
102 if (n >= 0xd800 && n <= 0xdfff && ((uint32) (uint16) *data) >= 0xdc00)
111 auto n = (uint32) (uint16) (*--data);
113 if (n >= 0xdc00 && n <= 0xdfff)
123 auto n = (uint32) (uint16) *data++;
125 if (n >= 0xd800 && n <= 0xdfff && ((uint32) (uint16) *data) >= 0xdc00)
126 n = 0x10000 + ((((n - 0xd800) << 10) | (((uint32) (uint16) *data++) - 0xdc00)));
128 return (juce_wchar) n;
144 while (++numToSkip <= 0)
149 while (--numToSkip >= 0)
185 void write (juce_wchar charToWrite) noexcept
187 if (charToWrite >= 0x10000)
189 charToWrite -= 0x10000;
190 *data++ = (CharType) (0xd800 + (charToWrite >> 10));
191 *data++ = (CharType) (0xdc00 + (charToWrite & 0x3ff));
195 *data++ = (CharType) charToWrite;
213 auto n = (uint32) (uint16) *d++;
215 if (n >= 0xd800 && n <= 0xdfff)
246 return sizeof (CharType) * (findNullIndex (data) + 1);
254 return (charToWrite >= 0x10000) ? (
sizeof (CharType) * 2) :
sizeof (CharType);
261 template <
class CharPo
inter>
267 while ((n = text.getAndAdvance()) != 0)
285 template <
typename CharPo
inter>
296 while ((*data = *s) != 0)
307 template <
typename CharPo
inter>
317 template <
typename CharPo
inter>
324 template <
typename CharPo
inter>
325 int compare (CharPointer other)
const noexcept
331 template <
typename CharPo
inter>
338 template <
typename CharPo
inter>
345 template <
typename CharPo
inter>
351 #if JUCE_MSVC && ! DOXYGEN 354 return _wcsicmp (data, other.data);
359 return _wcsnicmp (data, other.data, (
size_t) maxChars);
364 const CharType*
const t = wcsstr (data, stringToFind.
getAddress());
365 return t ==
nullptr ? -1 : (int) (t - data);
370 template <
typename CharPo
inter>
371 int indexOf (CharPointer stringToFind)
const noexcept
377 int indexOf (juce_wchar charToFind)
const noexcept
383 int indexOf (juce_wchar charToFind,
bool ignoreCase)
const noexcept
413 return CharacterFunctions::getIntValue<int, CharPointer_UTF16> (*this);
421 return _wtoi64 (data);
423 return CharacterFunctions::getIntValue<int64, CharPointer_UTF16> (*this);
436 auto n = (uint32) character;
437 return n < 0x10ffff && (n < 0xd800 || n > 0xdfff);
443 maxBytesToRead /= (int)
sizeof (CharType);
445 while (--maxBytesToRead >= 0 && *dataToTest != 0)
447 auto n = (uint32) (uint16) *dataToTest++;
459 auto nextChar = (uint32) (uint16) *dataToTest++;
461 if (nextChar < 0xdc00 || nextChar > 0xdfff)
479 byteOrderMarkBE1 = 0xfe,
480 byteOrderMarkBE2 = 0xff,
481 byteOrderMarkLE1 = 0xff,
482 byteOrderMarkLE2 = 0xfe
490 jassert (possibleByteOrder !=
nullptr);
491 auto c =
static_cast<const uint8*
> (possibleByteOrder);
493 return c[0] == (uint8) byteOrderMarkBE1
494 && c[1] == (uint8) byteOrderMarkBE2;
502 jassert (possibleByteOrder !=
nullptr);
503 auto c =
static_cast<const uint8*
> (possibleByteOrder);
505 return c[0] == (uint8) byteOrderMarkLE1
506 && c[1] == (uint8) byteOrderMarkLE2;
512 static unsigned int findNullIndex (
const CharType* t) noexcept
A simple wrapper around std::atomic.
static double getDoubleValue(CharPointerType text) noexcept
Parses a character string, to read a floating-point value.
static juce_wchar toUpperCase(juce_wchar character) noexcept
Converts a character to upper-case.
juce_wchar operator*() const noexcept
Returns the unicode character that this pointer is pointing to.
size_t lengthUpTo(size_t maxCharsToCount) const noexcept
Returns the number of characters in this string, or the given value, whichever is lower...
bool isLetterOrDigit() const noexcept
Returns true if the first character of this string is a letter or digit.
bool isLowerCase() const noexcept
Returns true if the first character of this string is lower-case.
juce_wchar getAndAdvance() noexcept
Returns the character that this pointer is currently pointing to, and then advances the pointer to po...
bool isEmpty() const noexcept
Returns true if this pointer is pointing to a null character.
bool isLetter() const noexcept
Returns true if the first character of this string is a letter.
juce_wchar toUpperCase() const noexcept
Returns an upper-case version of the first character of this string.
int indexOf(CharPointer stringToFind) const noexcept
Returns the character index of a substring, or -1 if it isn't found.
int getIntValue32() const noexcept
Parses this string as a 32-bit integer.
static int indexOfCharIgnoreCase(Type text, juce_wchar charToFind) noexcept
Finds the character index of a given character in another string, using a case-independent match...
static void copyAll(DestCharPointerType &dest, SrcCharPointerType src) noexcept
Copies null-terminated characters from one string to another.
void operator-=(int numToSkip) noexcept
Moves this pointer backwards by the specified number of characters.
int compare(CharPointer other) const noexcept
Compares this string with another one.
static bool canRepresent(juce_wchar character) noexcept
Returns true if the given unicode character can be represented in this encoding.
static int compareIgnoreCase(juce_wchar char1, juce_wchar char2) noexcept
Compares two characters, using a case-independant match.
void operator+=(int numToSkip) noexcept
Moves this pointer forwards by the specified number of characters.
int compareIgnoreCase(CharPointer other) const noexcept
Compares this string with another one.
bool isWhitespace() const noexcept
Returns true if the first character of this string is whitespace.
static bool isDigit(char character) noexcept
Checks whether a character is a digit.
static Type findEndOfWhitespace(Type text) noexcept
Returns a pointer to the first non-whitespace character in a string.
CharPointer_UTF16 operator-(int numToSkip) const noexcept
Returns a pointer which is moved backwards from this one by the specified number of characters...
static bool isValidString(const CharType *dataToTest, int maxBytesToRead)
Returns true if this data contains a valid string in this encoding.
static bool isWhitespace(char character) noexcept
Checks whether a character is whitespace.
bool isDigit() const noexcept
Returns true if the first character of this string is a digit.
static int indexOfChar(Type text, const juce_wchar charToFind) noexcept
Finds the character index of a given character in another string.
bool isUpperCase() const noexcept
Returns true if the first character of this string is upper-case.
static int compareIgnoreCaseUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Compares two null-terminated character strings, using a case-independent match.
CharPointer_UTF16 findEndOfWhitespace() const noexcept
Returns the first non-whitespace character in the string.
static bool isUpperCase(juce_wchar character) noexcept
Checks whether a unicode character is upper-case.
static size_t lengthUpTo(CharPointerType text, const size_t maxCharsToCount) noexcept
Counts the number of characters in a given string, stopping if the count exceeds a specified limit...
CharType * getAddress() const noexcept
Returns the address that this pointer is pointing to.
static size_t copyWithDestByteLimit(DestCharPointerType &dest, SrcCharPointerType src, size_t maxBytesToWrite) noexcept
Copies characters from one string to another, up to a null terminator or a given byte size limit...
juce_wchar operator[](int characterIndex) const noexcept
Returns the character at a given character index from the start of the string.
void write(juce_wchar charToWrite) noexcept
Writes a unicode character to this string, and advances this pointer to point to the next position...
double getDoubleValue() const noexcept
Parses this string as a floating point double.
void writeAll(CharPointer src) noexcept
Copies a source string to this pointer, advancing this pointer as it goes.
CharPointer_UTF16 operator--() noexcept
Moves this pointer back to the previous character in the string.
void writeNull() const noexcept
Writes a null character to this string (leaving the pointer's position unchanged).
CharPointer_UTF16 atomicSwap(CharPointer_UTF16 newValue)
Atomically swaps this pointer for a new value, returning the previous value.
CharPointer_UTF16 operator++() noexcept
Moves this pointer along to the next character in the string.
juce_wchar toLowerCase() const noexcept
Returns a lower-case version of the first character of this string.
int indexOf(juce_wchar charToFind) const noexcept
Returns the character index of a unicode character, or -1 if it isn't found.
static juce_wchar toLowerCase(juce_wchar character) noexcept
Converts a character to lower-case.
static bool isLetter(char character) noexcept
Checks whether a character is alphabetic.
void writeWithCharLimit(CharPointer src, int maxChars) noexcept
Copies a source string to this pointer, advancing this pointer as it goes.
static size_t getBytesRequiredFor(juce_wchar charToWrite) noexcept
Returns the number of bytes that would be needed to represent the given unicode character in this enc...
static bool isByteOrderMarkLittleEndian(const void *possibleByteOrder) noexcept
Returns true if the first pair of bytes in this pointer are the UTF16 byte-order mark (little endian)...
int64 getIntValue64() const noexcept
Parses this string as a 64-bit integer.
size_t length() const noexcept
Returns the number of characters in this string.
static size_t getBytesRequiredFor(CharPointer text) noexcept
Returns the number of bytes that would be needed to represent the given string in this encoding forma...
CharPointer_UTF16 findTerminatingNull() const noexcept
Returns a pointer to the null character that terminates this string.
size_t writeWithDestByteLimit(CharPointer src, size_t maxDestBytes) noexcept
Copies a source string to this pointer, advancing this pointer as it goes.
Wraps a pointer to a null-terminated UTF-16 character string, and provides various methods to operate...
int compareIgnoreCaseUpTo(CharPointer other, int maxChars) const noexcept
Compares this string with another one, up to a specified number of characters.
static bool isByteOrderMarkBigEndian(const void *possibleByteOrder) noexcept
Returns true if the first pair of bytes in this pointer are the UTF16 byte-order mark (big endian)...
static int indexOf(CharPointerType1 textToSearch, const CharPointerType2 substringToLookFor) noexcept
Finds the character index of a given substring in another string.
size_t sizeInBytes() const noexcept
Returns the number of bytes that are used to represent this string.
CharPointer_UTF16 operator+(int numToSkip) const noexcept
Returns a pointer which is moved forwards from this one by the specified number of characters...
int compareUpTo(CharPointer other, int maxChars) const noexcept
Compares this string with another one, up to a specified number of characters.
void writeAll(CharPointer_UTF16 src) noexcept
Copies a source string to this pointer, advancing this pointer as it goes.
static bool isLowerCase(juce_wchar character) noexcept
Checks whether a unicode character is lower-case.
bool operator==(CharPointer_UTF16 other) const noexcept
This is a pointer comparison, it doesn't compare the actual text.
static bool isLetterOrDigit(char character) noexcept
Checks whether a character is alphabetic or numeric.
int indexOf(juce_wchar charToFind, bool ignoreCase) const noexcept
Returns the character index of a unicode character, or -1 if it isn't found.
static int compareUpTo(CharPointerType1 s1, CharPointerType2 s2, int maxChars) noexcept
Compares two null-terminated character strings, up to a given number of characters.
size_t lengthUpTo(CharPointer_UTF16 end) const noexcept
Returns the number of characters in this string, or up to the given end pointer, whichever is lower...
static void copyWithCharLimit(DestCharPointerType &dest, SrcCharPointerType src, int maxChars) noexcept
Copies characters from one string to another, up to a null terminator or a given maximum number of ch...
bool isNotEmpty() const noexcept
Returns true if this pointer is not pointing to a null character.
static int compare(juce_wchar char1, juce_wchar char2) noexcept
Compares two characters.