Loading...
Searching...
No Matches
juce_CharPointer_ASCII.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_ASCII final
{
public:
using CharType = char;
inline explicit CharPointer_ASCII (const CharType* rawPointer) noexcept
: data (const_cast<CharType*> (rawPointer))
{
}
inline CharPointer_ASCII (const CharPointer_ASCII& other) = default;
inline CharPointer_ASCII operator= (const CharPointer_ASCII other) noexcept
{
data = other.data;
return *this;
}
inline CharPointer_ASCII operator= (const CharType* text) noexcept
{
data = const_cast<CharType*> (text);
return *this;
}
inline bool operator== (CharPointer_ASCII other) const noexcept { return data == other.data; }
inline bool operator!= (CharPointer_ASCII other) const noexcept { return data != other.data; }
inline bool operator<= (CharPointer_ASCII other) const noexcept { return data <= other.data; }
inline bool operator< (CharPointer_ASCII other) const noexcept { return data < other.data; }
inline bool operator>= (CharPointer_ASCII other) const noexcept { return data >= other.data; }
inline bool operator> (CharPointer_ASCII 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 (juce_wchar) (uint8) *data; }
inline CharPointer_ASCII operator++() noexcept
{
++data;
return *this;
}
inline CharPointer_ASCII operator--() noexcept
{
--data;
return *this;
}
inline juce_wchar getAndAdvance() noexcept { return (juce_wchar) (uint8) *data++; }
CharPointer_ASCII operator++ (int) noexcept
{
auto temp (*this);
++data;
return temp;
}
inline void operator+= (const int numToSkip) noexcept
{
data += numToSkip;
}
inline void operator-= (const int numToSkip) noexcept
{
data -= numToSkip;
}
inline juce_wchar operator[] (const int characterIndex) const noexcept
{
return (juce_wchar) (uint8) data [characterIndex];
}
CharPointer_ASCII operator+ (const int numToSkip) const noexcept
{
return CharPointer_ASCII (data + numToSkip);
}
CharPointer_ASCII operator- (const int numToSkip) const noexcept
{
return CharPointer_ASCII (data - numToSkip);
}
inline void write (const juce_wchar charToWrite) noexcept
{
*data++ = (char) charToWrite;
}
inline void replaceChar (const juce_wchar newChar) noexcept
{
*data = (char) newChar;
}
inline void writeNull() const noexcept
{
*data = 0;
}
size_t length() const noexcept
{
return (size_t) strlen (data);
}
size_t lengthUpTo (const size_t maxCharsToCount) const noexcept
{
return CharacterFunctions::lengthUpTo (*this, maxCharsToCount);
}
size_t lengthUpTo (const CharPointer_ASCII end) const noexcept
{
return CharacterFunctions::lengthUpTo (*this, end);
}
size_t sizeInBytes() const noexcept
{
return length() + 1;
}
static size_t getBytesRequiredFor (const juce_wchar) noexcept
{
return 1;
}
template <class CharPointer>
static size_t getBytesRequiredFor (const CharPointer text) noexcept
{
return text.length();
}
CharPointer_ASCII findTerminatingNull() const noexcept
{
return CharPointer_ASCII (data + length());
}
template <typename CharPointer>
void writeAll (const CharPointer src) noexcept
{
CharacterFunctions::copyAll (*this, src);
}
template <typename CharPointer>
size_t writeWithDestByteLimit (const CharPointer src, const size_t maxDestBytes) noexcept
{
return CharacterFunctions::copyWithDestByteLimit (*this, src, maxDestBytes);
}
template <typename CharPointer>
void writeWithCharLimit (const CharPointer src, const int maxChars) noexcept
{
CharacterFunctions::copyWithCharLimit (*this, src, maxChars);
}
template <typename CharPointer>
int compare (const CharPointer other) const noexcept
{
return CharacterFunctions::compare (*this, other);
}
int compare (const CharPointer_ASCII other) const noexcept
{
return strcmp (data, other.data);
}
template <typename CharPointer>
int compareUpTo (const CharPointer other, const int maxChars) const noexcept
{
return CharacterFunctions::compareUpTo (*this, other, maxChars);
}
int compareUpTo (const CharPointer_ASCII other, const int maxChars) const noexcept
{
return strncmp (data, other.data, (size_t) maxChars);
}
template <typename CharPointer>
int compareIgnoreCase (const CharPointer other) const
{
return CharacterFunctions::compareIgnoreCase (*this, other);
}
int compareIgnoreCase (const CharPointer_ASCII other) const
{
#if JUCE_MINGW || (JUCE_WINDOWS && JUCE_CLANG)
return CharacterFunctions::compareIgnoreCase (*this, other);
#elif JUCE_WINDOWS
return stricmp (data, other.data);
#else
return strcasecmp (data, other.data);
#endif
}
template <typename CharPointer>
int compareIgnoreCaseUpTo (const CharPointer other, const int maxChars) const noexcept
{
return CharacterFunctions::compareIgnoreCaseUpTo (*this, other, maxChars);
}
template <typename CharPointer>
int indexOf (const CharPointer stringToFind) const noexcept
{
return CharacterFunctions::indexOf (*this, stringToFind);
}
int indexOf (const juce_wchar charToFind) const noexcept
{
int i = 0;
while (data[i] != 0)
{
if (data[i] == (char) charToFind)
return i;
++i;
}
return -1;
}
int indexOf (const juce_wchar charToFind, const 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 ((juce_wchar) (uint8) *data) != 0; }
bool isLowerCase() const { return CharacterFunctions::isLowerCase ((juce_wchar) (uint8) *data) != 0; }
juce_wchar toUpperCase() const noexcept { return CharacterFunctions::toUpperCase ((juce_wchar) (uint8) *data); }
juce_wchar toLowerCase() const noexcept { return CharacterFunctions::toLowerCase ((juce_wchar) (uint8) *data); }
int getIntValue32() const noexcept { return atoi (data); }
int64 getIntValue64() const noexcept
{
#if JUCE_LINUX || JUCE_BSD || JUCE_ANDROID || JUCE_MINGW
return atoll (data);
#elif JUCE_WINDOWS
return _atoi64 (data);
#else
return CharacterFunctions::getIntValue <int64, CharPointer_ASCII> (*this);
#endif
}
double getDoubleValue() const noexcept { return CharacterFunctions::getDoubleValue (*this); }
CharPointer_ASCII findEndOfWhitespace() const noexcept { return CharacterFunctions::findEndOfWhitespace (*this); }
void incrementToEndOfWhitespace() noexcept { CharacterFunctions::incrementToEndOfWhitespace (*this); }
static bool canRepresent (juce_wchar character) noexcept
{
return ((unsigned int) character) < (unsigned int) 128;
}
static bool isValidString (const CharType* dataToTest, int maxBytesToRead)
{
while (--maxBytesToRead >= 0)
{
if (((signed char) *dataToTest) <= 0)
return *dataToTest == 0;
++dataToTest;
}
return true;
}
private:
CharType* data;
};
} // 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