8#include "unicode_normalization.hpp"
9#include "unicode_grapheme_cluster_break.hpp"
10#include "../utility/utility.hpp"
11#include "../macros.hpp"
20 using char_type = hi::grapheme;
21 using int_type = std::make_signed_t<char_type::value_type>;
25 using comparison_category = std::strong_ordering;
27 constexpr static void assign(char_type& r, char_type
const& a)
noexcept
41 [[nodiscard]]
constexpr static bool eq(char_type a, char_type b)
noexcept
46 [[nodiscard]]
constexpr static bool lt(char_type a, char_type b)
noexcept
51 constexpr static char_type *
move(char_type *dst, char_type
const *src,
std::size_t count)
noexcept
53 hi_axiom_not_null(src);
54 hi_axiom_not_null(dst);
62 dst[i - 1] = src[i - 1];
68 constexpr static char_type *
copy(char_type *dst, char_type
const *src,
std::size_t count)
noexcept
70 hi_axiom_not_null(src);
71 hi_axiom_not_null(dst);
81 hi_axiom_not_null(s1);
82 hi_axiom_not_null(s2);
86 return s1[i] < s2[i] ? -1 : 1;
97 while (s[i] !=
'\0') {
103 constexpr static char_type
const *
find(
const char_type *p,
std::size_t count,
const char_type& ch)
noexcept
105 hi_axiom_not_null(p);
115 constexpr static char_type
to_char_type(int_type c)
noexcept
120 constexpr static int_type
to_int_type(char_type c)
noexcept
125 constexpr static bool eq_int_type(int_type c1, int_type c2)
noexcept
130 constexpr static int_type
eof()
noexcept
135 constexpr static int_type
not_eof(int_type e)
noexcept
137 return e < 0 ? 0 : e;
141namespace hi::inline
v1 {
144hi_export
using gstring_view = std::basic_string_view<grapheme>;
147hi_export
using gstring = std::pmr::basic_string<grapheme>;
151[[nodiscard]]
constexpr bool operator==(gstring_view
const &lhs, std::string_view
const &rhs)
noexcept
153 if (lhs.size() != rhs.size()) {
157 auto l_it = lhs.begin();
158 auto l_last = lhs.end();
159 auto r_it = rhs.begin();
161 for (; l_it != l_last; ++l_it, ++r_it) {
162 if (*l_it != *r_it) {
177hi_export
template<std::input_or_output_iterator It, std::sentinel_for<It> ItEnd>
178constexpr void set_language(It first, ItEnd last, language_tag language)
noexcept
180 language = language.expand();
182 for (
auto it = first; it != last; ++it) {
183 it->set_language_tag(language);
187hi_export [[nodiscard]]
constexpr gstring set_language(gstring str, language_tag language)
noexcept
189 set_language(str.begin(), str.end(), language);
210hi_export
template<std::input_or_output_iterator It, std::sentinel_for<It> ItEnd>
211constexpr void fix_language(It first, ItEnd last, language_tag default_language_tag)
noexcept
212 requires(std::is_same_v<std::iter_value_t<It>,
grapheme>)
218 hilet first_language_it =
std::find_if(first, last, [](
auto &x) {
return x.language(); });
219 if (first_language_it != last) {
220 default_language_tag = first_language_it->language_tag().expand();
222 default_language_tag = default_language_tag.expand();
225 for (
auto it = first; it != first_language_it; ++it) {
226 it->set_language_tag(default_language_tag);
229 for (
auto it = first_language_it; it != last; ++it) {
230 if (not it->language()) {
231 it->set_language_tag(default_language_tag);
233 it->set_language_tag(it->language_tag().expand());
238hi_export [[nodiscard]]
constexpr gstring fix_language(gstring str, language_tag default_language_tag)
noexcept
240 fix_language(str.begin(), str.end(), default_language_tag);
253hi_export [[nodiscard]]
constexpr gstring
259 auto break_state = detail::grapheme_break_state{};
262 for (hilet code_point : normalized_string) {
263 if (detail::breaks_grapheme(code_point, break_state)) {
264 if (cluster.size() > 0) {
270 cluster += code_point;
272 if (ssize(cluster) != 0) {
287hi_export [[nodiscard]]
constexpr gstring
298hi_export [[nodiscard]]
constexpr std::string to_string(gstring_view rhs)
noexcept
302 for (hilet c : rhs) {
317 for (hilet c : rhs) {
332 for (hilet c : rhs) {
343hi_export [[nodiscard]]
constexpr std::string to_string(gstring
const& rhs)
noexcept
345 return to_string(gstring_view{rhs});
355 for (hilet c : rhs) {
367 for (hilet c : rhs) {
DOXYGEN BUG.
Definition algorithm.hpp:16
hi_export constexpr void fix_language(It first, ItEnd last, language_tag default_language_tag) noexcept
Fix the language for the string.
Definition gstring.hpp:211
hi_export constexpr std::u32string to_u32string(gstring_view rhs) noexcept
Convert a grapheme string to UTF-8.
Definition gstring.hpp:328
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:306
hi_export constexpr void set_language(It first, ItEnd last, language_tag language) noexcept
Set the language for the string.
Definition gstring.hpp:178
hi_export 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:254
hi_export constexpr std::wstring to_wstring(gstring_view rhs) noexcept
Convert a grapheme string to UTF-8.
Definition gstring.hpp:313
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out char_cast(In rhs) noexcept
Cast a character.
Definition cast.hpp:550
Definition grapheme.hpp:147
A grapheme-cluster, what a user thinks a character is.
Definition grapheme.hpp:160
Definition unicode_normalization.hpp:22
Tag used in constructors to set the intrinsic value of that object.
Definition misc.hpp:86
T to_char_type(T... args)