Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
Punycode

An implementation of RFC 3492 Punycode. More...

Classes

class  sourcemeta::core::PunycodeError

Functions

SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::utf32_to_punycode (std::u32string_view input) -> std::string
SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::utf8_to_punycode (std::istream &input, std::ostream &output) -> void
SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::utf8_to_punycode (const std::string_view input) -> std::string
SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::punycode_to_utf32 (const std::string_view input) -> std::u32string
SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::punycode_to_utf8 (std::istream &input, std::ostream &output) -> void
SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::punycode_to_utf8 (const std::string_view input) -> std::string

Detailed Description

An implementation of RFC 3492 Punycode.

This functionality is included as follows:

#include <sourcemeta/core/punycode.h>

Class Documentation

◆ sourcemeta::core::PunycodeError

class sourcemeta::core::PunycodeError

An error that represents a Punycode encoding or decoding failure

Inheritance diagram for sourcemeta::core::PunycodeError:

Public Member Functions

 PunycodeError (const char *message)
 Construct an error with the given message.
 PunycodeError (std::string message)=delete
 PunycodeError (std::string &&message)=delete
 PunycodeError (std::string_view message)=delete

Function Documentation

◆ punycode_to_utf32()

SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::punycode_to_utf32 ( const std::string_view input) -> std::u32string

Decode Punycode to Unicode code points (UTF-32). For example:

#include <sourcemeta/core/punycode.h>
#include <cassert>
const std::u32string expected{0x0048, 0x0065, 0x006C, 0x006C, 0x006F,
0x002D, 0x305D, 0x308C, 0x305E, 0x308C,
0x306E, 0x5834, 0x6240};
assert(sourcemeta::core::punycode_to_utf32("Hello--fc4qua05auwb3674vfr0b")
==
expected);
SOURCEMETA_CORE_PUNYCODE_EXPORT auto punycode_to_utf32(const std::string_view input) -> std::u32string

Note that stream-based overloads for UTF-32 are not provided because the C++ standard library does not define the required locale facets (std::ctype<char32_t>) for std::basic_istream<char32_t> and std::basic_ostream<char32_t> to function properly.

◆ punycode_to_utf8() [1/2]

SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::punycode_to_utf8 ( const std::string_view input) -> std::string

Decode Punycode to UTF-8. For example:

#include <sourcemeta/core/punycode.h>
#include <cassert>
assert(sourcemeta::core::punycode_to_utf8("Mnchen-3ya") ==
"M\xC3\xBCnchen");
SOURCEMETA_CORE_PUNYCODE_EXPORT auto punycode_to_utf8(std::istream &input, std::ostream &output) -> void

◆ punycode_to_utf8() [2/2]

SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::punycode_to_utf8 ( std::istream & input,
std::ostream & output ) -> void

Decode Punycode to UTF-8 using streams. For example:

#include <sourcemeta/core/punycode.h>
#include <sstream>
#include <cassert>
std::istringstream input{"Mnchen-3ya"};
std::ostringstream output;
assert(output.str() == "M\xC3\xBCnchen");

◆ utf32_to_punycode()

SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::utf32_to_punycode ( std::u32string_view input) -> std::string

Encode Unicode code points (UTF-32) to Punycode. For example:

#include <sourcemeta/core/punycode.h>
#include <cassert>
const std::u32string input{0x0048, 0x0065, 0x006C, 0x006C, 0x006F,
0x002D, 0x305D, 0x308C, 0x305E, 0x308C,
0x306E, 0x5834, 0x6240};
"Hello--fc4qua05auwb3674vfr0b");
SOURCEMETA_CORE_PUNYCODE_EXPORT auto utf32_to_punycode(std::u32string_view input) -> std::string

Note that stream-based overloads for UTF-32 are not provided because the C++ standard library does not define the required locale facets (std::ctype<char32_t>) for std::basic_istream<char32_t> and std::basic_ostream<char32_t> to function properly.

◆ utf8_to_punycode() [1/2]

SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::utf8_to_punycode ( const std::string_view input) -> std::string

Encode UTF-8 to Punycode. For example:

#include <sourcemeta/core/punycode.h>
#include <cassert>
assert(sourcemeta::core::utf8_to_punycode("M\xC3\xBCnchen") ==
"Mnchen-3ya");
SOURCEMETA_CORE_PUNYCODE_EXPORT auto utf8_to_punycode(std::istream &input, std::ostream &output) -> void

◆ utf8_to_punycode() [2/2]

SOURCEMETA_CORE_PUNYCODE_EXPORT auto sourcemeta::core::utf8_to_punycode ( std::istream & input,
std::ostream & output ) -> void

Encode UTF-8 to Punycode using streams. For example:

#include <sourcemeta/core/punycode.h>
#include <sstream>
#include <cassert>
std::istringstream input{"M\xC3\xBCnchen"};
std::ostringstream output;
assert(output.str() == "Mnchen-3ya");