7#include "iso_3166_intf.hpp"
8#include "../utility/utility.hpp"
9#include "../algorithm/algorithm.hpp"
10#include "../macros.hpp"
15hi_export_module(hikogui.i18n.iso_3166 : impl);
17hi_export
namespace hi::inline
v1 {
21 fixed_string<2> code2;
22 fixed_string<3> code3;
30[[nodiscard]]
consteval auto iso_3166_infos_init() noexcept
287 constexpr auto data_size =
sizeof(data) /
sizeof(data[0]);
291 for (
auto i = 0_uz; i != data_size; ++i) {
298constexpr auto iso_3166_infos = iso_3166_infos_init();
300[[nodiscard]]
consteval auto iso_3166_code2_by_number_init() noexcept
303 for (
auto i = 0_uz; i != r.size(); ++i) {
307 for (
auto const& info : iso_3166_infos) {
308 r[info.number] = info.code2;
313[[nodiscard]]
consteval auto iso_3166_code3_by_number_init() noexcept
316 for (
auto i = 0_uz; i != r.size(); ++i) {
320 for (
auto const& info : iso_3166_infos) {
321 r[info.number] = info.code3;
326[[nodiscard]]
consteval auto iso_3166_number_by_code2_init() noexcept
328 constexpr auto size = std::tuple_size_v<
decltype(iso_3166_infos)>;
332 for (
auto i = 0_uz; i != iso_3166_infos.size(); ++i) {
333 auto const& info = iso_3166_infos[i];
334 r[i] = {info.code2, info.number};
337 std::sort(r.begin(), r.end(), [](
auto const& a,
auto const& b) {
338 return a.first < b.first;
343[[nodiscard]]
consteval auto iso_3166_number_by_code3_init() noexcept
345 constexpr auto size = std::tuple_size_v<
decltype(iso_3166_infos)>;
349 for (
auto i = 0_uz; i != iso_3166_infos.size(); ++i) {
350 auto const& info = iso_3166_infos[i];
351 r[i] = {info.code3, info.number};
354 std::sort(r.begin(), r.end(), [](
auto const& a,
auto const& b) {
355 return a.first < b.first;
360constexpr auto iso_3166_code2_by_number = iso_3166_code2_by_number_init();
361constexpr auto iso_3166_code3_by_number = iso_3166_code3_by_number_init();
362constexpr auto iso_3166_number_by_code2 = iso_3166_number_by_code2_init();
363constexpr auto iso_3166_number_by_code3 = iso_3166_number_by_code3_init();
367constexpr iso_3166::iso_3166(std::string_view str)
370 _v = from_string<uint16_t>(str);
371 hi_check(_v < 1000,
"ISO-3166 number must be between 000 and 999, got '{}'", _v);
373 }
else if (str.size() == 2) {
374 auto str_up = to_upper(str);
377 detail::iso_3166_number_by_code2.
begin(),
378 detail::iso_3166_number_by_code2.
end(),
380 [](
auto const& item,
auto const& value) {
381 return item.first < value;
385 it != detail::iso_3166_number_by_code2.
end() and it->first == str_up,
386 "Could not find ISO-3166 2 letter language code '{}'",
391 }
else if (str.size() == 3) {
392 auto str_up = to_upper(str);
395 detail::iso_3166_number_by_code3.
begin(),
396 detail::iso_3166_number_by_code3.
end(),
398 [](
auto const& item,
auto const& value) {
399 return item.first < value;
403 it != detail::iso_3166_number_by_code3.
end() and it->first == str_up,
404 "Could not find ISO-3166 3 letter language code '{}'",
410 throw parse_error(std::format(
"Could not parse ISO-3166 code '{}'", str));
414[[nodiscard]]
constexpr std::string iso_3166::code2() const noexcept
416 hi_assert(_v < 1000);
417 return detail::iso_3166_code2_by_number[_v];
420[[nodiscard]]
constexpr std::string iso_3166::code3() const noexcept
422 hi_assert(_v < 1000);
423 return detail::iso_3166_code3_by_number[_v];
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition iso_3166_impl.hpp:20