6#include "character_attributes.hpp"
7#include "../unicode/module.hpp"
8#include "../i18n/module.hpp"
9#include "../utility/module.hpp"
56 auto last = src +
count;
58 if (dest >= first and dest < last) {
74 auto r = std::lexicographical_compare_three_way(s1, s1 +
count, s2, s2 +
count);
75 return r == std::strong_ordering::equal ? 0 : r == std::strong_ordering::less ? -1 : 1;
82 while (*ptr++ !=
'\0') {}
89 auto last = p +
count;
100 auto tmp = hi::char_cast<char_type::value_type>(c);
109 return hi::char_cast<int_type>(c.intrinsic());
131namespace hi {
inline namespace v1 {
134using text_view = std::basic_string_view<character>;
144template<
typename It, std::sentinel_for<It> ItEnd>
145inline void fixup_script(It first, ItEnd last, iso_15924 default_script)
noexcept
146 requires(std::is_same_v<std::iter_value_t<It>,
character>)
150 auto last_language = iso_639{};
151 auto last_script = iso_15924{};
152 auto missing_script_count = 0_uz;
153 for (
auto it = first; it != last; ++it) {
154 hilet code_point = (*it)[0];
155 auto attributes = it->attributes();
156 hilet language = attributes.language();
157 hilet script = attributes.script();
160 if (language != last_language) {
161 last_language = language;
165 hilet new_script = [&] {
166 hilet udb_script = ucd_get_script(code_point);
168 if (udb_script != unicode_script::Zzzz and udb_script != unicode_script::Common) {
173 }
else if (not script and last_script) {
184 if (script != new_script) {
185 attributes.set_script(new_script);
186 it->set_attributes(attributes);
191 last_script = new_script;
193 ++missing_script_count;
197 if (missing_script_count == 0) {
205 last_script = default_script;
206 for (
auto rev_it = last; rev_it != first; --rev_it) {
207 hilet it = rev_it - 1;
208 auto attributes = it->attributes();
209 hilet script = attributes.script();
211 hilet new_script = script ? script : last_script;
214 if (script != new_script) {
215 attributes.set_script(script);
216 it->set_attributes(attributes);
221 last_script = new_script;
229template<std::ranges::range R>
230inline void fixup_script(R& str, iso_15924 default_script)
noexcept
231 requires(std::is_same_v<std::ranges::range_value_t<R>, character>)
233 return fixup_script(std::ranges::begin(str), std::ranges::end(str), default_script);
239[[nodiscard]]
inline text to_text(gstring_view str, character_attributes default_attributes)
noexcept
243 for (
hilet c : str) {
244 r += character{c, default_attributes};
252template<character_attribute... Args>
253[[nodiscard]]
inline text to_text(gstring_view str, Args
const&...args)
noexcept
255 return to_text(str, character_attributes{args...});
261[[nodiscard]]
inline text to_text(
262 std::string_view str,
263 unicode_normalize_config config,
264 character_attributes default_attributes)
noexcept
266 return to_text(to_gstring(str, config), default_attributes);
272[[nodiscard]]
inline text
273to_text(std::string_view str, character_attributes default_attributes)
noexcept
275 return to_text(to_gstring(str, unicode_normalize_config::NFC()), default_attributes);
282template<character_attribute... Args>
283[[nodiscard]]
inline text to_text(std::string_view str, unicode_normalize_config config, Args
const&...args)
noexcept
285 return to_text(str, config, character_attributes{args...});
291template<character_attribute... Args>
292[[nodiscard]]
inline text to_text(std::string_view str, Args
const&...args)
noexcept
294 return to_text(str, unicode_normalize_config::NFC(), character_attributes{args...});
300[[nodiscard]]
inline text to_text_with_markup(gstring_view str, character_attributes default_attributes)
noexcept
303 auto attributes = default_attributes;
305 auto in_command =
false;
308 auto output_incomplete_command = [&] {
309 r += character{
'[', attributes};
310 for (
hilet cap_c : capture) {
311 r += character{cap_c, attributes};
315 for (
hilet c : str) {
320 auto output_bad_command = [&] {
321 output_incomplete_command();
322 r += character{
']', attributes};
325 if (capture.empty()) {
326 output_bad_command();
328 }
else if (capture.size() == 1) {
329 if (capture.front() ==
'.') {
330 attributes = default_attributes;
331 }
else if (
auto phrasing = to_text_phrasing(capture.front())) {
332 attributes.set_phrasing(*phrasing);
334 output_bad_command();
337 }
else if (is_alpha(capture.front())) {
339 attributes.set_language(hi::language_tag{capture}.expand());
341 output_bad_command();
345 output_bad_command();
349 }
else if (c ==
'[' and capture.empty()) {
351 r += character{
'[', attributes};
353 }
else if (c.size() == 1 and c[0] <= 0x7f) {
354 capture += char_cast<char>(c[0]);
358 output_incomplete_command();
362 }
else if (c ==
'[') {
366 r += character{c, attributes};
370 if (not capture.empty()) {
371 output_incomplete_command();
381[[nodiscard]]
inline text to_text_with_markup(std::string_view str, character_attributes default_attributes)
noexcept
383 return to_text_with_markup(to_gstring(str), default_attributes);
389template<character_attribute... Attributes>
390[[nodiscard]]
inline text to_text_with_markup(gstring_view str, Attributes
const&...attributes)
noexcept
392 return to_text_with_markup(str, character_attributes{attributes...});
398template<character_attribute... Attributes>
399[[nodiscard]]
inline text to_text_with_markup(std::string_view str, Attributes
const&...attributes)
noexcept
401 return to_text_with_markup(str, character_attributes{attributes...});
407[[nodiscard]]
constexpr gstring to_gstring(text_view str)
noexcept
410 r.reserve(str.size());
411 for (
hilet c : str) {
444template<
typename It, std::sentinel_for<It> ItEnd>
446 requires(std::is_same_v<std::iter_value_t<It>,
character>)
448 for (
auto it = first; it != last; ++it) {
449 it->set_attributes(attributes);
457template<
typename It, std::sentinel_for<It> ItEnd,
character_attribute... Args>
459 requires(std::is_same_v<std::iter_value_t<It>,
character>)
467template<std::ranges::range R>
469 requires(std::is_same_v<std::ranges::range_value_t<R>,
character>)
471 return set_attributes(std::ranges::begin(str), std::ranges::end(str), attributes);
477template<std::ranges::range R, character_attribute... Args>
479 requires(std::is_same_v<std::ranges::range_value_t<R>,
character>)
491[[nodiscard]]
text to_text(std::integral
auto const& value)
noexcept
503[[nodiscard]]
text to_text(std::floating_point
auto const& value)
noexcept
517template<std::
integral T>
520 return from_string<T>(
to_string(str), base);
531template<std::
floating_po
int T>
Defines the standard HikoGUI character type.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
constexpr std::string to_string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:215
constexpr std::u32string to_u32string(std::u32string_view rhs) noexcept
Identity conversion from UTF-32 to UTF-32.
Definition to_string.hpp:23
constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
Conversion from UTF-32 to wide-string (UTF-16/32).
Definition to_string.hpp:155
T from_text(text_view str, int base=10)
Convert a string to an integer.
Definition text.hpp:518
void fixup_script(It first, ItEnd last, iso_15924 default_script) noexcept
Fixup the iso_15924 script in text.
Definition text.hpp:145
void set_attributes(It first, ItEnd last, character_attributes attributes) noexcept
Change the attributes on a piece of text.
Definition text.hpp:445
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
The standard HikoGUI character type.
Definition character.hpp:34
Definition character_attributes.hpp:13
Tag used in constructors to set the intrinsic value of that object.
Definition utility.hpp:242
T copy_backward(T... args)
T to_char_type(T... args)