11#include "../utility/module.hpp"
16namespace hi::inline
v1 {
106constexpr auto phrasing_metadata = enum_metadata{
107 phrasing::regular,
"regular",
108 phrasing::emphesis,
"emphesis",
109 phrasing::strong,
"strong",
110 phrasing::code,
"code",
111 phrasing::abbreviation,
"abbreviation",
112 phrasing::quote,
"quote",
113 phrasing::keyboard,
"keyboard",
114 phrasing::highlight,
"highlight",
115 phrasing::math,
"math",
116 phrasing::example,
"example",
117 phrasing::unarticulated,
"unarticulated",
118 phrasing::title,
"title",
119 phrasing::success,
"success",
120 phrasing::warning,
"warning",
121 phrasing::error,
"error",
126[[nodiscard]]
constexpr std::optional<phrasing> to_phrasing(
char c)
129 case 'r':
return phrasing::regular;
130 case 'e':
return phrasing::emphesis;
131 case 's':
return phrasing::strong;
132 case 'c':
return phrasing::code;
133 case 'a':
return phrasing::abbreviation;
134 case 'q':
return phrasing::quote;
135 case 'k':
return phrasing::keyboard;
136 case 'h':
return phrasing::highlight;
137 case 'm':
return phrasing::math;
138 case 'x':
return phrasing::example;
139 case 'u':
return phrasing::unarticulated;
140 case 't':
return phrasing::title;
141 case 'S':
return phrasing::success;
142 case 'W':
return phrasing::warning;
143 case 'E':
return phrasing::error;
150enum class phrasing_mask : uint16_t {
151 regular = 1 << std::to_underlying(phrasing::regular),
152 emphesis = 1 << std::to_underlying(phrasing::emphesis),
153 strong = 1 << std::to_underlying(phrasing::strong),
154 code = 1 << std::to_underlying(phrasing::code),
155 abbreviation = 1 << std::to_underlying(phrasing::abbreviation),
156 quote = 1 << std::to_underlying(phrasing::quote),
157 keyboard = 1 << std::to_underlying(phrasing::keyboard),
158 highlight = 1 << std::to_underlying(phrasing::highlight),
159 math = 1 << std::to_underlying(phrasing::math),
160 example = 1 << std::to_underlying(phrasing::example),
161 unarticulated = 1 << std::to_underlying(phrasing::unarticulated),
162 title = 1 << std::to_underlying(phrasing::title),
163 success = 1 << std::to_underlying(phrasing::success),
164 warning = 1 << std::to_underlying(phrasing::warning),
165 error = 1 << std::to_underlying(phrasing::error),
168 title | success | warning | error
172 std::bit_width(phrasing_metadata.size() - 1) <=
sizeof(std::underlying_type_t<phrasing_mask>) * CHAR_BIT,
173 "All phrasings must fit the phrasing_mask.");
175[[nodiscard]]
constexpr phrasing_mask operator&(phrasing_mask
const& lhs, phrasing_mask
const& rhs)
noexcept
177 return static_cast<phrasing_mask
>(std::to_underlying(lhs) & std::to_underlying(rhs));
180[[nodiscard]]
constexpr phrasing_mask operator|(phrasing_mask
const& lhs, phrasing_mask
const& rhs)
noexcept
182 return static_cast<phrasing_mask
>(std::to_underlying(lhs) | std::to_underlying(rhs));
185[[nodiscard]]
constexpr phrasing_mask to_phrasing_mask(phrasing
const& rhs)
noexcept
187 hi_axiom(std::to_underlying(rhs) <
sizeof(phrasing_mask) * CHAR_BIT);
188 return static_cast<phrasing_mask
>(1 << std::to_underlying(rhs));
191[[nodiscard]]
constexpr phrasing_mask to_phrasing_mask(
std::string const& str)
193 auto r = phrasing_mask{};
195 for (
hilet c : str) {
197 r = phrasing_mask::all;
198 }
else if (
hilet p = to_phrasing(c)) {
199 r = r | to_phrasing_mask(*p);
201 throw parse_error(std::format(
"Unknown character '{}' in text-phrasing-mask", c));
208[[nodiscard]]
constexpr bool all(phrasing_mask
const& rhs)
noexcept
210 return (rhs & phrasing_mask::all) == phrasing_mask::all;
213[[nodiscard]]
constexpr bool to_bool(phrasing_mask
const& rhs)
noexcept
215 return to_bool(std::to_underlying(rhs));
224[[nodiscard]]
constexpr bool matches(phrasing_mask
const& lhs,
phrasing const& rhs)
noexcept
226 return to_bool(lhs & to_phrasing_mask(rhs));
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ keyboard
The gui_event has keyboard data.
phrasing
Phrasing.
Definition phrasing.hpp:27
@ 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.
@ regular
Regular, normal text.
@ 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.hpp:13
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:224