11#include "../utility/utility.hpp"
12#include "../macros.hpp"
19hi_export_module(hikogui.unicode.phrasing);
21hi_export
namespace hi::inline
v1 {
115constexpr auto phrasing_metadata = enum_metadata{
116 phrasing::regular,
"regular",
117 phrasing::emphasis,
"emphasis",
118 phrasing::strong,
"strong",
119 phrasing::code,
"code",
120 phrasing::abbreviation,
"abbreviation",
121 phrasing::quote,
"quote",
122 phrasing::keyboard,
"keyboard",
123 phrasing::highlight,
"highlight",
124 phrasing::math,
"math",
125 phrasing::example,
"example",
126 phrasing::placeholder,
"placeholder",
127 phrasing::unarticulated,
"unarticulated",
128 phrasing::title,
"title",
129 phrasing::success,
"success",
130 phrasing::warning,
"warning",
131 phrasing::error,
"error",
136[[nodiscard]]
constexpr std::optional<phrasing> to_phrasing(
char c)
139 case 'r':
return phrasing::regular;
140 case 'e':
return phrasing::emphasis;
141 case 's':
return phrasing::strong;
142 case 'c':
return phrasing::code;
143 case 'a':
return phrasing::abbreviation;
144 case 'q':
return phrasing::quote;
145 case 'k':
return phrasing::keyboard;
146 case 'h':
return phrasing::highlight;
147 case 'm':
return phrasing::math;
148 case 'x':
return phrasing::example;
149 case 'p':
return phrasing::placeholder;
150 case 'u':
return phrasing::unarticulated;
151 case 't':
return phrasing::title;
152 case 'S':
return phrasing::success;
153 case 'W':
return phrasing::warning;
154 case 'E':
return phrasing::error;
161enum class phrasing_mask : uint16_t {
162 regular = 1 << std::to_underlying(phrasing::regular),
163 emphasis = 1 << std::to_underlying(phrasing::emphasis),
164 strong = 1 << std::to_underlying(phrasing::strong),
165 code = 1 << std::to_underlying(phrasing::code),
166 abbreviation = 1 << std::to_underlying(phrasing::abbreviation),
167 quote = 1 << std::to_underlying(phrasing::quote),
168 keyboard = 1 << std::to_underlying(phrasing::keyboard),
169 highlight = 1 << std::to_underlying(phrasing::highlight),
170 math = 1 << std::to_underlying(phrasing::math),
171 example = 1 << std::to_underlying(phrasing::example),
172 placeholder = 1 << std::to_underlying(phrasing::placeholder),
173 unarticulated = 1 << std::to_underlying(phrasing::unarticulated),
174 title = 1 << std::to_underlying(phrasing::title),
175 success = 1 << std::to_underlying(phrasing::success),
176 warning = 1 << std::to_underlying(phrasing::warning),
177 error = 1 << std::to_underlying(phrasing::error),
184 std::bit_width(phrasing_metadata.size() - 1) <=
sizeof(std::underlying_type_t<phrasing_mask>) * CHAR_BIT,
185 "All phrasings must fit the phrasing_mask.");
187[[nodiscard]]
constexpr phrasing_mask operator&(phrasing_mask
const& lhs, phrasing_mask
const& rhs)
noexcept
189 return static_cast<phrasing_mask
>(std::to_underlying(lhs) & std::to_underlying(rhs));
192[[nodiscard]]
constexpr phrasing_mask operator|(phrasing_mask
const& lhs, phrasing_mask
const& rhs)
noexcept
194 return static_cast<phrasing_mask
>(std::to_underlying(lhs) | std::to_underlying(rhs));
197[[nodiscard]]
constexpr phrasing_mask to_phrasing_mask(phrasing
const& rhs)
noexcept
199 hi_axiom(std::to_underlying(rhs) <
sizeof(phrasing_mask) * CHAR_BIT);
200 return static_cast<phrasing_mask
>(1 << std::to_underlying(rhs));
203[[nodiscard]]
constexpr phrasing_mask to_phrasing_mask(std::string
const& str)
205 auto r = phrasing_mask{};
207 for (
auto const c : str) {
209 r = phrasing_mask::all;
210 }
else if (
auto const p = to_phrasing(c)) {
211 r = r | to_phrasing_mask(*p);
213 throw parse_error(std::format(
"Unknown character '{}' in text-phrasing-mask", c));
220[[nodiscard]]
constexpr bool all(phrasing_mask
const& rhs)
noexcept
222 return (rhs & phrasing_mask::all) == phrasing_mask::all;
225[[nodiscard]]
constexpr bool to_bool(phrasing_mask
const& rhs)
noexcept
227 return to_bool(std::to_underlying(rhs));
236[[nodiscard]]
constexpr bool matches(phrasing_mask
const& lhs,
phrasing const& rhs)
noexcept
238 return to_bool(lhs & to_phrasing_mask(rhs));
@ keyboard
The gui_event has keyboard data.
Definition gui_event_variant.hpp:32
phrasing
Phrasing.
Definition phrasing.hpp:31
@ example
Used in help text to show an example.
Definition phrasing.hpp:81
@ highlight
The text is marked or highlighted as if being marked by a highlight pen.
Definition phrasing.hpp:71
@ unarticulated
Unarticulated.
Definition phrasing.hpp:91
@ placeholder
Placeholder for text which will be replaced by the user.
Definition phrasing.hpp:86
@ strong
Strong text; spoken louder, as if the text is not to be missed.
Definition phrasing.hpp:44
@ warning
Format a warning message Often in bright yellow.
Definition phrasing.hpp:106
@ math
Text formatted as math.
Definition phrasing.hpp:76
@ code
Text is a piece of programming-code; a variable name, a function name.
Definition phrasing.hpp:50
@ abbreviation
An abbreviation.
Definition phrasing.hpp:55
@ error
Format a "bad" message Often in bright red.
Definition phrasing.hpp:111
@ title
Format a heading Often in bold, larger font and on a line by itself.
Definition phrasing.hpp:96
@ emphasis
Emphesised text; spoken as if the text is special importance, significant or promonent.
Definition phrasing.hpp:39
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
@ regular
400: Normal / Regular
Definition font_weight.hpp:25
constexpr bool matches(phrasing_mask const &lhs, phrasing const &rhs) noexcept
Check if the text-phrasing is included in the text-phrasing-mask.
Definition phrasing.hpp:236