8#include "unicode_normalization.hpp"
9#include "unicode_grapheme_cluster_break.hpp"
10#include "../utility/utility.hpp"
11#include "../i18n/i18n.hpp"
12#include "../time/time.hpp"
13#include "../macros.hpp"
25hi_export_module(hikogui.unicode.gstring);
27hi_export
namespace std {
31 using char_type = hi::grapheme;
32 using int_type = std::make_signed_t<char_type::value_type>;
36 using comparison_category = std::strong_ordering;
38 constexpr static void assign(char_type& r, char_type
const& a)
noexcept
52 [[nodiscard]]
constexpr static bool eq(char_type a, char_type b)
noexcept
57 [[nodiscard]]
constexpr static bool lt(char_type a, char_type b)
noexcept
62 constexpr static char_type *
move(char_type *dst, char_type
const *src,
std::size_t count)
noexcept
64 hi_axiom_not_null(src);
65 hi_axiom_not_null(dst);
73 dst[i - 1] = src[i - 1];
79 constexpr static char_type *
copy(char_type *dst, char_type
const *src,
std::size_t count)
noexcept
81 hi_axiom_not_null(src);
82 hi_axiom_not_null(dst);
92 hi_axiom_not_null(s1);
93 hi_axiom_not_null(s2);
97 return s1[i] < s2[i] ? -1 : 1;
105 hi_axiom_not_null(s);
108 while (s[i] !=
'\0') {
114 constexpr static char_type
const *
find(
const char_type *p,
std::size_t count,
const char_type& ch)
noexcept
116 hi_axiom_not_null(p);
126 constexpr static char_type
to_char_type(int_type c)
noexcept
131 constexpr static int_type
to_int_type(char_type c)
noexcept
136 constexpr static bool eq_int_type(int_type c1, int_type c2)
noexcept
141 constexpr static int_type
eof()
noexcept
146 constexpr static int_type
not_eof(int_type e)
noexcept
148 return e < 0 ? 0 : e;
157using gstring_view = std::basic_string_view<grapheme>;
160[[
nodiscard]]
constexpr bool operator==(gstring_view
const &lhs, std::string_view
const &rhs)
noexcept
162 if (lhs.size() != rhs.size()) {
166 auto l_it = lhs.begin();
168 auto r_it = rhs.begin();
186template<std::input_or_output_iterator It, std::sentinel_for<It> ItEnd>
189 language = language.expand();
191 for (
auto it = first;
it != last; ++
it) {
192 it->set_language_tag(language);
196[[
nodiscard]]
constexpr gstring set_language(gstring str, language_tag language)
noexcept
198 set_language(str.begin(), str.end(), language);
219template<std::input_or_output_iterator It, std::sentinel_for<It> ItEnd>
221 requires(std::is_same_v<std::iter_value_t<It>,
grapheme>)
239 if (
not it->language()) {
242 it->set_language_tag(
it->language_tag().expand());
272 if (detail::breaks_grapheme(code_point,
break_state)) {
311 for (
auto const c : rhs) {
326 for (
auto const c : rhs) {
341 for (
auto const c : rhs) {
354 return to_string(gstring_view{rhs});
359hi_export
namespace std {
366 for (
auto const c : rhs) {
constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
Identity conversion from UTF-32 to UTF-32.
Definition to_string.hpp:28
constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
Conversion from UTF-32 to wide-string (UTF-16/32).
Definition to_string.hpp:160
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
constexpr void fix_language(It first, ItEnd last, language_tag default_language_tag) noexcept
Fix the language for the string.
Definition gstring.hpp:220
constexpr gstring to_gstring(std::u32string_view rhs, unicode_normalize_config config=unicode_normalize_config::NFC()) noexcept
Convert a UTF-32 string-view to a grapheme-string.
Definition gstring.hpp:263
constexpr void set_language(It first, ItEnd last, language_tag language) noexcept
Set the language for the string.
Definition gstring.hpp:187
constexpr std::u32string unicode_normalize(std::u32string_view text, unicode_normalize_config config=unicode_normalize_config::NFC()) noexcept
Convert text to a Unicode composed normal form.
Definition unicode_normalization.hpp:308
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
Definition grapheme.hpp:154
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:167
Definition unicode_normalization.hpp:24
T to_char_type(T... args)