diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2024-09-22 12:41:28 -0500 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2024-09-22 12:41:28 -0500 |
commit | 7da829d48f9059c83ab9cada2c850621e8bbd3f3 (patch) | |
tree | 314e7a5b645e910d4997e3bee980bd2024f3087d /include | |
parent | bf81e34921e3e30b05313efbcf5c9fa839cb7c05 (diff) |
Basics of library.
Diffstat (limited to 'include')
-rw-r--r-- | include/fud_array.hpp (renamed from include/array.hpp) | 8 | ||||
-rw-r--r-- | include/fud_c_file.hpp (renamed from include/c_file.hpp) | 16 | ||||
-rw-r--r-- | include/fud_fud_type_traits.hpp (renamed from include/fud_type_traits.hpp) | 0 | ||||
-rw-r--r-- | include/fud_memory.hpp (renamed from include/memory.hpp) | 18 | ||||
-rw-r--r-- | include/fud_result.hpp (renamed from include/result.hpp) | 6 | ||||
-rw-r--r-- | include/fud_status.hpp (renamed from include/status.hpp) | 42 | ||||
-rw-r--r-- | include/fud_string.hpp (renamed from include/string.hpp) | 62 | ||||
-rw-r--r-- | include/fud_unique_array.hpp (renamed from include/unique_array.hpp) | 4 | ||||
-rw-r--r-- | include/fud_utf8.hpp (renamed from include/utf8.hpp) | 157 | ||||
-rw-r--r-- | include/fud_utf8_iterator.hpp | 56 | ||||
-rw-r--r-- | include/libfud.hpp | 4 | ||||
-rw-r--r-- | include/utf8_iterator.hpp | 39 |
12 files changed, 242 insertions, 170 deletions
diff --git a/include/array.hpp b/include/fud_array.hpp index 9de6c0a..4e2c702 100644 --- a/include/array.hpp +++ b/include/fud_array.hpp @@ -15,10 +15,10 @@ * limitations under the License. */ -#ifndef EXT_ARRAY_HPP -#define EXT_ARRAY_HPP +#ifndef FUD_ARRAY_HPP +#define FUD_ARRAY_HPP -#include "memory.hpp" +#include "fud_memory.hpp" #include <cstdlib> @@ -108,6 +108,6 @@ struct Array { constexpr auto operator<=>(const Array<T, Size>& other) const noexcept = default; }; -} // namespace ext_lib +} // namespace fud #endif diff --git a/include/c_file.hpp b/include/fud_c_file.hpp index 0f43e08..f89839d 100644 --- a/include/c_file.hpp +++ b/include/fud_c_file.hpp @@ -1,4 +1,5 @@ /* + * libfud * Copyright 2024 Dominick Allen * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,10 +18,11 @@ #ifndef FUD_C_FILE_HPP #define FUD_C_FILE_HPP -#include "result.hpp" +#include "fud_string.hpp" +#include "fud_result.hpp" #include <cstdint> -#include <string> +#include <cstdio> namespace fud { @@ -82,17 +84,17 @@ enum class FileResult class CBinaryFile { public: - CBinaryFile(const std::string& filename, CFileMode mode); - CBinaryFile(const std::string& filename, CFileMode mode, const std::string& extraFlags); + CBinaryFile(const String& filename, CFileMode mode); + CBinaryFile(const String& filename, CFileMode mode, const String& extraFlags); ~CBinaryFile(); FileResult open(); void close(); const FILE* file() const; private: - std::string m_filename; - std::string m_extraFlags{}; - std::string m_mode; + String m_filename; + String m_extraFlags{}; + String m_mode; CFileMode m_modeFlags; FILE* m_file{nullptr}; }; diff --git a/include/fud_type_traits.hpp b/include/fud_fud_type_traits.hpp index 3fdff79..3fdff79 100644 --- a/include/fud_type_traits.hpp +++ b/include/fud_fud_type_traits.hpp diff --git a/include/memory.hpp b/include/fud_memory.hpp index 1ca6029..d6708cd 100644 --- a/include/memory.hpp +++ b/include/fud_memory.hpp @@ -15,11 +15,11 @@ * limitations under the License. */ -#ifndef MEMORY_HPP -#define MEMORY_HPP +#ifndef FUD_MEMORY_HPP +#define FUD_MEMORY_HPP -#include "result.hpp" -#include "status.hpp" +#include "fud_result.hpp" +#include "fud_status.hpp" #include <cstddef> #include <cstdint> @@ -27,12 +27,22 @@ namespace fud { +extern void* fudAlloc(size_t size); +extern void* fudRealloc(size_t size); +extern void fudFree(void* ptr); + // An allocating function which returns null on failure. using FudAllocOne = void(*)(size_t); // An allocating function which returns null on failure. using FudAllocMany = void(*)(size_t, size_t); +/** \brief Copies from source to destination count bytes. + * + * \retcode FudStatus::Success + * \retcode FudStatus::NullPointer if destination or source are null + * \retcode FudStatus::InvalidInput if destination_size < count + */ FudStatus copyMem(void* destination, size_t destination_size, const void* source, size_t count); FudStatus compareMem(const void* lhs, size_t destination_size, const void* rhs, size_t count, int* difference); diff --git a/include/result.hpp b/include/fud_result.hpp index 158afd1..9c69800 100644 --- a/include/result.hpp +++ b/include/fud_result.hpp @@ -1,5 +1,5 @@ /* - * LibFud + * libfud * Copyright 2024 Dominick Allen * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +15,8 @@ * limitations under the License. */ -#ifndef BOOKMOUSE_RESULT_HPP -#define BOOKMOUSE_RESULT_HPP +#ifndef FUD_RESULT_HPP +#define FUD_RESULT_HPP #include <utility> #include <variant> diff --git a/include/status.hpp b/include/fud_status.hpp index 2bba4b3..47b14a4 100644 --- a/include/status.hpp +++ b/include/fud_status.hpp @@ -15,8 +15,8 @@ * limitations under the License. */ -#ifndef STATUS_HPP -#define STATUS_HPP +#ifndef FUD_STATUS_HPP +#define FUD_STATUS_HPP namespace fud { @@ -41,43 +41,43 @@ enum class [[nodiscard]] FudStatus NotSupported }; -static inline const char* ExtStatusToString(FudStatus status) +static inline const char* FudStatusToString(FudStatus status) { switch (status) { case FudStatus::Success: - return "ExtSuccess"; + return "Success"; case FudStatus::NullPointer: - return "ExtNullPointer"; + return "NullPointer"; case FudStatus::StringInvalid: - return "ExtStringInvalid"; + return "StringInvalid"; case FudStatus::OperationInvalid: - return "ExtOperationInvalid"; + return "OperationInvalid"; case FudStatus::AllocFailure: - return "ExtAllocFailure"; + return "AllocFailure"; case FudStatus::InvalidInput: - return "ExtInvalidInput"; + return "InvalidInput"; case FudStatus::Utf8Invalid: - return "ExtUtf8Invalid"; + return "Utf8Invalid"; case FudStatus::Failure: - return "ExtFailure"; + return "Failure"; case FudStatus::NotFound: - return "ExtNotFound"; + return "NotFound"; case FudStatus::Aliased: - return "ExtAliased"; + return "Aliased"; case FudStatus::Empty: - return "ExtEmpty"; + return "Empty"; case FudStatus::Partial: - return "ExtPartial"; + return "Partial"; case FudStatus::Full: - return "ExtFull"; + return "Full"; case FudStatus::RangeError: - return "ExtRangeError"; + return "RangeError"; case FudStatus::VariantInvalid: - return "ExtVariantInvalid"; + return "VariantInvalid"; case FudStatus::NotImplemented: - return "ExtNotImplemented"; + return "NotImplemented"; case FudStatus::NotSupported: - return "ExtNotSupported"; + return "NotSupported"; default: return "Unknown"; } @@ -101,6 +101,6 @@ bool anyAreNull(T pointer, Ts... pointers) return anyAreNull(pointers...); } -} // namespace ext_lib +} // namespace fud #endif diff --git a/include/string.hpp b/include/fud_string.hpp index 89aa94e..42009b4 100644 --- a/include/string.hpp +++ b/include/fud_string.hpp @@ -1,4 +1,5 @@ /* + * libfud * Copyright 2024 Dominick Allen * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,7 +18,7 @@ #ifndef FUD_STRING_HPP #define FUD_STRING_HPP -#include "utf8.hpp" +#include "fud_utf8.hpp" #include <climits> #include <cstddef> @@ -26,8 +27,21 @@ static_assert(CHAR_BIT == 8); namespace fud { +constexpr size_t SSO_BUF_LENGTH = 15; +constexpr size_t SSO_BUF_SIZE = SSO_BUF_LENGTH + 1; + class String { public: + String() = default; + explicit String(const utf8* cString); + explicit String(const char* cString); + String(const String& rhs); + String(String&& rhs); + ~String(); + + String& operator=(const String& rhs); + String& operator=(String&& rhs); + [[nodiscard]] constexpr size_t length() const { return m_length; @@ -43,9 +57,28 @@ class String { return m_capacity; } - [[nodiscard]] constexpr utf8* data() const + /** \brier The underlying data, guaranteed to have c string representation. */ + [[nodiscard]] constexpr const utf8* data() const { - return m_data; + return isLarge() ? m_data : m_buffer.data(); + } + + /** \brier The underlying data as an explicit c string. */ + [[nodiscard]] inline const char* c_str() const + { + return isLarge() ? reinterpret_cast<const char*>(m_data) : reinterpret_cast<const char*>(m_buffer.data()); + } + + /** \brier The underlying data, guaranteed to have c string representation. */ + [[nodiscard]] constexpr utf8* data() + { + return isLarge() ? m_data : m_buffer.data(); + } + + /** \brier The underlying data as an explicit c string. */ + [[nodiscard]] inline char* c_str() + { + return isLarge() ? reinterpret_cast<char*>(m_data) : reinterpret_cast<char*>(m_buffer.data()); } [[nodiscard]] bool nullTerminated() const; @@ -69,16 +102,27 @@ class String { [[nodiscard]] FudStatus pushBack(utf8 letter); - [[nodiscard]] FudStatus pushBack(const ExtUtf8& letter); + [[nodiscard]] FudStatus pushBack(const FudUtf8& letter); std::optional<utf8> pop(); [[nodiscard]] FudStatus catenate(StringView source); + [[nodiscard]] String append(const String& rhs) const; + private: - utf8* m_data; - size_t m_length; - size_t m_capacity; + using BufType = Array<utf8, SSO_BUF_SIZE>; + union { + BufType m_buffer{BufType::constFill(0)}; + utf8* m_data; + }; + size_t m_length{0}; + size_t m_capacity{0}; + + [[nodiscard]] constexpr bool isLarge() const + { + return m_capacity > SSO_BUF_LENGTH; + } }; class StringView { @@ -148,6 +192,10 @@ class StringView { FudStatus skipWhitespace(StringView& view, size_t& skipIndex); +ssize_t cStringLength(const char* str); + +ssize_t cStringLength(const char* str, size_t maxLength); + } // namespace fud #endif diff --git a/include/unique_array.hpp b/include/fud_unique_array.hpp index a7e0731..428374a 100644 --- a/include/unique_array.hpp +++ b/include/fud_unique_array.hpp @@ -18,8 +18,8 @@ #ifndef FUD_UNIQUE_ARRAY_HPP #define FUD_UNIQUE_ARRAY_HPP -#include "array.hpp" -#include "fud_type_traits.hpp" +#include "fud_array.hpp" +#include "fud_fud_type_traits.hpp" #include <cstdlib> #include <utility> diff --git a/include/utf8.hpp b/include/fud_utf8.hpp index c66d93c..da1a5fe 100644 --- a/include/utf8.hpp +++ b/include/fud_utf8.hpp @@ -18,15 +18,10 @@ #ifndef FUD_UTF8_HPP #define FUD_UTF8_HPP -#include "array.hpp" -#include "memory.hpp" -#include "status.hpp" -#include "unique_array.hpp" - -/* -#include "ext_hash.hpp" -#include "ext_set.hpp" -*/ +#include "fud_array.hpp" +#include "fud_memory.hpp" +#include "fud_status.hpp" +#include "fud_unique_array.hpp" #include <cstdint> #include <optional> @@ -238,33 +233,33 @@ struct Utf84Byte { using Utf8Variant = std::variant<Ascii, Utf82Byte, Utf83Byte, Utf84Byte>; -constexpr auto ExtUtf8TypeSet{UniqueArray<size_t, 0, 1, 2, 3>{}}; -enum class ExtUtf8Type : uint8_t +constexpr auto Utf8TypeSet{UniqueArray<size_t, 0, 1, 2, 3>{}}; +enum class Utf8Type : uint8_t { Ascii, Utf82Byte, Utf83Byte, Utf84Byte, }; -static_assert(ExtUtf8TypeSet.m_values[0] == static_cast<uint8_t>(ExtUtf8Type::Ascii)); -static_assert(ExtUtf8TypeSet.m_values[1] == static_cast<uint8_t>(ExtUtf8Type::Utf82Byte)); -static_assert(ExtUtf8TypeSet.m_values[2] == static_cast<uint8_t>(ExtUtf8Type::Utf83Byte)); -static_assert(ExtUtf8TypeSet.m_values[3] == static_cast<uint8_t>(ExtUtf8Type::Utf84Byte)); +static_assert(Utf8TypeSet.m_values[0] == static_cast<uint8_t>(Utf8Type::Ascii)); +static_assert(Utf8TypeSet.m_values[1] == static_cast<uint8_t>(Utf8Type::Utf82Byte)); +static_assert(Utf8TypeSet.m_values[2] == static_cast<uint8_t>(Utf8Type::Utf83Byte)); +static_assert(Utf8TypeSet.m_values[3] == static_cast<uint8_t>(Utf8Type::Utf84Byte)); class String; class StringView; -struct ExtUtf8 { +struct FudUtf8 { Utf8Variant m_variant{Utf8Variant{Ascii{}}}; static constexpr Ascii invalidAsciiCode{Ascii{0xFF}}; - static ExtUtf8 fromString(const String& fudString, size_t index) noexcept; - static ExtUtf8 fromStringView(StringView&& fudView, size_t index) noexcept; - static ExtUtf8 fromStringView(const StringView& fudView, size_t index) noexcept; + static FudUtf8 fromString(const String& fudString, size_t index) noexcept; + static FudUtf8 fromStringView(StringView&& fudView, size_t index) noexcept; + static FudUtf8 fromStringView(const StringView& fudView, size_t index) noexcept; - static constexpr ExtUtf8 makeUtf8(Array<utf8, 4>& data) + static constexpr FudUtf8 makeUtf8(Array<utf8, 4>& data) { - ExtUtf8 unicode{}; + FudUtf8 unicode{}; if (Ascii::valid(data[0])) { unicode.m_variant = Ascii{data[0]}; } else if (Utf82Byte::valid(data[0], data[1])) { @@ -279,9 +274,9 @@ struct ExtUtf8 { return unicode; } - static constexpr ExtUtf8 makeUtf8(const Ascii& utf8Char) + static constexpr FudUtf8 makeUtf8(const Ascii& utf8Char) { - ExtUtf8 unicode{{Utf8Variant{Ascii{}}}}; + FudUtf8 unicode{{Utf8Variant{Ascii{}}}}; if (utf8Char.valid()) { unicode.m_variant = utf8Char; } else { @@ -290,33 +285,33 @@ struct ExtUtf8 { return unicode; } - static constexpr ExtUtf8 invalidAscii() + static constexpr FudUtf8 invalidAscii() { - ExtUtf8 utf8{}; + FudUtf8 utf8{}; utf8.m_variant = Ascii{invalidAsciiCode}; return utf8; } - [[nodiscard]] constexpr ExtUtf8Type getType() const + [[nodiscard]] constexpr Utf8Type getType() const { - return static_cast<ExtUtf8Type>(m_variant.index()); + return static_cast<Utf8Type>(m_variant.index()); } [[nodiscard]] constexpr bool isAscii() const { - return getType() == ExtUtf8Type::Ascii; + return getType() == Utf8Type::Ascii; } [[nodiscard]] constexpr bool valid() const noexcept { switch (m_variant.index()) { - case static_cast<size_t>(ExtUtf8Type::Ascii): + case static_cast<size_t>(Utf8Type::Ascii): return std::get<Ascii>(m_variant).valid(); - case static_cast<size_t>(ExtUtf8Type::Utf82Byte): + case static_cast<size_t>(Utf8Type::Utf82Byte): return std::get<Utf82Byte>(m_variant).valid(); - case static_cast<size_t>(ExtUtf8Type::Utf83Byte): + case static_cast<size_t>(Utf8Type::Utf83Byte): return std::get<Utf83Byte>(m_variant).valid(); - case static_cast<size_t>(ExtUtf8Type::Utf84Byte): + case static_cast<size_t>(Utf8Type::Utf84Byte): return std::get<Utf84Byte>(m_variant).valid(); default: // unlikely return false; @@ -329,13 +324,13 @@ struct ExtUtf8 { return 0; } switch (m_variant.index()) { - case static_cast<size_t>(ExtUtf8Type::Ascii): + case static_cast<size_t>(Utf8Type::Ascii): return Ascii::size(); - case static_cast<size_t>(ExtUtf8Type::Utf82Byte): + case static_cast<size_t>(Utf8Type::Utf82Byte): return Utf82Byte::size(); - case static_cast<size_t>(ExtUtf8Type::Utf83Byte): + case static_cast<size_t>(Utf8Type::Utf83Byte): return Utf83Byte::size(); - case static_cast<size_t>(ExtUtf8Type::Utf84Byte): + case static_cast<size_t>(Utf8Type::Utf84Byte): return Utf84Byte::size(); default: // unlikely return 0; @@ -349,13 +344,13 @@ struct ExtUtf8 { } switch (m_variant.index()) { - case static_cast<size_t>(ExtUtf8Type::Ascii): + case static_cast<size_t>(Utf8Type::Ascii): return std::get<Ascii>(m_variant).characters.data(); - case static_cast<size_t>(ExtUtf8Type::Utf82Byte): + case static_cast<size_t>(Utf8Type::Utf82Byte): return std::get<Utf82Byte>(m_variant).characters.data(); - case static_cast<size_t>(ExtUtf8Type::Utf83Byte): + case static_cast<size_t>(Utf8Type::Utf83Byte): return std::get<Utf83Byte>(m_variant).characters.data(); - case static_cast<size_t>(ExtUtf8Type::Utf84Byte): + case static_cast<size_t>(Utf8Type::Utf84Byte): return std::get<Utf84Byte>(m_variant).characters.data(); default: // unlikely return nullptr; @@ -374,7 +369,7 @@ struct ExtUtf8 { [[nodiscard]] constexpr int64_t hash() const noexcept { - using fud::ExtUtf8Type; + using fud::Utf8Type; using fud::Utf82Byte; using fud::Utf83Byte; using fud::Utf84Byte; @@ -387,17 +382,17 @@ struct ExtUtf8 { constexpr uint8_t TwoByteShift = 2 * OneByteShift; constexpr uint8_t ThreeByteShift = 3 * OneByteShift; - switch (static_cast<ExtUtf8Type>(m_variant.index())) { - case ExtUtf8Type::Ascii: + switch (static_cast<Utf8Type>(m_variant.index())) { + case Utf8Type::Ascii: return std::get<Ascii>(m_variant).characters[0]; - case ExtUtf8Type::Utf82Byte: + case Utf8Type::Utf82Byte: return static_cast<int64_t>(std::get<Utf82Byte>(m_variant).characters[0]) << OneByteShift | static_cast<int64_t>(std::get<Utf82Byte>(m_variant).characters[1]); - case ExtUtf8Type::Utf83Byte: + case Utf8Type::Utf83Byte: return static_cast<int64_t>(std::get<Utf83Byte>(m_variant).characters[0]) << TwoByteShift | static_cast<int64_t>(std::get<Utf83Byte>(m_variant).characters[1]) << OneByteShift | static_cast<int64_t>(std::get<Utf83Byte>(m_variant).characters[2]); - case ExtUtf8Type::Utf84Byte: + case Utf8Type::Utf84Byte: return static_cast<int64_t>(std::get<Utf84Byte>(m_variant).characters[0]) << ThreeByteShift | static_cast<int64_t>(std::get<Utf84Byte>(m_variant).characters[1]) << TwoByteShift | static_cast<int64_t>(std::get<Utf84Byte>(m_variant).characters[2]) << OneByteShift | @@ -407,15 +402,15 @@ struct ExtUtf8 { } } - constexpr bool operator==(const ExtUtf8& other) const noexcept = default; + constexpr bool operator==(const FudUtf8& other) const noexcept = default; - constexpr auto operator<=>(const ExtUtf8& other) const noexcept + constexpr auto operator<=>(const FudUtf8& other) const noexcept { - auto hasSameAlternative = []<typename T>(const ExtUtf8& lhs, const ExtUtf8& rhs) noexcept { + auto hasSameAlternative = []<typename T>(const FudUtf8& lhs, const FudUtf8& rhs) noexcept { return std::holds_alternative<T>(lhs.m_variant) && std::holds_alternative<T>(rhs.m_variant); }; - auto getSameAlternative = []<typename T>(const ExtUtf8& lhs, const ExtUtf8& rhs) noexcept { + auto getSameAlternative = []<typename T>(const FudUtf8& lhs, const FudUtf8& rhs) noexcept { return std::get<T>(lhs.m_variant).operator<=>(std::get<T>(rhs.m_variant)); }; @@ -460,7 +455,7 @@ struct ExtUtf8 { std::optional<Ascii> getAscii() const { - if (m_variant.index() == static_cast<size_t>(ExtUtf8Type::Ascii)) { + if (m_variant.index() == static_cast<size_t>(Utf8Type::Ascii)) { return std::get<Ascii>(m_variant); } return std::nullopt; @@ -468,89 +463,89 @@ struct ExtUtf8 { }; /** \brief Checks if a character is ascii. */ -bool ext_lib_char_is_ascii(char character); +bool char_is_ascii(char character); -FudStatus ext_lib_utf8_is_ascii(ExtUtf8& character, bool& isAscii); +FudStatus utf8_is_ascii(FudUtf8& character, bool& isAscii); /** \brief Checks if a character is alphanumeric. */ -bool ext_lib_char_is_alphanumeric(char character); +bool char_is_alphanumeric(char character); /** \brief Checks if a character is alphanumeric. */ -FudStatus ext_lib_utf8_is_alphanumeric(ExtUtf8* character, bool* pred); +FudStatus utf8_is_alphanumeric(FudUtf8* character, bool* pred); /** \brief Checks if a character is alphabetic. */ -bool ext_lib_char_is_alpha(char character); +bool char_is_alpha(char character); /** \brief Checks if a character is alphabetic. */ -FudStatus ext_lib_utf8_is_alpha(ExtUtf8* character, bool* pred); +FudStatus utf8_is_alpha(FudUtf8* character, bool* pred); /** \brief Checks if a character is lowercase. */ -bool ext_lib_char_is_lowercase(char character); +bool char_is_lowercase(char character); /** \brief Checks if a character is lowercase. */ -FudStatus ext_lib_utf8_is_lowercase(ExtUtf8* character, bool* pred); +FudStatus utf8_is_lowercase(FudUtf8* character, bool* pred); /** \brief Checks if a character is an uppercase character. */ -bool ext_lib_char_is_uppercase(char character); +bool char_is_uppercase(char character); /** \brief Checks if a character is uppercase. */ -FudStatus ext_lib_utf8_is_uppercase(ExtUtf8* character, bool* pred); +FudStatus utf8_is_uppercase(FudUtf8* character, bool* pred); /** \brief Checks if a character is a digit. */ -bool ext_lib_char_is_digit(char character); +bool char_is_digit(char character); /** \brief Checks if a character is a digit. */ -FudStatus ext_lib_utf8_is_digit(ExtUtf8* character, bool* pred); +FudStatus utf8_is_digit(FudUtf8* character, bool* pred); /** \brief Checks if a character is a hexadecimal character. */ -bool ext_lib_char_is_hex_digit(char character); +bool char_is_hex_digit(char character); /** \brief Checks if a character is a hexadecimal digit. */ -FudStatus ext_lib_utf8_is_hex_digit(ExtUtf8* character, bool* pred); +FudStatus utf8_is_hex_digit(FudUtf8* character, bool* pred); /** \brief Checks if a character is a control character. */ -bool ext_lib_char_is_control(char character); +bool char_is_control(char character); /** \brief Checks if a character is a control character. */ -FudStatus ext_lib_utf8_is_control(ExtUtf8* character, bool* pred); +FudStatus utf8_is_control(FudUtf8* character, bool* pred); /** \brief Checks if a character is a graphical character. */ -bool ext_lib_char_is_graphical(char character); +bool char_is_graphical(char character); /** \brief Checks if a character is a graphical character. */ -FudStatus ext_lib_utf8_is_graphical(ExtUtf8* character, bool* pred); +FudStatus utf8_is_graphical(FudUtf8* character, bool* pred); /** \brief Checks if a character is a space character. */ -bool ext_lib_char_is_space(char character); +bool char_is_space(char character); /** \brief Checks if a character is a space character. */ -FudStatus ext_lib_utf8_is_space(ExtUtf8* character, bool* pred); +FudStatus utf8_is_space(FudUtf8* character, bool* pred); /** \brief Checks if a character is a blank character. */ -bool ext_lib_char_is_blank(char character); +bool char_is_blank(char character); /** \brief Checks if a character is a blank character. */ -FudStatus ext_lib_utf8_is_blank(ExtUtf8* character, bool* pred); +FudStatus utf8_is_blank(FudUtf8* character, bool* pred); /** \brief Checks if a character is a printable character. */ -bool ext_lib_char_is_printable(char character); +bool char_is_printable(char character); /** \brief Checks if a character is a printable character. */ -FudStatus ext_lib_utf8_is_printable(ExtUtf8* character, bool* pred); +FudStatus utf8_is_printable(FudUtf8* character, bool* pred); /** \brief Checks if a character is a punctuation character. */ -bool ext_lib_char_is_punctuation(char character); +bool char_is_punctuation(char character); /** \brief Checks if a character is a punctuation character. */ -FudStatus ext_lib_utf8_is_punctuation(ExtUtf8* character, bool* pred); +FudStatus utf8_is_punctuation(FudUtf8* character, bool* pred); -uint8_t ext_lib_char_to_lower(uint8_t character); +uint8_t char_to_lower(uint8_t character); -ExtUtf8* ext_lib_utf8_to_lower(ExtUtf8* character); +FudUtf8* utf8_to_lower(FudUtf8* character); -uint8_t ext_lib_char_to_upper(uint8_t character); +uint8_t char_to_upper(uint8_t character); -ExtUtf8* ext_lib_utf8_to_upper(ExtUtf8* character); +FudUtf8* utf8_to_upper(FudUtf8* character); } // namespace fud diff --git a/include/fud_utf8_iterator.hpp b/include/fud_utf8_iterator.hpp new file mode 100644 index 0000000..3721b00 --- /dev/null +++ b/include/fud_utf8_iterator.hpp @@ -0,0 +1,56 @@ +/* + * libfud + * Copyright 2024 Dominick Allen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUD_UTF8_ITERATOR_HPP +#define FUD_UTF8_ITERATOR_HPP + +#include "fud_string.hpp" +#include "fud_utf8.hpp" + +#include <cstddef> +#include <optional> + +namespace fud { + +class Utf8Iterator { + private: + size_t m_index{0}; + // NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members) + const StringView m_view; + // NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members) + + public: + explicit constexpr Utf8Iterator(const String& fudString) : m_view{fudString} + { + } + + explicit constexpr Utf8Iterator(const StringView& view) : m_view{view} + { + } + + constexpr void reset() + { + m_index = 0; + } + + [[nodiscard]] std::optional<FudUtf8> peek() const; + std::optional<FudUtf8> next(); +}; + +} // namespace fud + +#endif diff --git a/include/libfud.hpp b/include/libfud.hpp index ffea195..be840a4 100644 --- a/include/libfud.hpp +++ b/include/libfud.hpp @@ -1,5 +1,5 @@ /* - * LibFud + * libfud * Copyright 2024 Dominick Allen * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ #ifndef LIBFUD_HPP #define LIBFUD_HPP -#include "result.hpp" // IWYU pragma: export +#include "fud_result.hpp" // IWYU pragma: export namespace fud { diff --git a/include/utf8_iterator.hpp b/include/utf8_iterator.hpp deleted file mode 100644 index 1f9674b..0000000 --- a/include/utf8_iterator.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef FUD_UTF8_ITERATOR_HPP -#define FUD_UTF8_ITERATOR_HPP - -#include "string.hpp" -#include "utf8.hpp" - -#include <cstddef> -#include <optional> - -namespace fud { - -class Utf8Iterator { - private: - size_t m_index{0}; - // NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members) - const StringView m_view; - // NOLINTEND(cppcoreguidelines-avoid-const-or-ref-data-members) - - public: - explicit constexpr Utf8Iterator(const String& extString) : m_view{extString} - { - } - - explicit constexpr Utf8Iterator(const StringView& view) : m_view{view} - { - } - - constexpr void reset() - { - m_index = 0; - } - - [[nodiscard]] std::optional<ExtUtf8> peek() const; - std::optional<ExtUtf8> next(); -}; - -} // namespace fud - -#endif |