dasmig-core 1.2.0
Shared random engine, distributions and data tiers for the dasmig generator libraries
Loading...
Searching...
No Matches
country.hpp File Reference

Helpers for ISO 3166-1 alpha-2 country codes. More...

#include <stdexcept>
#include <string>
#include <string_view>

Go to the source code of this file.

Functions

constexpr bool dasmig::core::is_alpha2 (std::string_view code) noexcept
 Whether text has the shape of an ISO 3166-1 alpha-2 code: exactly two capital ASCII letters.
 
std::invalid_argument dasmig::core::unknown_country_error (std::string_view code)
 The exception libraries throw for a country code they have no data for. Its message is Unknown country code: <code>.
 

Detailed Description

Helpers for ISO 3166-1 alpha-2 country codes.

Author
Diego Dasso Migotto (diegomigotto at hotmail dot com)

Definition in file country.hpp.

Function Documentation

◆ is_alpha2()

constexpr bool dasmig::core::is_alpha2 ( std::string_view  code)
constexprnoexcept

Whether text has the shape of an ISO 3166-1 alpha-2 code: exactly two capital ASCII letters.

This checks the shape only. It does not know which codes are assigned or which a library has data for.

Parameters
codeText to check.
Returns
true for "BR", false for "br", "BRA", "" or "B1".

Definition at line 26 of file country.hpp.

◆ unknown_country_error()

std::invalid_argument dasmig::core::unknown_country_error ( std::string_view  code)
inline

The exception libraries throw for a country code they have no data for. Its message is Unknown country code: <code>.

throw core::unknown_country_error(cca2);
Parameters
codeThe code that was not found.
Returns
A std::invalid_argument to throw.

Definition at line 40 of file country.hpp.