summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominick Allen <djallen@librehumanitas.org>2024-11-03 13:04:00 -0600
committerDominick Allen <djallen@librehumanitas.org>2024-11-03 13:04:00 -0600
commit1e89700693e92bb9c78ace739c71431b74d91e22 (patch)
tree08d40bf1c650987fac55805ce4b930a19c065fec
parent9b4b87765d48d2d6aed6ac1f40c4aa2684fad766 (diff)
Rename FudUtf8 to Utf8.
-rw-r--r--include/fud_string.hpp11
-rw-r--r--include/fud_utf8.hpp64
-rw-r--r--include/fud_utf8_iterator.hpp4
-rw-r--r--source/fud_string.cpp18
-rw-r--r--source/fud_utf8.cpp38
-rw-r--r--source/fud_utf8_iterator.cpp8
-rw-r--r--test/test_utf8.cpp82
7 files changed, 124 insertions, 101 deletions
diff --git a/include/fud_string.hpp b/include/fud_string.hpp
index 86261c4..935e1c1 100644
--- a/include/fud_string.hpp
+++ b/include/fud_string.hpp
@@ -286,16 +286,25 @@ class String {
/** \brief Attempts to reserve newCapacity bytes of storage. */
FudStatus reserve(size_t newCapacity);
+ /** \brief Returns the first character in the sequence if the length is
+ * greater than zero. */
+ [[nodiscard]] Option<utf8> front();
+
/** \brief Returns the last character in the sequence if the length is
* greater than zero. */
[[nodiscard]] Option<utf8> back();
+ /** \brief Append a character to the back of the string, growing it if necessary. */
FudStatus pushBack(char letter);
+ /** @copydoc String::pushBack(char letter) */
FudStatus pushBack(utf8 letter);
- FudStatus pushBack(const FudUtf8& letter);
+ /** @copydoc String::pushBack(char letter) */
+ FudStatus pushBack(const Utf8& letter);
+ /** \brief Pop and return a character from the back of the string if its
+ * length is greater than zero. */
Option<utf8> pop();
FudStatus append(const char* source);
diff --git a/include/fud_utf8.hpp b/include/fud_utf8.hpp
index 414352f..119640c 100644
--- a/include/fud_utf8.hpp
+++ b/include/fud_utf8.hpp
@@ -281,18 +281,18 @@ static_assert(Utf8TypeSet.m_values[1] == static_cast<uint8_t>(Utf8Type::Utf82Byt
static_assert(Utf8TypeSet.m_values[2] == static_cast<uint8_t>(Utf8Type::Utf83Byte));
static_assert(Utf8TypeSet.m_values[3] == static_cast<uint8_t>(Utf8Type::Utf84Byte));
-struct FudUtf8 {
+struct Utf8 {
Utf8Variant m_variant{Utf8Variant{Ascii{}}};
static constexpr Ascii invalidAsciiCode{Ascii{0xFF}};
- static FudUtf8 from(const String& fudString, size_t index) noexcept;
+ static Utf8 from(const String& fudString, size_t index) noexcept;
- static FudUtf8 from(StringView view, size_t index) noexcept;
+ static Utf8 from(StringView view, size_t index) noexcept;
- static constexpr FudUtf8 make(const Array<utf8, 4>& data)
+ static constexpr Utf8 make(const Array<utf8, 4>& data)
{
- FudUtf8 unicode{};
+ Utf8 unicode{};
if (Ascii::valid(data[0])) {
unicode.m_variant = Ascii{data[0]};
} else if (Utf82Byte::valid(data[0], data[1])) {
@@ -307,14 +307,14 @@ struct FudUtf8 {
return unicode;
}
- static constexpr FudUtf8 make(utf8 utf8Char)
+ static constexpr Utf8 make(utf8 utf8Char)
{
return make(Ascii{utf8Char});
}
- static constexpr FudUtf8 make(Ascii utf8Char)
+ static constexpr Utf8 make(Ascii utf8Char)
{
- FudUtf8 unicode{{Utf8Variant{Ascii{}}}};
+ Utf8 unicode{{Utf8Variant{Ascii{}}}};
if (utf8Char.valid()) {
unicode.m_variant = utf8Char;
} else {
@@ -323,9 +323,9 @@ struct FudUtf8 {
return unicode;
}
- static constexpr FudUtf8 make(Utf8Variant utf8Variant)
+ static constexpr Utf8 make(Utf8Variant utf8Variant)
{
- FudUtf8 unicode{};
+ Utf8 unicode{};
unicode.m_variant = utf8Variant;
if (!std::visit([](auto arg) { return arg.valid(); }, utf8Variant)) {
unicode.m_variant = invalidAsciiCode;
@@ -333,9 +333,9 @@ struct FudUtf8 {
return unicode;
}
- static constexpr FudUtf8 invalidAscii()
+ static constexpr Utf8 invalidAscii()
{
- FudUtf8 character{};
+ Utf8 character{};
character.m_variant = Ascii{invalidAsciiCode};
return character;
}
@@ -450,15 +450,15 @@ struct FudUtf8 {
}
}
- constexpr bool operator==(const FudUtf8& other) const noexcept = default;
+ constexpr bool operator==(const Utf8& other) const noexcept = default;
- constexpr auto operator<=>(const FudUtf8& other) const noexcept
+ constexpr auto operator<=>(const Utf8& other) const noexcept
{
- auto hasSameAlternative = []<typename T>(const FudUtf8& lhs, const FudUtf8& rhs) noexcept {
+ auto hasSameAlternative = []<typename T>(const Utf8& lhs, const Utf8& rhs) noexcept {
return std::holds_alternative<T>(lhs.m_variant) && std::holds_alternative<T>(rhs.m_variant);
};
- auto getSameAlternative = []<typename T>(const FudUtf8& lhs, const FudUtf8& rhs) noexcept {
+ auto getSameAlternative = []<typename T>(const Utf8& lhs, const Utf8& rhs) noexcept {
return std::get<T>(lhs.m_variant).operator<=>(std::get<T>(rhs.m_variant));
};
@@ -514,14 +514,14 @@ namespace classify {
using CharPredicate = bool (*)(char);
using Utf8Predicate = bool (*)(utf8);
-using FudUtf8Predicate = bool (*)(FudUtf8);
+using FudUtf8Predicate = bool (*)(Utf8);
/** \brief Checks if a character is ascii. */
[[nodiscard]] bool isAscii(char character);
[[nodiscard]] bool isAscii(utf8 character);
-[[nodiscard]] bool isAscii(FudUtf8 character);
+[[nodiscard]] bool isAscii(Utf8 character);
/** \brief Checks if a character is alphanumeric. */
[[nodiscard]] bool isAlphanumeric(char character);
@@ -530,7 +530,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isAlphanumeric(utf8 character);
/** \brief Checks if a character is alphanumeric. */
-[[nodiscard]] bool isAlphanumeric(FudUtf8 character);
+[[nodiscard]] bool isAlphanumeric(Utf8 character);
/** \brief Checks if a character is alphabetic. */
[[nodiscard]] bool isAlpha(char character);
@@ -539,7 +539,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isAlpha(utf8 character);
/** \brief Checks if a character is alphabetic. */
-[[nodiscard]] bool isAlpha(FudUtf8 character);
+[[nodiscard]] bool isAlpha(Utf8 character);
/** \brief Checks if a character is lowercase. */
[[nodiscard]] bool isLowercase(char character);
@@ -548,7 +548,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isLowercase(utf8 character);
/** \brief Checks if a character is lowercase. */
-[[nodiscard]] bool isLowercase(FudUtf8 character);
+[[nodiscard]] bool isLowercase(Utf8 character);
/** \brief Checks if a character is uppercase. */
[[nodiscard]] bool isUppercase(char character);
@@ -557,7 +557,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isUppercase(utf8 character);
/** \brief Checks if a character is uppercase. */
-[[nodiscard]] bool isUppercase(FudUtf8 character);
+[[nodiscard]] bool isUppercase(Utf8 character);
/** \brief Checks if a character is a digit. */
[[nodiscard]] bool isDigit(char character);
@@ -566,7 +566,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isDigit(utf8 character);
/** \brief Checks if a character is a digit. */
-[[nodiscard]] bool isDigit(FudUtf8 character);
+[[nodiscard]] bool isDigit(Utf8 character);
/** \brief Checks if a character is a hexadecimal character. */
[[nodiscard]] bool isHexDigit(char character);
@@ -575,7 +575,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isHexDigit(utf8 character);
/** \brief Checks if a character is a hexadecimal digit. */
-[[nodiscard]] bool isHexDigit(FudUtf8 character);
+[[nodiscard]] bool isHexDigit(Utf8 character);
/** \brief Checks if a character is a control character. */
[[nodiscard]] bool isControl(char character);
@@ -584,7 +584,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isControl(utf8 character);
/** \brief Checks if a character is a control character. */
-[[nodiscard]] bool isControl(FudUtf8 character);
+[[nodiscard]] bool isControl(Utf8 character);
/** \brief Checks if a character is a graphical character. */
[[nodiscard]] bool isGraphical(char character);
@@ -593,7 +593,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isGraphical(utf8 character);
/** \brief Checks if a character is a graphical character. */
-[[nodiscard]] bool isGraphical(FudUtf8 character);
+[[nodiscard]] bool isGraphical(Utf8 character);
/** \brief Checks if a character is a space character. */
[[nodiscard]] bool isSpace(char character);
@@ -602,7 +602,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isSpace(utf8 character);
/** \brief Checks if a character is a space character. */
-[[nodiscard]] bool isSpace(FudUtf8 character);
+[[nodiscard]] bool isSpace(Utf8 character);
/** \brief Checks if a character is a blank character. */
[[nodiscard]] bool isBlank(char character);
@@ -611,7 +611,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isBlank(utf8 character);
/** \brief Checks if a character is a blank character. */
-[[nodiscard]] bool isBlank(FudUtf8 character);
+[[nodiscard]] bool isBlank(Utf8 character);
/** \brief Checks if a character is a printable character. */
[[nodiscard]] bool isPrintable(char character);
@@ -620,7 +620,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isPrintable(utf8 character);
/** \brief Checks if a character is a printable character. */
-[[nodiscard]] bool isPrintable(FudUtf8 character);
+[[nodiscard]] bool isPrintable(Utf8 character);
/** \brief Checks if a character is a punctuation character. */
[[nodiscard]] bool isPunctuation(char character);
@@ -629,7 +629,7 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
[[nodiscard]] bool isPunctuation(utf8 character);
/** \brief Checks if a character is a punctuation character. */
-[[nodiscard]] bool isPunctuation(FudUtf8 character);
+[[nodiscard]] bool isPunctuation(Utf8 character);
} // namespace classify
@@ -637,13 +637,13 @@ using FudUtf8Predicate = bool (*)(FudUtf8);
uint8_t charToLower(uint8_t character);
/** \brief Converts character to lowercase if valid. */
-FudUtf8 utf8ToLower(FudUtf8 character);
+Utf8 utf8ToLower(Utf8 character);
/** \brief Converts character to uppercase if valid. */
uint8_t charToUpper(uint8_t character);
/** \brief Converts character to uppercase if valid. */
-FudUtf8 utf8ToUpper(FudUtf8 character);
+Utf8 utf8ToUpper(Utf8 character);
} // namespace fud
diff --git a/include/fud_utf8_iterator.hpp b/include/fud_utf8_iterator.hpp
index 25aaae6..4f036a4 100644
--- a/include/fud_utf8_iterator.hpp
+++ b/include/fud_utf8_iterator.hpp
@@ -47,8 +47,8 @@ class Utf8Iterator {
m_index = 0;
}
- [[nodiscard]] Option<FudUtf8> peek() const;
- Option<FudUtf8> next();
+ [[nodiscard]] Option<Utf8> peek() const;
+ Option<Utf8> next();
};
} // namespace fud
diff --git a/source/fud_string.cpp b/source/fud_string.cpp
index fa34cc9..cd3e918 100644
--- a/source/fud_string.cpp
+++ b/source/fud_string.cpp
@@ -371,9 +371,23 @@ FudStatus String::reserve(size_t newCapacity)
return resize(newCapacity);
}
+[[nodiscard]] Option<utf8> String::front()
+{
+ if (!valid() || length() < 1) {
+ return NullOpt;
+ }
+
+ utf8 frontChar = dataMut()[0];
+ if (Ascii::valid(frontChar)) {
+ return frontChar;
+ }
+
+ return NullOpt;
+}
+
[[nodiscard]] Option<utf8> String::back()
{
- if (!valid()) {
+ if (!valid() || length() < 1) {
return NullOpt;
}
@@ -443,7 +457,7 @@ FudStatus String::pushBack(utf8 letter)
return FudStatus::Success;
}
-FudStatus String::pushBack(const FudUtf8& letter)
+FudStatus String::pushBack(const Utf8& letter)
{
if (!valid()) {
return FudStatus::StringInvalid;
diff --git a/source/fud_utf8.cpp b/source/fud_utf8.cpp
index ec72b6d..d4b5442 100644
--- a/source/fud_utf8.cpp
+++ b/source/fud_utf8.cpp
@@ -21,12 +21,12 @@
namespace fud {
-FudUtf8 FudUtf8::from(const String& fudString, size_t index) noexcept
+Utf8 Utf8::from(const String& fudString, size_t index) noexcept
{
return from(fudString.asView(), index);
}
-FudUtf8 FudUtf8::from(StringView view, size_t index) noexcept
+Utf8 Utf8::from(StringView view, size_t index) noexcept
{
auto len = view.length();
const auto* vData = view.data();
@@ -34,7 +34,7 @@ FudUtf8 FudUtf8::from(StringView view, size_t index) noexcept
return invalidAscii();
}
- FudUtf8 localChar{Ascii{vData[index]}};
+ Utf8 localChar{Ascii{vData[index]}};
if (localChar.valid()) {
return localChar;
}
@@ -75,14 +75,14 @@ bool isAscii(utf8 character)
return (character & ~ASCII_MASK) == 0;
}
-bool isAscii(FudUtf8 character)
+bool isAscii(Utf8 character)
{
return character.getType() == Utf8Type::Ascii && character.valid();
}
namespace impl {
-bool isAsciiPredicate(FudUtf8 character, bool (*predicate)(char))
+bool isAsciiPredicate(Utf8 character, bool (*predicate)(char))
{
auto maybeAscii = character.getAscii();
if (!maybeAscii.hasValue()) {
@@ -113,7 +113,7 @@ bool isAlphanumeric(utf8 character)
return isDigit(character);
}
-bool isAlphanumeric(FudUtf8 character)
+bool isAlphanumeric(Utf8 character)
{
return impl::isAsciiPredicate(character, isAlphanumeric);
}
@@ -136,7 +136,7 @@ bool isAlpha(utf8 character)
return isLowercase(character);
}
-bool isAlpha(FudUtf8 character)
+bool isAlpha(Utf8 character)
{
return impl::isAsciiPredicate(character, isAlpha);
}
@@ -155,7 +155,7 @@ bool isLowercase(utf8 character)
return 'a' <= character && character <= 'z';
}
-bool isLowercase(FudUtf8 character)
+bool isLowercase(Utf8 character)
{
return impl::isAsciiPredicate(character, isLowercase);
}
@@ -174,7 +174,7 @@ bool isUppercase(utf8 character)
return 'A' <= character && character <= 'Z';
}
-bool isUppercase(FudUtf8 character)
+bool isUppercase(Utf8 character)
{
return impl::isAsciiPredicate(character, isUppercase);
}
@@ -193,7 +193,7 @@ bool isDigit(utf8 character)
return '0' <= character && character <= '9';
}
-bool isDigit(FudUtf8 character)
+bool isDigit(Utf8 character)
{
return impl::isAsciiPredicate(character, isDigit);
}
@@ -213,7 +213,7 @@ bool isHexDigit(utf8 character)
('A' <= character && character <= 'F');
}
-bool isHexDigit(FudUtf8 character)
+bool isHexDigit(Utf8 character)
{
return impl::isAsciiPredicate(character, isHexDigit);
}
@@ -234,7 +234,7 @@ bool isControl(utf8 character)
return ((static_cast<utf8>(character) <= maxControlChar)) || character == deleteChar;
}
-bool isControl(FudUtf8 character)
+bool isControl(Utf8 character)
{
return impl::isAsciiPredicate(character, isControl);
}
@@ -253,7 +253,7 @@ bool isGraphical(utf8 character)
return isAlphanumeric(character) || isPunctuation(character);
}
-bool isGraphical(FudUtf8 character)
+bool isGraphical(Utf8 character)
{
return impl::isAsciiPredicate(character, isGraphical);
}
@@ -272,7 +272,7 @@ bool isSpace(utf8 character)
return character == ' ' || character == '\t' || character == '\n' || character == '\r' || character == '\v';
}
-bool isSpace(FudUtf8 character)
+bool isSpace(Utf8 character)
{
return impl::isAsciiPredicate(character, isSpace);
}
@@ -291,7 +291,7 @@ bool isBlank(utf8 character)
return character == ' ' || character == '\t';
}
-bool isBlank(FudUtf8 character)
+bool isBlank(Utf8 character)
{
return impl::isAsciiPredicate(character, isBlank);
}
@@ -310,7 +310,7 @@ bool isPrintable(utf8 character)
return (character >= ' ' && character <= '~');
}
-bool isPrintable(FudUtf8 character)
+bool isPrintable(Utf8 character)
{
return impl::isAsciiPredicate(character, isPrintable);
}
@@ -330,7 +330,7 @@ bool isPunctuation(utf8 character)
(character >= '[' && character <= '`') || (character >= '{' && character <= '~');
}
-bool isPunctuation(FudUtf8 character)
+bool isPunctuation(Utf8 character)
{
return impl::isAsciiPredicate(character, isPunctuation);
}
@@ -347,7 +347,7 @@ uint8_t charToLower(uint8_t character)
return character;
}
-FudUtf8 utf8ToLower(FudUtf8 character)
+Utf8 utf8ToLower(Utf8 character)
{
static_cast<void>(
character.transformAscii([](Ascii& ascii) { ascii = Ascii{charToLower(static_cast<utf8>(ascii.asChar()))}; }));
@@ -365,7 +365,7 @@ uint8_t charToUpper(uint8_t character)
return character;
}
-FudUtf8 utf8ToUpper(FudUtf8 character)
+Utf8 utf8ToUpper(Utf8 character)
{
static_cast<void>(
character.transformAscii([](Ascii& ascii) { ascii = Ascii{charToUpper(static_cast<utf8>(ascii.asChar()))}; }));
diff --git a/source/fud_utf8_iterator.cpp b/source/fud_utf8_iterator.cpp
index 00ce146..5bdc784 100644
--- a/source/fud_utf8_iterator.cpp
+++ b/source/fud_utf8_iterator.cpp
@@ -19,13 +19,13 @@
namespace fud {
-Option<FudUtf8> Utf8Iterator::peek() const
+Option<Utf8> Utf8Iterator::peek() const
{
if (m_index >= m_view.length()) {
return NullOpt;
}
- auto character = FudUtf8::from(m_view, m_index);
+ auto character = Utf8::from(m_view, m_index);
if (!character.valid()) {
return NullOpt;
@@ -34,14 +34,14 @@ Option<FudUtf8> Utf8Iterator::peek() const
return character;
}
-Option<FudUtf8> Utf8Iterator::next()
+Option<Utf8> Utf8Iterator::next()
{
if (m_index >= m_view.length()) {
m_index = m_view.length();
return NullOpt;
}
- auto character = FudUtf8::from(m_view, m_index);
+ auto character = Utf8::from(m_view, m_index);
if (!character.valid()) {
m_index = m_view.length();
diff --git a/test/test_utf8.cpp b/test/test_utf8.cpp
index e5cb89a..a8e4969 100644
--- a/test/test_utf8.cpp
+++ b/test/test_utf8.cpp
@@ -65,7 +65,7 @@ constexpr size_t invalidAsciiSize = UINT8_MAX + 1 - validAsciiSize;
constexpr size_t numControlChars = 33;
constexpr char printableCharOffset = 0x20;
-constexpr auto invalidAscii = FudUtf8::invalidAsciiCode.character();
+constexpr auto invalidAscii = Utf8::invalidAsciiCode.character();
auto invalidAsciiGenerator()
{
@@ -75,7 +75,7 @@ auto invalidAsciiGenerator()
template <typename T>
auto toUtf8(T letter)
{
- return FudUtf8::make(static_cast<utf8>(letter));
+ return Utf8::make(static_cast<utf8>(letter));
}
template <typename T>
@@ -88,18 +88,18 @@ TEST(Utf8Test, Utf8Creation)
{
const Array<utf8, 4> threeByte = {THREE_BYTE};
- FudUtf8 utf8Point{FudUtf8::make(threeByte)};
+ Utf8 utf8Point{Utf8::make(threeByte)};
ASSERT_NE(utf8Point.data(), nullptr);
ASSERT_EQ(utf8Point.size(), 3);
ASSERT_NE(utf8Point.hash(), -1);
const Array<utf8, 4> asciiLetter = {'A'};
- utf8Point = FudUtf8::make(asciiLetter);
+ utf8Point = Utf8::make(asciiLetter);
ASSERT_NE(utf8Point.data(), nullptr);
ASSERT_EQ(utf8Point.size(), 1);
const Array<utf8, 4> twoByte = {TWO_BYTE};
- utf8Point = FudUtf8::make(twoByte);
+ utf8Point = Utf8::make(twoByte);
ASSERT_NE(utf8Point.data(), nullptr);
ASSERT_EQ(utf8Point.size(), 2);
ASSERT_NE(utf8Point.hash(), -1);
@@ -109,13 +109,13 @@ TEST(Utf8Test, Utf8Creation)
static_cast<utf8>(FOUR_BYTE[1]),
static_cast<utf8>(FOUR_BYTE[2]),
static_cast<utf8>(FOUR_BYTE[3])};
- utf8Point = FudUtf8::make(fourByte);
+ utf8Point = Utf8::make(fourByte);
ASSERT_NE(utf8Point.data(), nullptr);
ASSERT_EQ(utf8Point.size(), 4);
ASSERT_NE(utf8Point.hash(), -1);
const Array<utf8, 4> invalidBytes = {0xFF, 0xFF, 0xFF, 0xFF};
- utf8Point = FudUtf8::make(invalidBytes);
+ utf8Point = Utf8::make(invalidBytes);
ASSERT_EQ(utf8Point.data(), nullptr);
ASSERT_EQ(utf8Point.size(), 0);
ASSERT_EQ(utf8Point.hash(), -1);
@@ -174,29 +174,29 @@ TEST(Utf8Test, Utf8MultiByte)
ASSERT_TRUE(characterOpt.hasValue());
// MULTI_BYTE_LITERAL "test今日素敵はですねƩ®😀z"
- const Array<FudUtf8, 16> multiByteCharacters{
- FudUtf8::make(Utf8Variant{Ascii{'t'}}),
- FudUtf8::make(Utf8Variant{Ascii{'e'}}),
- FudUtf8::make(Utf8Variant{Ascii{'s'}}),
- FudUtf8::make(Utf8Variant{Ascii{'t'}}),
- FudUtf8::from(StringView{sizeof("今"), "今"}, 0),
- FudUtf8::from(StringView{sizeof("日"), "日"}, 0),
- FudUtf8::from(StringView{sizeof("素"), "素"}, 0),
- FudUtf8::from(StringView{sizeof("敵"), "敵"}, 0),
- FudUtf8::from(StringView{sizeof("は"), "は"}, 0),
- FudUtf8::from(StringView{sizeof("で"), "で"}, 0),
- FudUtf8::from(StringView{sizeof("す"), "す"}, 0),
- FudUtf8::from(StringView{sizeof("ね"), "ね"}, 0),
- FudUtf8::from(StringView{sizeof("Ʃ"), "Ʃ"}, 0),
- FudUtf8::from(StringView{sizeof("®"), "®"}, 0),
- FudUtf8::from(StringView{sizeof("😀"), "😀"}, 0),
- FudUtf8::make(Utf8Variant{Ascii{'z'}}),
+ const Array<Utf8, 16> multiByteCharacters{
+ Utf8::make(Utf8Variant{Ascii{'t'}}),
+ Utf8::make(Utf8Variant{Ascii{'e'}}),
+ Utf8::make(Utf8Variant{Ascii{'s'}}),
+ Utf8::make(Utf8Variant{Ascii{'t'}}),
+ Utf8::from(StringView{sizeof("今"), "今"}, 0),
+ Utf8::from(StringView{sizeof("日"), "日"}, 0),
+ Utf8::from(StringView{sizeof("素"), "素"}, 0),
+ Utf8::from(StringView{sizeof("敵"), "敵"}, 0),
+ Utf8::from(StringView{sizeof("は"), "は"}, 0),
+ Utf8::from(StringView{sizeof("で"), "で"}, 0),
+ Utf8::from(StringView{sizeof("す"), "す"}, 0),
+ Utf8::from(StringView{sizeof("ね"), "ね"}, 0),
+ Utf8::from(StringView{sizeof("Ʃ"), "Ʃ"}, 0),
+ Utf8::from(StringView{sizeof("®"), "®"}, 0),
+ Utf8::from(StringView{sizeof("😀"), "😀"}, 0),
+ Utf8::make(Utf8Variant{Ascii{'z'}}),
};
size_t idx = 0;
while (characterOpt.hasValue()) {
auto character = characterOpt.value();
- if (character != FudUtf8{Utf8Variant{Ascii{'\0'}}}) {
+ if (character != Utf8{Utf8Variant{Ascii{'\0'}}}) {
EXPECT_TRUE(character.size() >= 1);
ASSERT_LT(idx, multiByteCharacters.size());
EXPECT_EQ(character.size(), multiByteCharacters[idx].size());
@@ -209,7 +209,7 @@ TEST(Utf8Test, Utf8MultiByte)
utf8Iter.reset();
ASSERT_TRUE(utf8Iter.next().hasValue());
- FudUtf8 invalid = FudUtf8::invalidAscii();
+ Utf8 invalid = Utf8::invalidAscii();
ASSERT_FALSE(invalid.valid());
ASSERT_EQ(invalid.size(), 0);
ASSERT_EQ(invalid.data(), nullptr);
@@ -228,14 +228,14 @@ TEST(Utf8Test, Utf8IsAscii)
ASSERT_FALSE(anyOf([&]() -> Option<char> { return invalidCharIota().map(toLetter<int16_t>); }, static_cast<CharPredicate>(isAscii)));
- FudUtf8 unicode{FudUtf8::invalidAscii()};
+ Utf8 unicode{Utf8::invalidAscii()};
ASSERT_FALSE(isAscii(unicode));
charIota.set(0);
- ASSERT_TRUE(allOf([&]() -> Option<FudUtf8> { return charIota().map(toUtf8<int16_t>); }, static_cast<FudUtf8Predicate>(isAscii)));
+ ASSERT_TRUE(allOf([&]() -> Option<Utf8> { return charIota().map(toUtf8<int16_t>); }, static_cast<FudUtf8Predicate>(isAscii)));
invalidCharIota.set(invalidAsciiSize);
- ASSERT_FALSE(anyOf([&]() -> Option<FudUtf8> { return invalidCharIota().map(toUtf8<int16_t>); }, static_cast<FudUtf8Predicate>(isAscii)));
+ ASSERT_FALSE(anyOf([&]() -> Option<Utf8> { return invalidCharIota().map(toUtf8<int16_t>); }, static_cast<FudUtf8Predicate>(isAscii)));
}
template <typename T, size_t Size = SIZE_MAX>
@@ -280,7 +280,7 @@ TEST(Utf8Test, Utf8IsAlphanumeric)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isAlphanumeric)));
- ASSERT_FALSE(isAlphanumeric(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isAlphanumeric(Utf8{Ascii{invalidAscii}}));
auto iotaGenerator = invalidAsciiGenerator();
auto generator = generate(
@@ -317,7 +317,7 @@ TEST(Utf8Test, Utf8IsAlpha)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isAlpha)));
- ASSERT_FALSE(isAlpha(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isAlpha(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, alphaChars.size()> alphaGenerator{alphaChars.span()};
auto utf8AlphaGenerator = [&]() { return alphaGenerator().map(toUtf8<uint16_t>); };
@@ -349,7 +349,7 @@ TEST(Utf8Test, Utf8IsLower)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isLowercase)));
- ASSERT_FALSE(isLowercase(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isLowercase(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, lowerChars.size()> lowerGenerator{lowerChars.span()};
auto utf8LowerGenerator = [&]() { return lowerGenerator().map(toUtf8<uint16_t>); };
@@ -381,7 +381,7 @@ TEST(Utf8Test, Utf8IsUpper)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isUppercase)));
- ASSERT_FALSE(isUppercase(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isUppercase(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, upperChars.size()> upperGenerator{upperChars.span()};
auto utf8UpperGenerator = [&]() { return upperGenerator().map(toUtf8<uint16_t>); };
@@ -413,7 +413,7 @@ TEST(Utf8Test, Utf8IsDigit)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isDigit)));
- ASSERT_FALSE(isDigit(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isDigit(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, digitChars.size()> digitGenerator{digitChars.span()};
auto utf8DigitGenerator = [&]() { return digitGenerator().map(toUtf8<uint16_t>); };
@@ -445,7 +445,7 @@ TEST(Utf8Test, Utf8IsHexDigit)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isHexDigit)));
- ASSERT_FALSE(isHexDigit(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isHexDigit(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, hexDigitChars.size()> hexDigitGenerator{hexDigitChars.span()};
auto utf8HexDigitGenerator = [&]() { return hexDigitGenerator().map(toUtf8<uint16_t>); };
@@ -477,7 +477,7 @@ TEST(Utf8Test, Utf8IsControl)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isControl)));
- ASSERT_FALSE(isControl(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isControl(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, controlChars.size()> controlGenerator{controlChars.span()};
auto utf8ControlGenerator = [&]() { return controlGenerator().map(toUtf8<uint16_t>); };
@@ -512,7 +512,7 @@ TEST(Utf8Test, Utf8IsGraphical)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isGraphical)));
- ASSERT_FALSE(isGraphical(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isGraphical(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, graphicalChars.size()> graphicalGenerator{graphicalChars.span()};
auto utf8GraphicalGenerator = [&]() { return graphicalGenerator().map(toUtf8<uint16_t>); };
@@ -547,7 +547,7 @@ TEST(Utf8Test, Utf8IsSpace)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isSpace)));
- ASSERT_FALSE(isSpace(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isSpace(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, spaceChars.size()> spaceGenerator{spaceChars.span()};
auto utf8SpaceGenerator = [&]() { return spaceGenerator().map(toUtf8<uint16_t>); };
@@ -582,7 +582,7 @@ TEST(Utf8Test, Utf8IsBlank)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isBlank)));
- ASSERT_FALSE(isBlank(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isBlank(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, blankChars.size()> blankGenerator{blankChars.span()};
auto utf8BlankGenerator = [&]() { return blankGenerator().map(toUtf8<uint16_t>); };
@@ -617,7 +617,7 @@ TEST(Utf8Test, Utf8IsPrintable)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isPrintable)));
- ASSERT_FALSE(isPrintable(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isPrintable(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, printableChars.size()> printableGenerator{printableChars.span()};
auto utf8PrintableGenerator = [&]() { return printableGenerator().map(toUtf8<uint16_t>); };
@@ -652,7 +652,7 @@ TEST(Utf8Test, Utf8IsPunctuation)
auto invalidAsciiChars = invalidAsciiGenerator();
ASSERT_FALSE(anyOf(invalidAsciiChars, static_cast<CharPredicate>(isPunctuation)));
- ASSERT_FALSE(isPunctuation(FudUtf8{Ascii{invalidAscii}}));
+ ASSERT_FALSE(isPunctuation(Utf8{Ascii{invalidAscii}}));
SpanGenerator<utf8, punctuationChars.size()> punctuationGenerator{punctuationChars.span()};
auto utf8PunctuationGenerator = [&]() { return punctuationGenerator().map(toUtf8<uint16_t>); };