3#include "terminalpp/character_set.hpp"
4#include "terminalpp/core.hpp"
5#include "terminalpp/detail/ascii.hpp"
7#include <boost/container_hash/hash.hpp>
29 byte const character = detail::ascii::space,
31 : character_(
character), charset_(charset)
39 : ucharacter_{
text[0]}, charset_(terminalpp::charset::utf8)
47 : ucharacter_{
text[0],
text[1]}, charset_(terminalpp::charset::utf8)
56 charset_(terminalpp::charset::utf8)
64 : ucharacter_{
text[0]}, charset_(terminalpp::charset::utf8)
72 : ucharacter_{
text[0],
text[1]}, charset_(terminalpp::charset::utf8)
81 charset_(terminalpp::charset::utf8)
85 template <std::
size_t N>
86 explicit glyph(
byte const (&
text)[
N])
noexcept
88 : ucharacter_{0}, charset_(terminalpp::charset::utf8)
90 assign_utf8_bytes(
text,
N - 1);
93 template <std::
size_t N>
94 explicit glyph(
char8_t const (&
text)[
N])
noexcept
96 : ucharacter_{0}, charset_(terminalpp::charset::utf8)
98 assign_utf8_bytes(
reinterpret_cast<byte const *
>(
text),
N - 1);
112 template <
class T =
void>
116 : ucharacter_{0}, charset_(terminalpp::charset::utf8)
118 for (
size_t index = 0; index <
sizeof(ucharacter_); ++index)
120 ucharacter_[index] =
static_cast<byte>(
ustr[index]);
122 if (!(ucharacter_[index] & 0x80))
136 if (
lhs <
rhs)
return std::strong_ordering::less;
137 if (
rhs <
lhs)
return std::strong_ordering::greater;
138 return std::strong_ordering::equal;
148 if (
lhs.charset_ ==
rhs.charset_)
150 if (
lhs.charset_ == terminalpp::charset::utf8)
156 for (
auto lch = begin(
lhs.ucharacter_),
157 rch = begin(
rhs.ucharacter_);
158 lch != end(
lhs.ucharacter_);
171 return lhs.character_ ==
rhs.character_;
184 if (
lhs.charset_ <
rhs.charset_)
189 if (
lhs.charset_ ==
rhs.charset_)
191 if (
lhs.charset_ == terminalpp::charset::utf8)
198 for (
auto begin1 = begin(
lhs.ucharacter_),
214 return lhs.character_ <
rhs.character_;
225 std::size_t
seed = 0;
226 boost::hash_combine(
seed,
gly.charset_);
228 if (
gly.charset_ == terminalpp::charset::utf8)
230 for (
auto ch :
gly.ucharacter_)
232 boost::hash_combine(
seed,
ch);
237 boost::hash_combine(
seed,
gly.character_);
249 character_set charset_;
252 void assign_utf8_bytes(
byte const *
text, std::size_t
length)
noexcept;
256 return charset_ == terminalpp::charset::utf8 && ucharacter_[0] == 0xFF;
266bool is_printable(glyph
const &gly)
noexcept;
273std::ostream &operator<<(std::ostream &out, glyph
const &gly);
280struct hash<terminalpp::glyph>
283 using result_type = std::size_t;
285 [[nodiscard]] result_type operator()(
288 return hash_value(elem);
A structure that represents a character set.
Definition character_set.hpp:44
A structure representing an ANSI graphics effect (e.g. intensity, underlining)
Definition effect.hpp:27
constexpr effect() noexcept
Initialises the intensity to the default (normal) value.
Definition effect.hpp:31
A structure that carries around the character attributes of an ANSI element.
Definition glyph.hpp:20
friend std::size_t hash_value(glyph const &gly) noexcept
Hash function.
Definition glyph.hpp:223
constexpr glyph(byte const (&text)[4]) noexcept
Constructs a UTF-8 glyph from a char sequence.
Definition glyph.hpp:54
constexpr glyph(char8_t const (&text)[4]) noexcept
Constructs a UTF-8 glyph from a char sequence.
Definition glyph.hpp:79
constexpr glyph(char8_t const (&text)[2]) noexcept
Constructs a UTF-8 glyph from a char sequence.
Definition glyph.hpp:63
constexpr friend bool operator<(glyph const &lhs, glyph const &rhs) noexcept
Less-than operator.
Definition glyph.hpp:181
constexpr glyph(byte const (&text)[2]) noexcept
Constructs a UTF-8 glyph from a char sequence.
Definition glyph.hpp:38
constexpr glyph(char8_t const (&text)[3]) noexcept
Constructs a UTF-8 glyph from a char sequence.
Definition glyph.hpp:71
constexpr glyph(char const *ustr) noexcept
Constructs a UTF-8 glyph from a char sequence.
Definition glyph.hpp:115
constexpr glyph(byte const character=detail::ascii::space, character_set const charset=character_set()) noexcept
Default Constructor.
Definition glyph.hpp:28
constexpr glyph(byte const (&text)[3]) noexcept
Constructs a UTF-8 glyph from a char sequence.
Definition glyph.hpp:46
TERMINALPP_EXPORT constexpr friend bool operator==(glyph const &lhs, glyph const &rhs) noexcept
Equality operator.
Definition glyph.hpp:145
TERMINALPP_EXPORT constexpr friend auto operator<=>(glyph const &lhs, glyph const &rhs) noexcept
Relational operators for glyphs.
Definition glyph.hpp:133