From 6be2db68d6ff66ee5bb7e372324f9d736209f764 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 16 Apr 2024 11:55:36 +0100 Subject: [PATCH] CharPointer: Tidy up and fix arithmetic operator return types --- .../juce_core/text/juce_CharPointer_ASCII.h | 58 +++++++++---------- .../juce_core/text/juce_CharPointer_UTF16.h | 54 ++++++++--------- .../juce_core/text/juce_CharPointer_UTF32.h | 58 +++++++++---------- .../juce_core/text/juce_CharPointer_UTF8.h | 26 ++++----- 4 files changed, 90 insertions(+), 106 deletions(-) diff --git a/modules/juce_core/text/juce_CharPointer_ASCII.h b/modules/juce_core/text/juce_CharPointer_ASCII.h index fa8f38d879..ce94a936b0 100644 --- a/modules/juce_core/text/juce_CharPointer_ASCII.h +++ b/modules/juce_core/text/juce_CharPointer_ASCII.h @@ -51,57 +51,53 @@ class CharPointer_ASCII final public: using CharType = char; - inline explicit CharPointer_ASCII (const CharType* rawPointer) noexcept + explicit CharPointer_ASCII (const CharType* rawPointer) noexcept : data (const_cast (rawPointer)) { } - inline CharPointer_ASCII (const CharPointer_ASCII& other) = default; + CharPointer_ASCII (const CharPointer_ASCII& other) = default; - inline CharPointer_ASCII operator= (const CharPointer_ASCII other) noexcept - { - data = other.data; - return *this; - } + CharPointer_ASCII& operator= (const CharPointer_ASCII& other) noexcept = default; - inline CharPointer_ASCII operator= (const CharType* text) noexcept + CharPointer_ASCII& operator= (const CharType* text) noexcept { data = const_cast (text); return *this; } /** This is a pointer comparison, it doesn't compare the actual text. */ - 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; } + bool operator== (CharPointer_ASCII other) const noexcept { return data == other.data; } + bool operator!= (CharPointer_ASCII other) const noexcept { return data != other.data; } + bool operator<= (CharPointer_ASCII other) const noexcept { return data <= other.data; } + bool operator< (CharPointer_ASCII other) const noexcept { return data < other.data; } + bool operator>= (CharPointer_ASCII other) const noexcept { return data >= other.data; } + bool operator> (CharPointer_ASCII other) const noexcept { return data > other.data; } /** Returns the address that this pointer is pointing to. */ - inline CharType* getAddress() const noexcept { return data; } + CharType* getAddress() const noexcept { return data; } /** Returns the address that this pointer is pointing to. */ - inline operator const CharType*() const noexcept { return data; } + operator const CharType*() const noexcept { return data; } /** Returns true if this pointer is pointing to a null character. */ - inline bool isEmpty() const noexcept { return *data == 0; } + bool isEmpty() const noexcept { return *data == 0; } /** Returns true if this pointer is not pointing to a null character. */ - inline bool isNotEmpty() const noexcept { return *data != 0; } + bool isNotEmpty() const noexcept { return *data != 0; } /** Returns the unicode character that this pointer is pointing to. */ - inline juce_wchar operator*() const noexcept { return (juce_wchar) (uint8) *data; } + juce_wchar operator*() const noexcept { return (juce_wchar) (uint8) *data; } /** Moves this pointer along to the next character in the string. */ - inline CharPointer_ASCII operator++() noexcept + CharPointer_ASCII& operator++() noexcept { ++data; return *this; } /** Moves this pointer to the previous character in the string. */ - inline CharPointer_ASCII operator--() noexcept + CharPointer_ASCII& operator--() noexcept { --data; return *this; @@ -109,7 +105,7 @@ public: /** Returns the character that this pointer is currently pointing to, and then advances the pointer to point to the next character. */ - inline juce_wchar getAndAdvance() noexcept { return (juce_wchar) (uint8) *data++; } + juce_wchar getAndAdvance() noexcept { return (juce_wchar) (uint8) *data++; } /** Moves this pointer along to the next character in the string. */ CharPointer_ASCII operator++ (int) noexcept @@ -120,18 +116,20 @@ public: } /** Moves this pointer forwards by the specified number of characters. */ - inline void operator+= (const int numToSkip) noexcept + CharPointer_ASCII& operator+= (const int numToSkip) noexcept { data += numToSkip; + return *this; } - inline void operator-= (const int numToSkip) noexcept + CharPointer_ASCII& operator-= (const int numToSkip) noexcept { data -= numToSkip; + return *this; } /** Returns the character at a given character index from the start of the string. */ - inline juce_wchar operator[] (const int characterIndex) const noexcept + juce_wchar operator[] (const int characterIndex) const noexcept { return (juce_wchar) (uint8) data [characterIndex]; } @@ -139,28 +137,28 @@ public: /** Returns a pointer which is moved forwards from this one by the specified number of characters. */ CharPointer_ASCII operator+ (const int numToSkip) const noexcept { - return CharPointer_ASCII (data + numToSkip); + return CharPointer_ASCII (*this) += numToSkip; } /** Returns a pointer which is moved backwards from this one by the specified number of characters. */ CharPointer_ASCII operator- (const int numToSkip) const noexcept { - return CharPointer_ASCII (data - numToSkip); + return CharPointer_ASCII (*this) -= numToSkip; } /** Writes a unicode character to this string, and advances this pointer to point to the next position. */ - inline void write (const juce_wchar charToWrite) noexcept + void write (const juce_wchar charToWrite) noexcept { *data++ = (char) charToWrite; } - inline void replaceChar (const juce_wchar newChar) noexcept + void replaceChar (const juce_wchar newChar) noexcept { *data = (char) newChar; } /** Writes a null character to this string (leaving the pointer's position unchanged). */ - inline void writeNull() const noexcept + void writeNull() const noexcept { *data = 0; } diff --git a/modules/juce_core/text/juce_CharPointer_UTF16.h b/modules/juce_core/text/juce_CharPointer_UTF16.h index d36f370f05..1b588c8bdd 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF16.h +++ b/modules/juce_core/text/juce_CharPointer_UTF16.h @@ -52,44 +52,40 @@ public: using CharType = int16; #endif - inline explicit CharPointer_UTF16 (const CharType* rawPointer) noexcept + explicit CharPointer_UTF16 (const CharType* rawPointer) noexcept : data (const_cast (rawPointer)) { } - inline CharPointer_UTF16 (const CharPointer_UTF16& other) = default; + CharPointer_UTF16 (const CharPointer_UTF16& other) = default; - inline CharPointer_UTF16 operator= (CharPointer_UTF16 other) noexcept - { - data = other.data; - return *this; - } + CharPointer_UTF16& operator= (const CharPointer_UTF16& other) noexcept = default; - inline CharPointer_UTF16 operator= (const CharType* text) noexcept + CharPointer_UTF16& operator= (const CharType* text) noexcept { data = const_cast (text); return *this; } /** This is a pointer comparison, it doesn't compare the actual text. */ - inline bool operator== (CharPointer_UTF16 other) const noexcept { return data == other.data; } - inline bool operator!= (CharPointer_UTF16 other) const noexcept { return data != other.data; } - inline bool operator<= (CharPointer_UTF16 other) const noexcept { return data <= other.data; } - inline bool operator< (CharPointer_UTF16 other) const noexcept { return data < other.data; } - inline bool operator>= (CharPointer_UTF16 other) const noexcept { return data >= other.data; } - inline bool operator> (CharPointer_UTF16 other) const noexcept { return data > other.data; } + bool operator== (CharPointer_UTF16 other) const noexcept { return data == other.data; } + bool operator!= (CharPointer_UTF16 other) const noexcept { return data != other.data; } + bool operator<= (CharPointer_UTF16 other) const noexcept { return data <= other.data; } + bool operator< (CharPointer_UTF16 other) const noexcept { return data < other.data; } + bool operator>= (CharPointer_UTF16 other) const noexcept { return data >= other.data; } + bool operator> (CharPointer_UTF16 other) const noexcept { return data > other.data; } /** Returns the address that this pointer is pointing to. */ - inline CharType* getAddress() const noexcept { return data; } + CharType* getAddress() const noexcept { return data; } /** Returns the address that this pointer is pointing to. */ - inline operator const CharType*() const noexcept { return data; } + operator const CharType*() const noexcept { return data; } /** Returns true if this pointer is pointing to a null character. */ - inline bool isEmpty() const noexcept { return *data == 0; } + bool isEmpty() const noexcept { return *data == 0; } /** Returns true if this pointer is not pointing to a null character. */ - inline bool isNotEmpty() const noexcept { return *data != 0; } + bool isNotEmpty() const noexcept { return *data != 0; } /** Returns the unicode character that this pointer is pointing to. */ juce_wchar operator*() const noexcept @@ -103,7 +99,7 @@ public: } /** Moves this pointer along to the next character in the string. */ - CharPointer_UTF16 operator++() noexcept + CharPointer_UTF16& operator++() noexcept { auto n = (uint32) (uint16) *data++; @@ -114,7 +110,7 @@ public: } /** Moves this pointer back to the previous character in the string. */ - CharPointer_UTF16 operator--() noexcept + CharPointer_UTF16& operator--() noexcept { auto n = (uint32) (uint16) (*--data); @@ -145,7 +141,7 @@ public: } /** Moves this pointer forwards by the specified number of characters. */ - void operator+= (int numToSkip) noexcept + CharPointer_UTF16& operator+= (int numToSkip) noexcept { if (numToSkip < 0) { @@ -157,12 +153,14 @@ public: while (--numToSkip >= 0) ++*this; } + + return *this; } /** Moves this pointer backwards by the specified number of characters. */ - void operator-= (int numToSkip) noexcept + CharPointer_UTF16& operator-= (int numToSkip) noexcept { - operator+= (-numToSkip); + return operator+= (-numToSkip); } /** Returns the character at a given character index from the start of the string. */ @@ -176,17 +174,13 @@ public: /** Returns a pointer which is moved forwards from this one by the specified number of characters. */ CharPointer_UTF16 operator+ (int numToSkip) const noexcept { - auto p (*this); - p += numToSkip; - return p; + return CharPointer_UTF16 (*this) += numToSkip; } /** Returns a pointer which is moved backwards from this one by the specified number of characters. */ CharPointer_UTF16 operator- (int numToSkip) const noexcept { - auto p (*this); - p += -numToSkip; - return p; + return CharPointer_UTF16 (*this) -= numToSkip; } /** Writes a unicode character to this string, and advances this pointer to point to the next position. */ @@ -205,7 +199,7 @@ public: } /** Writes a null character to this string (leaving the pointer's position unchanged). */ - inline void writeNull() const noexcept + void writeNull() const noexcept { *data = 0; } diff --git a/modules/juce_core/text/juce_CharPointer_UTF32.h b/modules/juce_core/text/juce_CharPointer_UTF32.h index bd09be4c51..bfe1ad43b6 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF32.h +++ b/modules/juce_core/text/juce_CharPointer_UTF32.h @@ -48,57 +48,53 @@ class CharPointer_UTF32 final public: using CharType = juce_wchar; - inline explicit CharPointer_UTF32 (const CharType* rawPointer) noexcept + explicit CharPointer_UTF32 (const CharType* rawPointer) noexcept : data (const_cast (rawPointer)) { } - inline CharPointer_UTF32 (const CharPointer_UTF32& other) = default; + CharPointer_UTF32 (const CharPointer_UTF32& other) = default; - inline CharPointer_UTF32 operator= (CharPointer_UTF32 other) noexcept - { - data = other.data; - return *this; - } + CharPointer_UTF32& operator= (const CharPointer_UTF32& other) noexcept = default; - inline CharPointer_UTF32 operator= (const CharType* text) noexcept + CharPointer_UTF32& operator= (const CharType* text) noexcept { data = const_cast (text); return *this; } /** This is a pointer comparison, it doesn't compare the actual text. */ - 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; } + bool operator== (CharPointer_UTF32 other) const noexcept { return data == other.data; } + bool operator!= (CharPointer_UTF32 other) const noexcept { return data != other.data; } + bool operator<= (CharPointer_UTF32 other) const noexcept { return data <= other.data; } + bool operator< (CharPointer_UTF32 other) const noexcept { return data < other.data; } + bool operator>= (CharPointer_UTF32 other) const noexcept { return data >= other.data; } + bool operator> (CharPointer_UTF32 other) const noexcept { return data > other.data; } /** Returns the address that this pointer is pointing to. */ - inline CharType* getAddress() const noexcept { return data; } + CharType* getAddress() const noexcept { return data; } /** Returns the address that this pointer is pointing to. */ - inline operator const CharType*() const noexcept { return data; } + operator const CharType*() const noexcept { return data; } /** Returns true if this pointer is pointing to a null character. */ - inline bool isEmpty() const noexcept { return *data == 0; } + bool isEmpty() const noexcept { return *data == 0; } /** Returns true if this pointer is not pointing to a null character. */ - inline bool isNotEmpty() const noexcept { return *data != 0; } + bool isNotEmpty() const noexcept { return *data != 0; } /** Returns the unicode character that this pointer is pointing to. */ - inline juce_wchar operator*() const noexcept { return *data; } + juce_wchar operator*() const noexcept { return *data; } /** Moves this pointer along to the next character in the string. */ - inline CharPointer_UTF32 operator++() noexcept + CharPointer_UTF32& operator++() noexcept { ++data; return *this; } /** Moves this pointer to the previous character in the string. */ - inline CharPointer_UTF32 operator--() noexcept + CharPointer_UTF32& operator--() noexcept { --data; return *this; @@ -106,7 +102,7 @@ public: /** Returns the character that this pointer is currently pointing to, and then advances the pointer to point to the next character. */ - inline juce_wchar getAndAdvance() noexcept { return *data++; } + juce_wchar getAndAdvance() noexcept { return *data++; } /** Moves this pointer along to the next character in the string. */ CharPointer_UTF32 operator++ (int) noexcept @@ -117,18 +113,20 @@ public: } /** Moves this pointer forwards by the specified number of characters. */ - inline void operator+= (int numToSkip) noexcept + CharPointer_UTF32& operator+= (int numToSkip) noexcept { data += numToSkip; + return *this; } - inline void operator-= (int numToSkip) noexcept + CharPointer_UTF32& operator-= (int numToSkip) noexcept { data -= numToSkip; + return *this; } /** Returns the character at a given character index from the start of the string. */ - inline juce_wchar& operator[] (int characterIndex) const noexcept + juce_wchar& operator[] (int characterIndex) const noexcept { return data [characterIndex]; } @@ -136,28 +134,28 @@ public: /** Returns a pointer which is moved forwards from this one by the specified number of characters. */ CharPointer_UTF32 operator+ (int numToSkip) const noexcept { - return CharPointer_UTF32 (data + numToSkip); + return CharPointer_UTF32 (*this) += numToSkip; } /** Returns a pointer which is moved backwards from this one by the specified number of characters. */ CharPointer_UTF32 operator- (int numToSkip) const noexcept { - return CharPointer_UTF32 (data - numToSkip); + return CharPointer_UTF32 (*this) -= numToSkip; } /** Writes a unicode character to this string, and advances this pointer to point to the next position. */ - inline void write (juce_wchar charToWrite) noexcept + void write (juce_wchar charToWrite) noexcept { *data++ = charToWrite; } - inline void replaceChar (juce_wchar newChar) noexcept + void replaceChar (juce_wchar newChar) noexcept { *data = newChar; } /** Writes a null character to this string (leaving the pointer's position unchanged). */ - inline void writeNull() const noexcept + void writeNull() const noexcept { *data = 0; } diff --git a/modules/juce_core/text/juce_CharPointer_UTF8.h b/modules/juce_core/text/juce_CharPointer_UTF8.h index 78f257a498..f8679e73ce 100644 --- a/modules/juce_core/text/juce_CharPointer_UTF8.h +++ b/modules/juce_core/text/juce_CharPointer_UTF8.h @@ -55,13 +55,9 @@ public: CharPointer_UTF8 (const CharPointer_UTF8& other) = default; - CharPointer_UTF8 operator= (CharPointer_UTF8 other) noexcept - { - data = other.data; - return *this; - } + CharPointer_UTF8& operator= (const CharPointer_UTF8& other) noexcept = default; - CharPointer_UTF8 operator= (const CharType* text) noexcept + CharPointer_UTF8& operator= (const CharType* text) noexcept { data = const_cast (text); return *this; @@ -144,7 +140,7 @@ public: } /** Moves this pointer back to the previous character in the string. */ - CharPointer_UTF8 operator--() noexcept + CharPointer_UTF8& operator--() noexcept { int count = 0; @@ -201,7 +197,7 @@ public: } /** Moves this pointer forwards by the specified number of characters. */ - void operator+= (int numToSkip) noexcept + CharPointer_UTF8& operator+= (int numToSkip) noexcept { if (numToSkip < 0) { @@ -213,12 +209,14 @@ public: while (--numToSkip >= 0) ++*this; } + + return *this; } /** Moves this pointer backwards by the specified number of characters. */ - void operator-= (int numToSkip) noexcept + CharPointer_UTF8& operator-= (int numToSkip) noexcept { - operator+= (-numToSkip); + return operator+= (-numToSkip); } /** Returns the character at a given character index from the start of the string. */ @@ -232,17 +230,13 @@ public: /** Returns a pointer which is moved forwards from this one by the specified number of characters. */ CharPointer_UTF8 operator+ (int numToSkip) const noexcept { - auto p (*this); - p += numToSkip; - return p; + return CharPointer_UTF8 (*this) += numToSkip; } /** Returns a pointer which is moved backwards from this one by the specified number of characters. */ CharPointer_UTF8 operator- (int numToSkip) const noexcept { - auto p (*this); - p += -numToSkip; - return p; + return CharPointer_UTF8 (*this) -= numToSkip; } /** Returns the number of characters in this string. */