diff --git a/src/include/jessilib/http_query.hpp b/src/include/jessilib/http_query.hpp index b60f5c3..7d78ce9 100644 --- a/src/include/jessilib/http_query.hpp +++ b/src/include/jessilib/http_query.hpp @@ -144,7 +144,7 @@ constexpr syntax_tree_member make_simple_shrink_pair() { } template -bool html_form_default_action(get_endpoint_result decode, ContextT& inout_context, std::basic_string_view& inout_read_view) { +bool html_form_default_action(decode_result decode, ContextT& inout_context, std::basic_string_view& inout_read_view) { // A regular character; copy it and advance the read/write heads CharT*& write_head = inout_context.write_head; CharT* write_end = write_head + decode.units; diff --git a/src/include/jessilib/unicode.hpp b/src/include/jessilib/unicode.hpp index 25aadab..78c0787 100644 --- a/src/include/jessilib/unicode.hpp +++ b/src/include/jessilib/unicode.hpp @@ -89,7 +89,7 @@ bool is_valid(const InT& in_string) { InViewT in_string_view = static_cast(in_string); while (!in_string_view.empty()) { - get_endpoint_result string_front = decode_codepoint(in_string_view); + decode_result string_front = decode_codepoint(in_string_view); if (string_front.units == 0) { return false; } @@ -163,7 +163,7 @@ std::basic_string string_cast(const InT& in_string) { } while (!in_string_view.empty()) { - get_endpoint_result string_front = decode_codepoint(in_string_view); + decode_result string_front = decode_codepoint(in_string_view); if (string_front.units == 0) { return {}; } @@ -199,7 +199,7 @@ size_t find(std::basic_string_view in_string, char32_t in_codepoint) { size_t codepoints_removed{}; while (!in_string.empty()) { std::basic_string_view string = in_string; - get_endpoint_result string_front = decode_codepoint(string); + decode_result string_front = decode_codepoint(string); if (string_front.units == 0) { // Failed to decode front codepoint; bad unicode sequence @@ -267,12 +267,12 @@ size_t find(std::basic_string_view in_string, std::basic_string_view string = in_string; std::basic_string_view substring = in_substring; - get_endpoint_result string_front; + decode_result string_front; do { // TODO: optimize this for when in_string and in_substring are same type, by only decoding in_string, solely // to determine number of data units to compare string_front = decode_codepoint(string); - get_endpoint_result prefix_front = decode_codepoint(substring); + decode_result prefix_front = decode_codepoint(substring); if (string_front.units == 0 || prefix_front.units == 0) { @@ -386,7 +386,7 @@ constexpr void join_append(OutT& out_string, InT&& in_string, ArgsT&&... in_args } else { // Append over all the codepoints - get_endpoint_result decode; + decode_result decode; std::basic_string_view in_view = in_string; while ((decode = decode_codepoint(in_view)).units != 0) { encode_codepoint(out_string, decode.codepoint); diff --git a/src/include/jessilib/unicode_base.hpp b/src/include/jessilib/unicode_base.hpp index 034c7a0..83cda30 100644 --- a/src/include/jessilib/unicode_base.hpp +++ b/src/include/jessilib/unicode_base.hpp @@ -74,7 +74,7 @@ std::wstring encode_codepoint_w(char32_t in_codepoint); // ASSUMES UTF-16 OR UTF /** decode_codepoint */ -struct get_endpoint_result { +struct decode_result { char32_t codepoint{}; // Codepoint size_t units{}; // Number of data units codepoint was represented by, or 0 }; @@ -86,17 +86,17 @@ struct get_endpoint_result { * @return A struct containing a valid codepoint and the number of representative data units on success, zero otherwise. */ template -constexpr get_endpoint_result decode_codepoint_utf8(std::basic_string_view in_string); // UTF-8 +constexpr decode_result decode_codepoint_utf8(std::basic_string_view in_string); // UTF-8 template -constexpr get_endpoint_result decode_codepoint_utf16(std::basic_string_view in_string); // UTF-16 +constexpr decode_result decode_codepoint_utf16(std::basic_string_view in_string); // UTF-16 template -constexpr get_endpoint_result decode_codepoint_utf32(std::basic_string_view in_string); // UTF-32 +constexpr decode_result decode_codepoint_utf32(std::basic_string_view in_string); // UTF-32 template -constexpr get_endpoint_result decode_codepoint(std::basic_string_view in_string); // ASSUMES UTF-16 OR UTF-32 +constexpr decode_result decode_codepoint(std::basic_string_view in_string); // ASSUMES UTF-16 OR UTF-32 template -constexpr get_endpoint_result decode_codepoint(const CharT* in_begin, size_t in_length); +constexpr decode_result decode_codepoint(const CharT* in_begin, size_t in_length); template -constexpr get_endpoint_result decode_codepoint(const CharT* in_begin, const CharT* in_end); +constexpr decode_result decode_codepoint(const CharT* in_begin, const CharT* in_end); /** advance_codepoint */ @@ -125,7 +125,7 @@ bool is_valid_codepoint(const std::basic_string_view& in_string) { constexpr bool is_high_surrogate(char32_t in_codepoint); constexpr bool is_low_surrogate(char32_t in_codepoint); -constexpr get_endpoint_result decode_surrogate_pair(char16_t in_high_surrogate, char16_t in_low_surrogate); +constexpr decode_result decode_surrogate_pair(char16_t in_high_surrogate, char16_t in_low_surrogate); template struct unicode_traits : std::false_type {}; @@ -365,8 +365,8 @@ constexpr size_t encode_codepoint(CharT* out_buffer, char32_t in_codepoint) { /** decode_codepoint */ template -constexpr get_endpoint_result decode_codepoint_utf8(std::basic_string_view in_string) { - get_endpoint_result result{ 0, 0 }; +constexpr decode_result decode_codepoint_utf8(std::basic_string_view in_string) { + decode_result result{ 0, 0 }; if (in_string.empty()) { return result; @@ -426,7 +426,7 @@ constexpr get_endpoint_result decode_codepoint_utf8(std::basic_string_view -constexpr get_endpoint_result decode_codepoint_utf16(std::basic_string_view in_string) { +constexpr decode_result decode_codepoint_utf16(std::basic_string_view in_string) { if (in_string.empty()) { return { 0, 0 }; } @@ -449,7 +449,7 @@ constexpr get_endpoint_result decode_codepoint_utf16(std::basic_string_view -constexpr get_endpoint_result decode_codepoint_utf32(std::basic_string_view in_string) { +constexpr decode_result decode_codepoint_utf32(std::basic_string_view in_string) { if (in_string.empty()) { return { 0, 0 }; } @@ -458,7 +458,7 @@ constexpr get_endpoint_result decode_codepoint_utf32(std::basic_string_view -constexpr get_endpoint_result decode_codepoint(std::basic_string_view in_string) { +constexpr decode_result decode_codepoint(std::basic_string_view in_string) { if constexpr (std::is_same_v) { return decode_codepoint_utf8(in_string); } @@ -482,12 +482,12 @@ constexpr get_endpoint_result decode_codepoint(std::basic_string_view in_ } template -constexpr get_endpoint_result decode_codepoint(const CharT* in_begin, size_t in_length) { +constexpr decode_result decode_codepoint(const CharT* in_begin, size_t in_length) { return decode_codepoint(std::basic_string_view{in_begin, in_length}); } template -constexpr get_endpoint_result decode_codepoint(const CharT* in_begin, const CharT* in_end) { +constexpr decode_result decode_codepoint(const CharT* in_begin, const CharT* in_end) { return decode_codepoint(std::basic_string_view{in_begin, static_cast(in_end - in_begin)}); } @@ -499,7 +499,7 @@ constexpr bool is_low_surrogate(char32_t in_codepoint) { return in_codepoint >= 0xDC00 && in_codepoint <= 0xDFFF; } -constexpr get_endpoint_result decode_surrogate_pair(char16_t in_high_surrogate, char16_t in_low_surrogate) { +constexpr decode_result decode_surrogate_pair(char16_t in_high_surrogate, char16_t in_low_surrogate) { if (is_high_surrogate(in_high_surrogate) && is_low_surrogate((in_low_surrogate))) { // We have a valid surrogate pair; decode it into a codepoint and return diff --git a/src/include/jessilib/unicode_compare.hpp b/src/include/jessilib/unicode_compare.hpp index 7a68e30..97a4c31 100644 --- a/src/include/jessilib/unicode_compare.hpp +++ b/src/include/jessilib/unicode_compare.hpp @@ -145,8 +145,8 @@ size_t starts_with_length(std::basic_string_view in_string, std::basic size_t codepoints_removed{}; while (!in_string.empty() && !in_prefix.empty()) { - get_endpoint_result string_front = decode_codepoint(in_string); - get_endpoint_result prefix_front = decode_codepoint(in_prefix); + decode_result string_front = decode_codepoint(in_string); + decode_result prefix_front = decode_codepoint(in_prefix); if (string_front.units == 0 || prefix_front.units == 0) { @@ -195,8 +195,8 @@ size_t starts_with_lengthi(std::basic_string_view in_string, std::basi size_t codepoints_removed{}; while (!in_string.empty() && !in_prefix.empty()) { - get_endpoint_result string_front = decode_codepoint(in_string); - get_endpoint_result prefix_front = decode_codepoint(in_prefix); + decode_result string_front = decode_codepoint(in_string); + decode_result prefix_front = decode_codepoint(in_prefix); if (string_front.units == 0 || prefix_front.units == 0) { @@ -270,7 +270,7 @@ struct text_hash { static uint64_t hash(const CharT* data, const CharT* end) { uint64_t hash = 14695981039346656037ULL; - get_endpoint_result decode; + decode_result decode; while (data != end) { decode = decode_codepoint(data, end); if (decode.units == 0) { @@ -355,7 +355,7 @@ struct text_hashi { static uint64_t hash(const CharT* data, const CharT* end) { uint64_t hash = 14695981039346656037ULL; - get_endpoint_result decode; + decode_result decode; while (data != end) { decode = decode_codepoint(data, end - data); if (decode.units == 0) { diff --git a/src/include/jessilib/unicode_sequence.hpp b/src/include/jessilib/unicode_sequence.hpp index 34bc600..f288451 100644 --- a/src/include/jessilib/unicode_sequence.hpp +++ b/src/include/jessilib/unicode_sequence.hpp @@ -89,7 +89,7 @@ constexpr bool apply_shrink_sequence_tree(std::basic_string& inout_string std::basic_string_view read_view = inout_string; CharT* write_head = inout_string.data(); - get_endpoint_result decode; + decode_result decode; constexpr auto SubTreeEnd = SequenceTreeBegin + SequenceTreeSize; while ((decode = decode_codepoint(read_view)).units != 0) { diff --git a/src/include/jessilib/unicode_syntax.hpp b/src/include/jessilib/unicode_syntax.hpp index a37a7cd..8be0d8f 100644 --- a/src/include/jessilib/unicode_syntax.hpp +++ b/src/include/jessilib/unicode_syntax.hpp @@ -37,7 +37,7 @@ template using syntax_tree_action = bool(*)(ContextT& inout_context, std::basic_string_view& inout_read_view); template -using default_syntax_tree_action = bool(*)(get_endpoint_result in_codepoint, ContextT& inout_context, std::basic_string_view& inout_read_view); +using default_syntax_tree_action = bool(*)(decode_result in_codepoint, ContextT& inout_context, std::basic_string_view& inout_read_view); template using syntax_tree = const std::pair>[]; @@ -73,12 +73,12 @@ constexpr bool is_sorted() { } template -bool fail_action(get_endpoint_result, ContextT&, std::basic_string_view&) { +bool fail_action(decode_result, ContextT&, std::basic_string_view&) { return false; } template -bool noop_action(get_endpoint_result decode, ContextT&, std::basic_string_view& inout_read_view) { +bool noop_action(decode_result decode, ContextT&, std::basic_string_view& inout_read_view) { inout_read_view.remove_prefix(decode.units); return true; } @@ -111,7 +111,7 @@ constexpr bool apply_syntax_tree(ContextT& inout_context, std::basic_string_view return true; } - get_endpoint_result decode; + decode_result decode; constexpr auto SubTreeEnd = SequenceTreeBegin + SequenceTreeSize; while ((decode = decode_codepoint(inout_read_view)).units != 0) { auto parser = std::lower_bound(SequenceTreeBegin, SubTreeEnd, decode.codepoint, &syntax_tree_member_compare);