summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/fud_assert.cpp8
-rw-r--r--source/fud_format.cpp14
-rw-r--r--source/fud_string.cpp25
-rw-r--r--source/fud_string_view.cpp38
-rw-r--r--source/fud_utf8.cpp174
-rw-r--r--source/fud_utf8_iterator.cpp4
6 files changed, 131 insertions, 132 deletions
diff --git a/source/fud_assert.cpp b/source/fud_assert.cpp
index 98f17d0..3df6734 100644
--- a/source/fud_assert.cpp
+++ b/source/fud_assert.cpp
@@ -1,10 +1,11 @@
#include "fud_assert.hpp"
-#include "fud_array.hpp"
+// #include "fud_array.hpp"
#include <climits>
#include <cstdio>
-#include <format>
+#include <exception>
+// #include <format>
namespace fud {
@@ -20,15 +21,18 @@ constexpr auto MAX_LINE_CHARS = BITS_PER_OCTAL * sizeof(decltype(std::source_loc
fputs(file_name, stderr);
}
+ /*
constexpr std::size_t assertMsgSize = MAX_LINE_CHARS + 3;
Array<char, assertMsgSize> buffer{};
static_cast<void>(std::format_to_n(buffer.data(), buffer.size() - 1U, ":{}:", sourceLocation.line()));
buffer[buffer.size() - 1] = '\0';
fputs(buffer.data(), stderr);
+ */
fputs(sourceLocation.function_name(), stderr);
fputs(": ", stderr);
fputs(assertion, stderr);
+ fputc('\n', stderr);
std::terminate();
}
diff --git a/source/fud_format.cpp b/source/fud_format.cpp
new file mode 100644
index 0000000..ab1bb4f
--- /dev/null
+++ b/source/fud_format.cpp
@@ -0,0 +1,14 @@
+// #include "fud_format.hpp"
+
+namespace fud {
+
+/*
+Result<FormatSpec, FudStatus> FormatSpec::make(StringView view, size_t& length)
+{
+ static_cast<void>(view);
+ static_cast<void>(length);
+ return FudStatus::NotImplemented;
+}
+*/
+
+} // namespace fud
diff --git a/source/fud_string.cpp b/source/fud_string.cpp
index d354fe7..b714dfc 100644
--- a/source/fud_string.cpp
+++ b/source/fud_string.cpp
@@ -23,31 +23,6 @@
namespace fud {
-ssize_t cStringLength(const char* str)
-{
- constexpr auto maxLength = SSIZE_MAX - 1;
- return cStringLength(str, maxLength);
-}
-
-ssize_t cStringLength(const char* str, size_t maxLength)
-{
- if (str == nullptr || maxLength > (SSIZE_MAX - 1)) {
- return -1;
- }
-
- ssize_t size = 0;
-
- while (str[size] != 0 && static_cast<size_t>(size) < maxLength) {
- size++;
- }
-
- if (str[size] != 0 && static_cast<size_t>(size) == maxLength) {
- return static_cast<ssize_t>(maxLength) + 1;
- }
-
- return size;
-}
-
StringResult String::makeFromCString(const char* cString)
{
return makeFromCString(cString, &globalFudAllocator);
diff --git a/source/fud_string_view.cpp b/source/fud_string_view.cpp
index 23a4671..fdb63b3 100644
--- a/source/fud_string_view.cpp
+++ b/source/fud_string_view.cpp
@@ -61,7 +61,7 @@ Result<size_t, FudStatus> StringView::skipWhitespace()
return RetType::error(FudStatus::NullPointer);
}
size_t index = 0;
- while (m_length > 0 && char_is_space(static_cast<char>(m_data[0]))) {
+ while (m_length > 0 && charIsSpace(static_cast<char>(m_data[0]))) {
m_data++;
m_length--;
index++;
@@ -78,7 +78,7 @@ Result<size_t, FudStatus> StringView::trimWhitespace()
}
size_t count = 0;
- while (m_length > 0 && char_is_space(static_cast<char>(m_data[m_length - 1]))) {
+ while (m_length > 0 && charIsSpace(static_cast<char>(m_data[m_length - 1]))) {
m_length--;
count++;
}
@@ -86,6 +86,40 @@ Result<size_t, FudStatus> StringView::trimWhitespace()
return RetType::okay(count);
}
+bool StringView::advance()
+{
+ if (m_length < 1) {
+ return false;
+ }
+ m_length--;
+ m_data++;
+ return true;
+}
+
+void StringView::advanceUnsafe()
+{
+ fudAssert(m_length > 0);
+ m_length--;
+ m_data++;
+}
+
+bool StringView::advance(size_t size)
+{
+ if (size > m_length) {
+ return false;
+ }
+ m_length -= size;
+ m_data += size;
+ return true;
+}
+
+void StringView::advanceUnsafe(size_t size)
+{
+ fudAssert(size <= m_length);
+ m_length -= size;
+ m_data += size;
+}
+
#if 0
FudStatus fud_string_truncate(ExtBasicString* source, ssize_t newLength)
diff --git a/source/fud_utf8.cpp b/source/fud_utf8.cpp
index ee8137a..4d617da 100644
--- a/source/fud_utf8.cpp
+++ b/source/fud_utf8.cpp
@@ -19,26 +19,19 @@
#include "fud_string.hpp"
-#include <new> // IWYU pragma: keep - this is for placement new overloads.
-
namespace fud {
-FudUtf8 FudUtf8::fromString(const String& fudString, size_t index) noexcept
+FudUtf8 FudUtf8::from(const String& fudString, size_t index) noexcept
{
if (!fudString.valid()) {
return invalidAscii();
}
- return fromStringView(StringView{fudString}, index);
+ return from(StringView{fudString}, index);
}
-// FudUtf8 FudUtf8::fromStringView(const StringView& view, size_t index) noexcept
-// {
-// return fromStringView(StringView{view}, index);
-// }
-
-FudUtf8 FudUtf8::fromStringView(StringView view, size_t index) noexcept
+FudUtf8 FudUtf8::from(StringView view, size_t index) noexcept
{
auto viewLocal{view};
auto len = viewLocal.length();
@@ -76,126 +69,113 @@ FudUtf8 FudUtf8::fromStringView(StringView view, size_t index) noexcept
return invalidAscii();
}
-bool char_is_ascii(char character)
+bool charIsAscii(char character)
{
return static_cast<uint8_t>(character & ~ASCII_MASK) == 0;
}
-FudStatus utf8_is_ascii(FudUtf8* character, bool* isAscii)
+bool utf8IsAscii(FudUtf8 character)
{
- if (anyAreNull(character, isAscii)) {
- return FudStatus::NullPointer;
- }
-
- *isAscii = character->getType() == Utf8Type::Ascii && character->valid();
-
- return FudStatus::Success;
+ return character.getType() == Utf8Type::Ascii && character.valid();
}
namespace impl {
-/* Assumes that predicate is not a null pointer! */
template <typename Predicate>
-FudStatus isAsciiPredicate(FudUtf8* character, bool* pred, Predicate&& predicate)
+bool isAsciiPredicate(FudUtf8 character, Predicate&& predicate)
{
- if (anyAreNull(character, pred)) {
- return FudStatus::NullPointer;
- }
-
- auto maybeAscii = character->getAscii();
+ auto maybeAscii = character.getAscii();
if (!maybeAscii.has_value()) {
- return FudStatus::ArgumentInvalid;
+ return false;
}
auto asciiChar = *maybeAscii;
- *pred = std::forward<Predicate>(predicate)(asciiChar.asChar());
-
- return FudStatus::Success;
+ return std::forward<Predicate>(predicate)(asciiChar.asChar());
}
} // namespace impl
-bool char_is_alphanumeric(char character)
+bool charIsAlphanumeric(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
- if (char_is_alpha(character)) {
+ if (charIsAlpha(character)) {
return true;
}
- return char_is_digit(character);
+ return charIsDigit(character);
}
-FudStatus utf8_is_alphanumeric(FudUtf8* character, bool* pred)
+bool utf8IsAlphanumeric(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_alphanumeric);
+ return impl::isAsciiPredicate(character, charIsAlphanumeric);
}
-bool char_is_alpha(char character)
+bool charIsAlpha(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
- if (char_is_uppercase(character)) {
+ if (charIsUppercase(character)) {
return true;
}
- return char_is_lowercase(character);
+ return charIsLowercase(character);
}
-FudStatus utf8_is_alpha(FudUtf8* character, bool* pred)
+bool utf8IsAlpha(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_alpha);
+ return impl::isAsciiPredicate(character, charIsAlpha);
}
-bool char_is_lowercase(char character)
+bool charIsLowercase(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
return 'a' <= character && character <= 'z';
}
-FudStatus utf8_is_lowercase(FudUtf8* character, bool* pred)
+bool utf8IsLowercase(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_lowercase);
+ return impl::isAsciiPredicate(character, charIsLowercase);
}
-bool char_is_uppercase(char character)
+bool charIsUppercase(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
return 'A' <= character && character <= 'Z';
}
-FudStatus utf8_is_uppercase(FudUtf8* character, bool* pred)
+bool utf8IsUppercase(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_uppercase);
+ return impl::isAsciiPredicate(character, charIsUppercase);
}
-bool char_is_digit(char character)
+bool charIsDigit(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
return '0' <= character && character <= '9';
}
-FudStatus utf8_is_digit(FudUtf8* character, bool* pred)
+bool utf8IsDigit(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_digit);
+ return impl::isAsciiPredicate(character, charIsDigit);
}
-bool char_is_hex_digit(char character)
+bool charIsHexDigit(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
@@ -203,14 +183,14 @@ bool char_is_hex_digit(char character)
('A' <= character && character <= 'F');
}
-FudStatus utf8_is_hex_digit(FudUtf8* character, bool* pred)
+bool utf8IsHexDigit(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_hex_digit);
+ return impl::isAsciiPredicate(character, charIsHexDigit);
}
-bool char_is_control(char character)
+bool charIsControl(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
@@ -219,70 +199,70 @@ bool char_is_control(char character)
return ((static_cast<uint8_t>(character) <= maxControlChar)) || character == deleteChar;
}
-FudStatus utf8_is_control(FudUtf8* character, bool* pred)
+bool utf8IsControl(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_control);
+ return impl::isAsciiPredicate(character, charIsControl);
}
-bool char_is_graphical(char character)
+bool charIsGraphical(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
- return char_is_alphanumeric(character) || char_is_punctuation(character);
+ return charIsAlphanumeric(character) || charIsPunctuation(character);
}
-FudStatus utf8_is_graphical(FudUtf8* character, bool* pred)
+bool utf8IsGraphical(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_graphical);
+ return impl::isAsciiPredicate(character, charIsGraphical);
}
-bool char_is_space(char character)
+bool charIsSpace(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
return character == ' ' || character == '\t' || character == '\n' || character == '\r' || character == '\v';
}
-FudStatus utf8_is_space(FudUtf8* character, bool* pred)
+bool utf8IsSpace(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_space);
+ return impl::isAsciiPredicate(character, charIsSpace);
}
-bool char_is_blank(char character)
+bool charIsBlank(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
return character == ' ' || character == '\t';
}
-FudStatus utf8_is_blank(FudUtf8* character, bool* pred)
+bool utf8IsBlank(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_blank);
+ return impl::isAsciiPredicate(character, charIsBlank);
}
-bool char_is_printable(char character)
+bool charIsPrintable(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
return (character >= ' ' && character <= '~');
}
-FudStatus utf8_is_printable(FudUtf8* character, bool* pred)
+bool utf8IsPrintable(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_printable);
+ return impl::isAsciiPredicate(character, charIsPrintable);
}
-bool char_is_punctuation(char character)
+bool charIsPunctuation(char character)
{
- if (!char_is_ascii(character)) {
+ if (!charIsAscii(character)) {
return false;
}
@@ -290,14 +270,14 @@ bool char_is_punctuation(char character)
(character >= '[' && character <= '`') || (character >= '{' && character <= '~');
}
-FudStatus utf8_is_punctuation(FudUtf8* character, bool* pred)
+bool utf8IsPunctuation(FudUtf8 character)
{
- return impl::isAsciiPredicate(character, pred, char_is_punctuation);
+ return impl::isAsciiPredicate(character, charIsPunctuation);
}
-uint8_t char_to_lower(uint8_t character)
+uint8_t charToLower(uint8_t character)
{
- if (char_is_uppercase(static_cast<char>(character))) {
+ if (charIsUppercase(static_cast<char>(character))) {
constexpr uint8_t lowerA = 'a';
constexpr uint8_t upperA = 'A';
return static_cast<uint8_t>(character - upperA) + lowerA;
@@ -305,22 +285,18 @@ uint8_t char_to_lower(uint8_t character)
return character;
}
-FudUtf8* utf8_to_lower(FudUtf8* character)
+FudUtf8 utf8ToLower(FudUtf8 character)
{
- if (character == nullptr) {
- return character;
- }
-
- static_cast<void>(character->transformAscii([](Ascii& ascii) {
- ascii = Ascii{char_to_lower(static_cast<uint8_t>(ascii.asChar()))};
+ static_cast<void>(character.transformAscii([](Ascii& ascii) {
+ ascii = Ascii{charToLower(static_cast<uint8_t>(ascii.asChar()))};
}));
return character;
}
-uint8_t char_to_upper(uint8_t character)
+uint8_t charToUpper(uint8_t character)
{
- if (char_is_lowercase(static_cast<char>(character))) {
+ if (charIsLowercase(static_cast<char>(character))) {
constexpr uint8_t lowerA = 'a';
constexpr uint8_t upperA = 'A';
return static_cast<uint8_t>(character - lowerA) + upperA;
@@ -328,14 +304,10 @@ uint8_t char_to_upper(uint8_t character)
return character;
}
-FudUtf8* utf8_to_upper(FudUtf8* character)
+FudUtf8 utf8ToUpper(FudUtf8 character)
{
- if (character == nullptr) {
- return character;
- }
-
- static_cast<void>(character->transformAscii([](Ascii& ascii) {
- ascii = Ascii{char_to_upper(static_cast<uint8_t>(ascii.asChar()))};
+ static_cast<void>(character.transformAscii([](Ascii& ascii) {
+ ascii = Ascii{charToUpper(static_cast<uint8_t>(ascii.asChar()))};
}));
return character;
diff --git a/source/fud_utf8_iterator.cpp b/source/fud_utf8_iterator.cpp
index 2557dc0..a815c64 100644
--- a/source/fud_utf8_iterator.cpp
+++ b/source/fud_utf8_iterator.cpp
@@ -25,7 +25,7 @@ std::optional<FudUtf8> Utf8Iterator::peek() const
return std::nullopt;
}
- auto character = FudUtf8::fromStringView(m_view, m_index);
+ auto character = FudUtf8::from(m_view, m_index);
if (!character.valid()) {
return std::nullopt;
@@ -41,7 +41,7 @@ std::optional<FudUtf8> Utf8Iterator::next()
return std::nullopt;
}
- auto character = FudUtf8::fromStringView(m_view, m_index);
+ auto character = FudUtf8::from(m_view, m_index);
if (!character.valid()) {
m_index = m_view.length();