Browse Source

Rename to decode_result

master
Jessica James 3 years ago
parent
commit
3bb40fe082
  1. 2
      src/include/jessilib/http_query.hpp
  2. 12
      src/include/jessilib/unicode.hpp
  3. 32
      src/include/jessilib/unicode_base.hpp
  4. 12
      src/include/jessilib/unicode_compare.hpp
  5. 2
      src/include/jessilib/unicode_sequence.hpp
  6. 8
      src/include/jessilib/unicode_syntax.hpp

2
src/include/jessilib/http_query.hpp

@ -144,7 +144,7 @@ constexpr syntax_tree_member<CharT, ContextT> make_simple_shrink_pair() {
}
template<typename CharT, typename ContextT>
bool html_form_default_action(get_endpoint_result decode, ContextT& inout_context, std::basic_string_view<CharT>& inout_read_view) {
bool html_form_default_action(decode_result decode, ContextT& inout_context, std::basic_string_view<CharT>& 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;

12
src/include/jessilib/unicode.hpp

@ -89,7 +89,7 @@ bool is_valid(const InT& in_string) {
InViewT in_string_view = static_cast<InViewT>(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<OutCharT> 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<LhsCharT> in_string, char32_t in_codepoint) {
size_t codepoints_removed{};
while (!in_string.empty()) {
std::basic_string_view<LhsCharT> 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<LhsCharT> in_string, std::basic_string_view<R
std::basic_string_view<LhsCharT> string = in_string;
std::basic_string_view<RhsCharT> 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<InCharT> in_view = in_string;
while ((decode = decode_codepoint(in_view)).units != 0) {
encode_codepoint(out_string, decode.codepoint);

32
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<typename CharT>
constexpr get_endpoint_result decode_codepoint_utf8(std::basic_string_view<CharT> in_string); // UTF-8
constexpr decode_result decode_codepoint_utf8(std::basic_string_view<CharT> in_string); // UTF-8
template<typename CharT>
constexpr get_endpoint_result decode_codepoint_utf16(std::basic_string_view<CharT> in_string); // UTF-16
constexpr decode_result decode_codepoint_utf16(std::basic_string_view<CharT> in_string); // UTF-16
template<typename CharT>
constexpr get_endpoint_result decode_codepoint_utf32(std::basic_string_view<CharT> in_string); // UTF-32
constexpr decode_result decode_codepoint_utf32(std::basic_string_view<CharT> in_string); // UTF-32
template<typename CharT>
constexpr get_endpoint_result decode_codepoint(std::basic_string_view<CharT> in_string); // ASSUMES UTF-16 OR UTF-32
constexpr decode_result decode_codepoint(std::basic_string_view<CharT> in_string); // ASSUMES UTF-16 OR UTF-32
template<typename CharT>
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<typename CharT>
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<T>& 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<typename CharT>
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<typename CharT>
constexpr get_endpoint_result decode_codepoint_utf8(std::basic_string_view<CharT> in_string) {
get_endpoint_result result{ 0, 0 };
constexpr decode_result decode_codepoint_utf8(std::basic_string_view<CharT> 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<CharT
}
template<typename CharT>
constexpr get_endpoint_result decode_codepoint_utf16(std::basic_string_view<CharT> in_string) {
constexpr decode_result decode_codepoint_utf16(std::basic_string_view<CharT> in_string) {
if (in_string.empty()) {
return { 0, 0 };
}
@ -449,7 +449,7 @@ constexpr get_endpoint_result decode_codepoint_utf16(std::basic_string_view<Char
}
template<typename CharT>
constexpr get_endpoint_result decode_codepoint_utf32(std::basic_string_view<CharT> in_string) {
constexpr decode_result decode_codepoint_utf32(std::basic_string_view<CharT> in_string) {
if (in_string.empty()) {
return { 0, 0 };
}
@ -458,7 +458,7 @@ constexpr get_endpoint_result decode_codepoint_utf32(std::basic_string_view<Char
}
template<typename CharT>
constexpr get_endpoint_result decode_codepoint(std::basic_string_view<CharT> in_string) {
constexpr decode_result decode_codepoint(std::basic_string_view<CharT> in_string) {
if constexpr (std::is_same_v<CharT, char8_t>) {
return decode_codepoint_utf8(in_string);
}
@ -482,12 +482,12 @@ constexpr get_endpoint_result decode_codepoint(std::basic_string_view<CharT> in_
}
template<typename CharT>
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<CharT>(std::basic_string_view<CharT>{in_begin, in_length});
}
template<typename CharT>
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<CharT>(std::basic_string_view<CharT>{in_begin, static_cast<size_t>(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

12
src/include/jessilib/unicode_compare.hpp

@ -145,8 +145,8 @@ size_t starts_with_length(std::basic_string_view<LhsCharT> 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<LhsCharT> 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) {

2
src/include/jessilib/unicode_sequence.hpp

@ -89,7 +89,7 @@ constexpr bool apply_shrink_sequence_tree(std::basic_string<CharT>& inout_string
std::basic_string_view<CharT> 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) {

8
src/include/jessilib/unicode_syntax.hpp

@ -37,7 +37,7 @@ template<typename CharT, typename ContextT>
using syntax_tree_action = bool(*)(ContextT& inout_context, std::basic_string_view<CharT>& inout_read_view);
template<typename CharT, typename ContextT>
using default_syntax_tree_action = bool(*)(get_endpoint_result in_codepoint, ContextT& inout_context, std::basic_string_view<CharT>& inout_read_view);
using default_syntax_tree_action = bool(*)(decode_result in_codepoint, ContextT& inout_context, std::basic_string_view<CharT>& inout_read_view);
template<typename CharT, typename ContextT>
using syntax_tree = const std::pair<char32_t, syntax_tree_action<CharT, ContextT>>[];
@ -73,12 +73,12 @@ constexpr bool is_sorted() {
}
template<typename CharT, typename ContextT>
bool fail_action(get_endpoint_result, ContextT&, std::basic_string_view<CharT>&) {
bool fail_action(decode_result, ContextT&, std::basic_string_view<CharT>&) {
return false;
}
template<typename CharT, typename ContextT>
bool noop_action(get_endpoint_result decode, ContextT&, std::basic_string_view<CharT>& inout_read_view) {
bool noop_action(decode_result decode, ContextT&, std::basic_string_view<CharT>& 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<CharT, ContextT>);

Loading…
Cancel
Save