|
utf-42
|
Compile-time polymorphic string literal selection across character encodings. More...
#include <type_traits>#include <cstddef>#include <string>
Go to the source code of this file.
Classes | |
| struct | utf42::is_character< T > |
| Type trait that checks whether a type is a supported character type. More... | |
| class | utf42::basic_string_view< char_t > |
| A class that provides a lightweight, non-owning view of a string. More... | |
| struct | utf42::poly_enc |
| Container holding all character-encoded views of a string literal. More... | |
Namespaces | |
| namespace | utf42 |
| Main namespace of the library. | |
Macros | |
| #define | make_poly_enc(char_t, lit) |
| Creates a compile-time polymorphic encoded string literal. | |
| #define | cons_poly_enc(lit) |
| Constructs a compile-time polymorphic encoded string literal view. | |
Functions | |
| template<typename char_t > | |
| constexpr basic_string_view< char_t > | utf42::visit_poly_enc (const poly_enc &oPolyEnv) |
| Selects the appropriate encoded string view for a given character type. | |
Compile-time polymorphic string literal selection across character encodings.
This header provides a mechanism to define a single string literal and retrieve it as a std::basic_string_view of a desired character type (char, wchar_t, char8_t, char16_t, or char32_t) at compile time.
The approach relies on the compiler to generate all encoding variants of a string literal (via literal prefixes such as L, u8, u, and U) and selects the appropriate one using consteval dispatch.
This guarantees:
\uXXXX and \UXXXXXXXX escape sequencesmake_poly_enc must be used with a string literal. Passing non-literals results in undefined behavior.This file is part of utf42. Copyright (c) 2025 Dante Doménech MartÃnez
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| #define cons_poly_enc | ( | lit | ) |
Constructs a compile-time polymorphic encoded string literal view.
This macro generates all standard character-encoded versions of the provided string literal.
| lit | A string literal. |
std::basic_string_view<char_t> referring to the selected literal. | #define make_poly_enc | ( | char_t, | |
| lit | |||
| ) |
Creates a compile-time polymorphic encoded string literal.
This macro generates all standard character-encoded versions of the provided string literal and selects the one matching char_t.
| char_t | Desired character type (char, wchar_t, char8_t (if C++20), char16_t, or char32_t). |
| lit | A string literal. |
std::basic_string_view<char_t> referring to the selected literal.