JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
char.h File Reference

Character-semantics concept and utilities — constexpr-safe character classification and transformation for 1-byte fundamental types. More...

#include <concepts>
#include <type_traits>

Go to the source code of this file.

Namespaces

namespace  jh::meta
 Aggregated entry point for compile-time metaprogramming utilities.

Concepts

concept  jh::meta::any_char
 Concept representing character-semantic 1-byte integral types.

Functions

template<any_char Char>
constexpr bool jh::meta::is_alpha (Char c) noexcept
 Check if character is an alphabetic letter (A-Z, a-z).
template<any_char Char>
constexpr bool jh::meta::is_digit (Char c) noexcept
 Check if character is a decimal digit (0-9).
template<any_char Char>
constexpr bool jh::meta::is_alnum (Char c) noexcept
 Check if character is alphanumeric (letter or digit).
template<any_char Char>
constexpr bool jh::meta::is_hex_char (Char c) noexcept
 Check if character is a valid hexadecimal digit.
template<any_char Char>
constexpr bool jh::meta::is_base64_core (Char c) noexcept
 Check if character belongs to standard Base64 alphabet.
template<any_char Char>
constexpr bool jh::meta::is_base64url_core (Char c) noexcept
 Check if character belongs to Base64URL alphabet.
template<any_char Char>
constexpr bool jh::meta::is_ascii (Char c) noexcept
 Check if character is ASCII.
template<any_char Char>
constexpr bool jh::meta::is_printable_ascii (Char c) noexcept
 Check if character is printable 7-bit ASCII (range 32-126).
template<any_char Char>
constexpr bool jh::meta::is_uri_char (Char c) noexcept
 Check if character is a valid URI character (unencoded).
template<any_char Char>
constexpr bool jh::meta::is_valid_char (Char c) noexcept
 Validate ASCII: reject control chars and DEL, leave non-ASCII untouched.
template<any_char Char>
constexpr char jh::meta::to_upper (Char c) noexcept
 Convert letter to uppercase; leave others unchanged.
template<any_char Char>
constexpr char jh::meta::to_lower (Char c) noexcept
 Convert letter to lowercase; leave others unchanged.
template<any_char Char>
constexpr char jh::meta::flip_case (Char c) noexcept
 Flip case of alphabetic character.

Detailed Description

Character-semantics concept and utilities — constexpr-safe character classification and transformation for 1-byte fundamental types.

Author
JeongHan-Bae <mastropseudo@gmail.com>

This header defines jh::meta::any_char, a C++20 concept identifying the core 1-byte character types (char, signed char, unsigned char), together with a small constexpr-safe classification and transformation toolkit for character operations.

Overview

The any_char concept constrains type parameters to only those built-in 1-byte integral character types directly usable for raw text or binary data. This design ensures type purity, constexpr safety, and clear separation from UTF-8 and byte-level abstractions.

Included utilities

  • is_alpha() — check for alphabetic characters (A-Z, a-z).
  • is_digit() — check for decimal digits (0-9).
  • is_alnum() — check for alphanumeric (letter or digit).
  • is_hex_char() — check for valid hexadecimal characters (0-9, A-F, a-f).
  • is_base64_core() — check if part of the standard Base64 alphabet (A-Z, a-z, 0-9, '+', '/').
  • is_base64url_core() — check if part of the Base64URL alphabet (A-Z, a-z, 0-9, '-', '_').
  • is_ascii() — verify whether a character is within the 7-bit ASCII range (0-127).
  • is_printable_ascii() — check if character is a printable 7-bit ASCII symbol (32-126 inclusive).
  • is_valid_char() — check that character is not a control or DEL (returns true for all non-control bytes).
  • to_upper() — convert a letter to uppercase; leave others unchanged.
  • to_lower() — convert a letter to lowercase; leave others unchanged.
  • flip_case() — invert alphabetic case.

Design rationale

  • Concept-level filtering: The any_char constraint rejects higher-level or incompatible types such as char8_t, std::byte, and bool.
  • No remove_cvref usage: The concept explicitly expects the raw type form — it models the prototype of character semantics. cv-qualifiers (e.g. const Char) can be manually specified if needed. References are intentionally excluded because Char is a metaprogramming token rather than a forwarding type; templates like template<any_char Char> instantiate with copies, not references, preserving constexpr safety.
  • Strict 1-byte validation: Guarantees sizeof(T) == 1 and avoids UB across translation units when hashing or reinterpreting raw data.
Version
1.3.x
Date
2025