jaulib v1.3.6
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
jau::cfmt2 Namespace Reference

Author: Sven Gothel sgoth.nosp@m.el@j.nosp@m.ausof.nosp@m.t.co.nosp@m.m Copyright (c) 2024 Gothel Software e.K. More...

Namespaces

namespace  impl
 

Classes

struct  PResult
 

Enumerations

enum class  plength_t {
  plength_t::hh , plength_t::h , plength_t::none , plength_t::l ,
  plength_t::ll , plength_t::j , plength_t::z , plength_t::t ,
  plength_t::L
}
 
enum class  pstate_t {
  pstate_t::error , pstate_t::outside , pstate_t::start , pstate_t::field_width ,
  pstate_t::precision
}
 

Functions

template<typename... Targs>
constexpr bool check (const std::string_view fmt, const Targs &...) noexcept
 Strict type validation of arguments against the format string.
 
template<typename... Targs>
constexpr bool check2 (const std::string_view fmt) noexcept
 Strict type validation of arguments against the format string.
 
template<typename... Targs>
constexpr const PResult checkR (const std::string_view fmt, const Targs &...) noexcept
 Strict type validation of arguments against the format string.
 
template<typename... Targs>
constexpr const PResult checkR2 (const std::string_view fmt) noexcept
 Strict type validation of arguments against the format string.
 
static constexpr bool isDigit (const char c) noexcept
 
std::ostream & operator<< (std::ostream &out, const PResult &pc)
 
static constexpr const char * to_string (plength_t s) noexcept
 
static constexpr const char * to_string (pstate_t s) noexcept
 

Detailed Description

Author: Sven Gothel sgoth.nosp@m.el@j.nosp@m.ausof.nosp@m.t.co.nosp@m.m Copyright (c) 2024 Gothel Software e.K.


SPDX-License-Identifier: MIT

This Source Code Form is subject to the terms of the MIT License If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/license/mit/.

snprintf argument type checker jau::cfmt

Features

  • jau::cfmt::check() provides strict type matching of arguments against the format string.
  • Have jau::cfmt::check() to be passed before using std::snprintf(), removing safety concerns of the latter and benefit from its formatting and performance.
  • Follows C++ Reference

Type Conversion

Implementation follows type conversion rules as described in Variadic Default Conversion

  • float to double promotion
  • bool, char, short, and unscoped enumerations are converted to int or wider integer types as well as in va_arg
  • ignore signed/unsigned type differences for integral types
  • void pointer tolerance

Implementation Details

  • Validates arguments against format string at compile time or runtime, depending whether passed arguments are of constexpr nature (compile time).
  • Written in C++20 using template argument pack w/ save argument type checks
  • Written as constexpr, capable to be utilized at compile-time.

Supported Conversion Specifiers and Data Types

The following conversion specifiers are supported:

  • c, s, d, o, x, X, u, f, e, E, a, A, g, G, p
  • Their synonyms
    • i -> d
    • F -> f
  • Flags -, +, , 0 and #
  • Asterisk * for field width and precision

The following length modifiers are supported where allowed

  • hh [unsigned] char
  • h [unsigned] short
  • l [unsigned] long
  • ll [unsigned] long long
  • 'j' uintmax_t or intmax_t
  • 'z' size_t or ssize_t
  • 't' ptrdiff_t
  • 'L' long double

See C++ Reference for details.

Further Documentation