Loading...
Searching...
No Matches
juce_CharPointer_UTF32.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class CharPointer_UTF32 final
{
public:
using CharType = juce_wchar;
inline explicit CharPointer_UTF32 (const CharType* rawPointer) noexcept
: data (const_cast<CharType*> (rawPointer))
{
}
inline CharPointer_UTF32 (const CharPointer_UTF32& other) = default;
inline CharPointer_UTF32 operator= (CharPointer_UTF32 other) noexcept
{
data = other.data;
return *this;
}
inline CharPointer_UTF32 operator= (const CharType* text) noexcept
{
data = const_cast<CharType*> (text);
return *this;
}
inline bool operator== (CharPointer_UTF32 other) const noexcept { return data == other.data; }
inline bool operator!= (CharPointer_UTF32 other) const noexcept { return data != other.data; }
inline bool operator<= (CharPointer_UTF32 other) const noexcept { return data <= other.data; }
inline bool operator< (CharPointer_UTF32 other) const noexcept { return data < other.data; }
inline bool operator>= (CharPointer_UTF32 other) const noexcept { return data >= other.data; }
inline bool operator> (CharPointer_UTF32 other) const noexcept { return data > other.data; }
inline CharType* getAddress() const noexcept { return data; }
inline operator const CharType*() const noexcept { return data; }
inline bool isEmpty() const noexcept { return *data == 0; }
inline bool isNotEmpty() const noexcept { return *data != 0; }
inline juce_wchar operator*() const noexcept { return *data; }
inline CharPointer_UTF32 operator++() noexcept
{
++data;
return *this;
}
inline CharPointer_UTF32 operator--() noexcept
{
--data;
return *this;
}
inline juce_wchar getAndAdvance() noexcept { return *data++; }
CharPointer_UTF32 operator++ (int) noexcept
{
auto temp (*this);
++data;
return temp;
}
inline void operator+= (int numToSkip) noexcept
{
data += numToSkip;
}
inline void operator-= (int numToSkip) noexcept
{
data -= numToSkip;
}
inline juce_wchar& operator[] (int characterIndex) const noexcept
{
return data [characterIndex];
}
CharPointer_UTF32 operator+ (int numToSkip) const noexcept
{
return CharPointer_UTF32 (data + numToSkip);
}
CharPointer_UTF32 operator- (int numToSkip) const noexcept
{
return CharPointer_UTF32 (data - numToSkip);
}
inline void write (juce_wchar charToWrite) noexcept
{
*data++ = charToWrite;
}
inline void replaceChar (juce_wchar newChar) noexcept
{
*data = newChar;
}
inline void writeNull() const noexcept
{
*data = 0;
}
size_t length() const noexcept
{
#if JUCE_NATIVE_WCHAR_IS_UTF32 && ! JUCE_ANDROID
return wcslen (data);
#else
size_t n = 0;
while (data[n] != 0)
++n;
return n;
#endif
}
size_t lengthUpTo (size_t maxCharsToCount) const noexcept
{
return CharacterFunctions::lengthUpTo (*this, maxCharsToCount);
}
size_t lengthUpTo (CharPointer_UTF32 end) const noexcept
{
return CharacterFunctions::lengthUpTo (*this, end);
}
size_t sizeInBytes() const noexcept
{
return sizeof (CharType) * (length() + 1);
}
static size_t getBytesRequiredFor (juce_wchar) noexcept
{
return sizeof (CharType);
}
template <class CharPointer>
static size_t getBytesRequiredFor (CharPointer text) noexcept
{
return sizeof (CharType) * text.length();
}
CharPointer_UTF32 findTerminatingNull() const noexcept
{
return CharPointer_UTF32 (data + length());
}
template <typename CharPointer>
void writeAll (CharPointer src) noexcept
{
CharacterFunctions::copyAll (*this, src);
}
void writeAll (CharPointer_UTF32 src) noexcept
{
auto* s = src.data;
while ((*data = *s) != 0)
{
++data;
++s;
}
}
template <typename CharPointer>
size_t writeWithDestByteLimit (CharPointer src, size_t maxDestBytes) noexcept
{
return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes);
}
template <typename CharPointer>
void writeWithCharLimit (CharPointer src, int maxChars) noexcept
{
CharacterFunctions::copyWithCharLimit (*this, src, maxChars);
}
template <typename CharPointer>
int compare (CharPointer other) const noexcept
{
return CharacterFunctions::compare (*this, other);
}
#if JUCE_NATIVE_WCHAR_IS_UTF32 && ! JUCE_ANDROID
int compare (CharPointer_UTF32 other) const noexcept
{
return wcscmp (data, other.data);
}
#endif
template <typename CharPointer>
int compareUpTo (CharPointer other, int maxChars) const noexcept
{
return CharacterFunctions::compareUpTo (*this, other, maxChars);
}
template <typename CharPointer>
int compareIgnoreCase (CharPointer other) const
{
return CharacterFunctions::compareIgnoreCase (*this, other);
}
template <typename CharPointer>
int compareIgnoreCaseUpTo (CharPointer other, int maxChars) const noexcept
{
return CharacterFunctions::compareIgnoreCaseUpTo (*this, other, maxChars);
}
template <typename CharPointer>
int indexOf (CharPointer stringToFind) const noexcept
{
return CharacterFunctions::indexOf (*this, stringToFind);
}
int indexOf (juce_wchar charToFind) const noexcept
{
int i = 0;
while (data[i] != 0)
{
if (data[i] == charToFind)
return i;
++i;
}
return -1;
}
int indexOf (juce_wchar charToFind, bool ignoreCase) const noexcept
{
return ignoreCase ? CharacterFunctions::indexOfCharIgnoreCase (*this, charToFind)
: CharacterFunctions::indexOfChar (*this, charToFind);
}
bool isWhitespace() const { return CharacterFunctions::isWhitespace (*data) != 0; }
bool isDigit() const { return CharacterFunctions::isDigit (*data) != 0; }
bool isLetter() const { return CharacterFunctions::isLetter (*data) != 0; }
bool isLetterOrDigit() const { return CharacterFunctions::isLetterOrDigit (*data) != 0; }
bool isUpperCase() const { return CharacterFunctions::isUpperCase (*data) != 0; }
bool isLowerCase() const { return CharacterFunctions::isLowerCase (*data) != 0; }
juce_wchar toUpperCase() const noexcept { return CharacterFunctions::toUpperCase (*data); }
juce_wchar toLowerCase() const noexcept { return CharacterFunctions::toLowerCase (*data); }
int getIntValue32() const noexcept { return CharacterFunctions::getIntValue <int, CharPointer_UTF32> (*this); }
int64 getIntValue64() const noexcept { return CharacterFunctions::getIntValue <int64, CharPointer_UTF32> (*this); }
double getDoubleValue() const noexcept { return CharacterFunctions::getDoubleValue (*this); }
CharPointer_UTF32 findEndOfWhitespace() const noexcept { return CharacterFunctions::findEndOfWhitespace (*this); }
void incrementToEndOfWhitespace() noexcept { CharacterFunctions::incrementToEndOfWhitespace (*this); }
static bool canRepresent (juce_wchar character) noexcept
{
return ((uint32) character) < (uint32) 0x10ffff;
}
static bool isValidString (const CharType* dataToTest, int maxBytesToRead)
{
maxBytesToRead /= (int) sizeof (CharType);
while (--maxBytesToRead >= 0 && *dataToTest != 0)
if (! canRepresent (*dataToTest++))
return false;
return true;
}
CharPointer_UTF32 atomicSwap (CharPointer_UTF32 newValue)
{
return CharPointer_UTF32 (reinterpret_cast<Atomic<CharType*>&> (data).exchange (newValue.data));
}
private:
CharType* data;
};
} // namespace juce
juce::CharPointer_UTF32
Definition juce_CharPointer_UTF32.h:35
juce::CharPointer_UTF32::writeNull
void writeNull() const noexcept
Definition juce_CharPointer_UTF32.h:148
juce::CharPointer_UTF32::isValidString
static bool isValidString(const CharType *dataToTest, int maxBytesToRead)
Definition juce_CharPointer_UTF32.h:354
juce::CharPointer_UTF32::write
void write(juce_wchar charToWrite) noexcept
Definition juce_CharPointer_UTF32.h:137
juce::CharPointer_UTF32::operator++
CharPointer_UTF32 operator++() noexcept
Definition juce_CharPointer_UTF32.h:82
juce::CharPointer_UTF32::atomicSwap
CharPointer_UTF32 atomicSwap(CharPointer_UTF32 newValue)
Definition juce_CharPointer_UTF32.h:366
juce::CharPointer_UTF32::operator==
bool operator==(CharPointer_UTF32 other) const noexcept
Definition juce_CharPointer_UTF32.h:59
juce::CharPointer_UTF32::getBytesRequiredFor
static size_t getBytesRequiredFor(CharPointer text) noexcept
Definition juce_CharPointer_UTF32.h:199
juce::CharPointer_UTF32::compareIgnoreCase
int compareIgnoreCase(CharPointer other) const
Definition juce_CharPointer_UTF32.h:273
juce::CharPointer_UTF32::operator+=
void operator+=(int numToSkip) noexcept
Definition juce_CharPointer_UTF32.h:108
juce::CharPointer_UTF32::operator--
CharPointer_UTF32 operator--() noexcept
Definition juce_CharPointer_UTF32.h:89
juce::CharPointer_UTF32::findTerminatingNull
CharPointer_UTF32 findTerminatingNull() const noexcept
Definition juce_CharPointer_UTF32.h:205
juce::CharPointer_UTF32::getIntValue64
int64 getIntValue64() const noexcept
Definition juce_CharPointer_UTF32.h:336
juce::CharPointer_UTF32::writeWithDestByteLimit
size_t writeWithDestByteLimit(CharPointer src, size_t maxDestBytes) noexcept
Definition juce_CharPointer_UTF32.h:234
juce::CharPointer_UTF32::operator[]
juce_wchar & operator[](int characterIndex) const noexcept
Definition juce_CharPointer_UTF32.h:119
juce::CharPointer_UTF32::indexOf
int indexOf(CharPointer stringToFind) const noexcept
Definition juce_CharPointer_UTF32.h:287
juce::CharPointer_UTF32::toLowerCase
juce_wchar toLowerCase() const noexcept
Definition juce_CharPointer_UTF32.h:331
juce::CharPointer_UTF32::writeAll
void writeAll(CharPointer_UTF32 src) noexcept
Definition juce_CharPointer_UTF32.h:218
juce::CharPointer_UTF32::getAddress
CharType * getAddress() const noexcept
Definition juce_CharPointer_UTF32.h:67
juce::CharPointer_UTF32::writeWithCharLimit
void writeWithCharLimit(CharPointer src, int maxChars) noexcept
Definition juce_CharPointer_UTF32.h:244
juce::CharPointer_UTF32::isEmpty
bool isEmpty() const noexcept
Definition juce_CharPointer_UTF32.h:73
juce::CharPointer_UTF32::isNotEmpty
bool isNotEmpty() const noexcept
Definition juce_CharPointer_UTF32.h:76
juce::CharPointer_UTF32::sizeInBytes
size_t sizeInBytes() const noexcept
Definition juce_CharPointer_UTF32.h:181
juce::CharPointer_UTF32::findEndOfWhitespace
CharPointer_UTF32 findEndOfWhitespace() const noexcept
Definition juce_CharPointer_UTF32.h:342
juce::CharPointer_UTF32::incrementToEndOfWhitespace
void incrementToEndOfWhitespace() noexcept
Definition juce_CharPointer_UTF32.h:345
juce::CharPointer_UTF32::lengthUpTo
size_t lengthUpTo(CharPointer_UTF32 end) const noexcept
Definition juce_CharPointer_UTF32.h:173
juce::CharPointer_UTF32::length
size_t length() const noexcept
Definition juce_CharPointer_UTF32.h:154
juce::CharPointer_UTF32::isUpperCase
bool isUpperCase() const
Definition juce_CharPointer_UTF32.h:324
juce::CharPointer_UTF32::operator+
CharPointer_UTF32 operator+(int numToSkip) const noexcept
Definition juce_CharPointer_UTF32.h:125
juce::CharPointer_UTF32::isLetterOrDigit
bool isLetterOrDigit() const
Definition juce_CharPointer_UTF32.h:322
juce::CharPointer_UTF32::toUpperCase
juce_wchar toUpperCase() const noexcept
Definition juce_CharPointer_UTF32.h:329
juce::CharPointer_UTF32::getIntValue32
int getIntValue32() const noexcept
Definition juce_CharPointer_UTF32.h:334
juce::CharPointer_UTF32::canRepresent
static bool canRepresent(juce_wchar character) noexcept
Definition juce_CharPointer_UTF32.h:348
juce::CharPointer_UTF32::indexOf
int indexOf(juce_wchar charToFind) const noexcept
Definition juce_CharPointer_UTF32.h:293
juce::CharPointer_UTF32::isDigit
bool isDigit() const
Definition juce_CharPointer_UTF32.h:318
juce::CharPointer_UTF32::getBytesRequiredFor
static size_t getBytesRequiredFor(juce_wchar) noexcept
Definition juce_CharPointer_UTF32.h:189
juce::CharPointer_UTF32::lengthUpTo
size_t lengthUpTo(size_t maxCharsToCount) const noexcept
Definition juce_CharPointer_UTF32.h:167
juce::CharPointer_UTF32::compare
int compare(CharPointer other) const noexcept
Definition juce_CharPointer_UTF32.h:251
juce::CharPointer_UTF32::compareIgnoreCaseUpTo
int compareIgnoreCaseUpTo(CharPointer other, int maxChars) const noexcept
Definition juce_CharPointer_UTF32.h:280
juce::CharPointer_UTF32::getAndAdvance
juce_wchar getAndAdvance() noexcept
Definition juce_CharPointer_UTF32.h:97
juce::CharPointer_UTF32::isWhitespace
bool isWhitespace() const
Definition juce_CharPointer_UTF32.h:316
juce::CharPointer_UTF32::operator*
juce_wchar operator*() const noexcept
Definition juce_CharPointer_UTF32.h:79
juce::CharPointer_UTF32::isLowerCase
bool isLowerCase() const
Definition juce_CharPointer_UTF32.h:326
juce::CharPointer_UTF32::indexOf
int indexOf(juce_wchar charToFind, bool ignoreCase) const noexcept
Definition juce_CharPointer_UTF32.h:309
juce::CharPointer_UTF32::operator-
CharPointer_UTF32 operator-(int numToSkip) const noexcept
Definition juce_CharPointer_UTF32.h:131
juce::CharPointer_UTF32::compareUpTo
int compareUpTo(CharPointer other, int maxChars) const noexcept
Definition juce_CharPointer_UTF32.h:266
juce::CharPointer_UTF32::isLetter
bool isLetter() const
Definition juce_CharPointer_UTF32.h:320
juce::CharPointer_UTF32::getDoubleValue
double getDoubleValue() const noexcept
Definition juce_CharPointer_UTF32.h:339
juce::CharPointer_UTF32::writeAll
void writeAll(CharPointer src) noexcept
Definition juce_CharPointer_UTF32.h:212
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
juce::Atomic
Definition juce_Atomic.h:42