3#include "terminalpp/ansi/charset.hpp" 
    4#include "terminalpp/core.hpp" 
    6#include <boost/container_hash/hash.hpp> 
   17enum class charset : 
char 
   21    dec_supplementary_graphics,
 
   73        boost::hash_combine(seed, cs.value_);
 
 
   78    terminalpp::charset value_;
 
 
   83using charset_map_small_entry = std::pair<character_set, 
byte const (&)[1]>;
 
   84inline constexpr charset_map_small_entry 
const charset_map[] = {
 
   85    {charset::us_ascii,          ansi::charset_us_ascii           },
 
   86    {charset::sco,               ansi::charset_sco                },
 
   87    {charset::dec,               ansi::charset_dec                },
 
   88    {charset::dec_supplementary, ansi::charset_dec_supplementary  },
 
   89    {charset::dec_technical,     ansi::charset_dec_technical      },
 
   90    {charset::uk,                ansi::charset_uk                 },
 
   91    {charset::dutch,             ansi::charset_dutch              },
 
   92    {charset::finnish,           ansi::charset_finnish            },
 
   93    {charset::finnish,           ansi::charset_finnish_alt        },
 
   94    {charset::french,            ansi::charset_french             },
 
   95    {charset::french,            ansi::charset_french_alt         },
 
   96    {charset::french_canadian,   ansi::charset_french_canadian    },
 
   97    {charset::french_canadian,   ansi::charset_french_canadian_alt},
 
   98    {charset::german,            ansi::charset_german             },
 
   99    {charset::italian,           ansi::charset_italian            },
 
  100    {charset::danish,            ansi::charset_danish             },
 
  101    {charset::danish,            ansi::charset_danish_alt_1       },
 
  102    {charset::danish,            ansi::charset_danish_alt_2       },
 
  103    {charset::spanish,           ansi::charset_spanish            },
 
  104    {charset::swedish,           ansi::charset_swedish            },
 
  105    {charset::swedish,           ansi::charset_swedish_alt        },
 
  106    {charset::swiss,             ansi::charset_swiss              },
 
  109using charset_map_extended_entry = std::pair<character_set, 
byte const (&)[2]>;
 
  110inline constexpr charset_map_extended_entry 
const extended_charset_map[] = {
 
  111    {charset::dec_supplementary_graphics, ansi::charset_dec_supplementary_gr},
 
  112    {charset::portuguese,                 ansi::charset_portuguese          },
 
  122[[nodiscard]] 
constexpr std::optional<character_set> lookup_character_set(
 
  125    auto const len = code.size();
 
  132    if (code[0] == ansi::charset_extender)
 
  136            for (
auto &&mapping : detail::extended_charset_map)
 
  138                if (code[1] == mapping.second[1])
 
  140                    return mapping.first;
 
  147        for (
auto &&mapping : detail::charset_map)
 
  149            if (code[0] == mapping.second[0])
 
  151                return mapping.first;
 
  163[[nodiscard]] 
constexpr std::basic_string_view<byte> encode_character_set(
 
  164    character_set 
const &set) 
noexcept 
  166    constexpr auto project_first = [](
auto const &entry) {
 
  170    if (
auto const *entry =
 
  171            std::ranges::find(detail::charset_map, set, project_first);
 
  172        entry != std::cend(detail::charset_map))
 
  174        return {entry->second, 1};
 
  177    if (
auto const *entry =
 
  178            std::ranges::find(detail::extended_charset_map, set, project_first);
 
  179        entry != std::cend(detail::extended_charset_map))
 
  181        return {entry->second, 2};
 
  184    return encode_character_set(character_set(charset::us_ascii));
 
  192std::ostream &operator<<(std::ostream &out, character_set 
const &set);
 
  199struct hash<terminalpp::character_set>
 
  202    using result_type = std::size_t;
 
  204    [[nodiscard]] result_type operator()(
argument_type const &cs) 
const noexcept 
  206        return hash_value(cs);
 
 
A structure that represents a character set.
Definition character_set.hpp:44
 
constexpr character_set(charset const &set) noexcept
Initialises the character set the given value.
Definition character_set.hpp:55
 
constexpr friend auto operator<=>(character_set const &lhs, character_set const &rhs) noexcept=default
Relational operators for character sets.
 
constexpr character_set() noexcept
Initialises the character set to its default value.
Definition character_set.hpp:48
 
friend std::size_t hash_value(character_set const &cs) noexcept
Hash function.
Definition character_set.hpp:69