11#include "../utility/utility.hpp"
12#include "../macros.hpp"
19hi_export_module(hikogui.unicode.phrasing);
22hi_export
namespace hi::inline
v1 {
112constexpr auto phrasing_metadata = enum_metadata{
113 phrasing::regular,
"regular",
114 phrasing::emphesis,
"emphesis",
115 phrasing::strong,
"strong",
116 phrasing::code,
"code",
117 phrasing::abbreviation,
"abbreviation",
118 phrasing::quote,
"quote",
119 phrasing::keyboard,
"keyboard",
120 phrasing::highlight,
"highlight",
121 phrasing::math,
"math",
122 phrasing::example,
"example",
123 phrasing::unarticulated,
"unarticulated",
124 phrasing::title,
"title",
125 phrasing::success,
"success",
126 phrasing::warning,
"warning",
127 phrasing::error,
"error",
132[[nodiscard]]
constexpr std::optional<phrasing> to_phrasing(
char c)
135 case 'r':
return phrasing::regular;
136 case 'e':
return phrasing::emphesis;
137 case 's':
return phrasing::strong;
138 case 'c':
return phrasing::code;
139 case 'a':
return phrasing::abbreviation;
140 case 'q':
return phrasing::quote;
141 case 'k':
return phrasing::keyboard;
142 case 'h':
return phrasing::highlight;
143 case 'm':
return phrasing::math;
144 case 'x':
return phrasing::example;
145 case 'u':
return phrasing::unarticulated;
146 case 't':
return phrasing::title;
147 case 'S':
return phrasing::success;
148 case 'W':
return phrasing::warning;
149 case 'E':
return phrasing::error;
156enum class phrasing_mask : uint16_t {
157 regular = 1 << std::to_underlying(phrasing::regular),
158 emphesis = 1 << std::to_underlying(phrasing::emphesis),
159 strong = 1 << std::to_underlying(phrasing::strong),
160 code = 1 << std::to_underlying(phrasing::code),
161 abbreviation = 1 << std::to_underlying(phrasing::abbreviation),
162 quote = 1 << std::to_underlying(phrasing::quote),
163 keyboard = 1 << std::to_underlying(phrasing::keyboard),
164 highlight = 1 << std::to_underlying(phrasing::highlight),
165 math = 1 << std::to_underlying(phrasing::math),
166 example = 1 << std::to_underlying(phrasing::example),
167 unarticulated = 1 << std::to_underlying(phrasing::unarticulated),
168 title = 1 << std::to_underlying(phrasing::title),
169 success = 1 << std::to_underlying(phrasing::success),
170 warning = 1 << std::to_underlying(phrasing::warning),
171 error = 1 << std::to_underlying(phrasing::error),
174 title | success | warning | error
178 std::bit_width(phrasing_metadata.size() - 1) <=
sizeof(std::underlying_type_t<phrasing_mask>) * CHAR_BIT,
179 "All phrasings must fit the phrasing_mask.");
181[[nodiscard]]
constexpr phrasing_mask operator&(phrasing_mask
const& lhs, phrasing_mask
const& rhs)
noexcept
183 return static_cast<phrasing_mask
>(std::to_underlying(lhs) & std::to_underlying(rhs));
186[[nodiscard]]
constexpr phrasing_mask operator|(phrasing_mask
const& lhs, phrasing_mask
const& rhs)
noexcept
188 return static_cast<phrasing_mask
>(std::to_underlying(lhs) | std::to_underlying(rhs));
191[[nodiscard]]
constexpr phrasing_mask to_phrasing_mask(phrasing
const& rhs)
noexcept
193 hi_axiom(std::to_underlying(rhs) <
sizeof(phrasing_mask) * CHAR_BIT);
194 return static_cast<phrasing_mask
>(1 << std::to_underlying(rhs));
197[[nodiscard]]
constexpr phrasing_mask to_phrasing_mask(
std::string const& str)
199 auto r = phrasing_mask{};
201 for (
auto const c : str) {
203 r = phrasing_mask::all;
204 }
else if (
auto const p = to_phrasing(c)) {
205 r = r | to_phrasing_mask(*p);
207 throw parse_error(std::format(
"Unknown character '{}' in text-phrasing-mask", c));
214[[nodiscard]]
constexpr bool all(phrasing_mask
const& rhs)
noexcept
216 return (rhs & phrasing_mask::all) == phrasing_mask::all;
219[[nodiscard]]
constexpr bool to_bool(phrasing_mask
const& rhs)
noexcept
221 return to_bool(std::to_underlying(rhs));
230[[nodiscard]]
constexpr bool matches(phrasing_mask
const& lhs,
phrasing const& rhs)
noexcept
232 return to_bool(lhs & to_phrasing_mask(rhs));
@ keyboard
The gui_event has keyboard data.
phrasing
Phrasing.
Definition phrasing.hpp:33
@ example
Used in help text to show an example.
@ highlight
The text is marked or highlighted as if being marked by a highlight pen.
@ unarticulated
Unarticulated.
@ strong
Strong text; spoken louder, as if the text is not to be missed.
@ emphesis
Emphesised text; spoken as if the text is special importance, significant or promonent.
@ math
Text formatted as math.
@ code
Text is a piece of programming-code; a variable name, a function name.
@ abbreviation
An abbreviation.
@ title
Format a heading Often in bold, larger font and on a line by itself.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
@ regular
400: Normal / Regular
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:230