jaulib v1.5.1
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
String Utilities

String utilities for type conversion and manipulation. More...

Classes

class  jau::BasicStringLiteral< CharT, N >
 Static compile-time string literal storage. More...
 
struct  jau::cfmt::Config
 Global jau::cfmt configuration. More...
 
struct  jau::cfmt::FormatOpts
 
class  jau::cfmt::Result
 

Macros

#define jau_format_check(fmt, ...)
 Macro produces compile time validation using a static_assert against jau::cfmt::check2.
 
#define jau_format_checkLine(fmt, ...)
 Macro produces compile time validation using a static_assert against jau::cfmt::check2Line.
 
#define jau_format_string(fmt, ...)
 Macro, safely returns a (non-truncated) string according to snprintf() formatting rules using a reserved string length of jau::cfmt::default_string_capacity and variable number of arguments following the fmt argument.
 
#define jau_format_string2(fmt, ...)
 Macro, safely returns a (non-truncated) string according to snprintf() formatting rules using a reserved string length of jau::cfmt::default_string_capacity and variable number of arguments following the fmt argument.
 
#define jau_format_string_h(strLenHint, fmt, ...)
 Macro, safely returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the fmt argument.
 

Typedefs

template<size_t N>
using jau::StringLiteral = BasicStringLiteral<char, N>
 
template<size_t N>
using jau::WStringLiteral = BasicStringLiteral<wchar_t, N>
 

Enumerations

enum class  jau::cfmt::cspec_t : uint16_t {
  jau::cfmt::cspec_t::none , jau::cfmt::cspec_t::character , jau::cfmt::cspec_t::string , jau::cfmt::cspec_t::pointer ,
  jau::cfmt::cspec_t::signed_int , jau::cfmt::cspec_t::unsigned_int , jau::cfmt::cspec_t::floating_point , jau::cfmt::cspec_t::exp_float ,
  jau::cfmt::cspec_t::alt_float , jau::cfmt::cspec_t::hex_float
}
 Format conversion specifier (fully defined w/ radix) More...
 
enum class  jau::cfmt::flags_t : uint16_t {
  jau::cfmt::flags_t::none = 0 , jau::cfmt::flags_t::hash = (uint16_t)1 << 1 , jau::cfmt::flags_t::zeropad = (uint16_t)1 << 2 , jau::cfmt::flags_t::left = (uint16_t)1 << 3 ,
  jau::cfmt::flags_t::space = (uint16_t)1 << 4 , jau::cfmt::flags_t::plus = (uint16_t)1 << 5 , jau::cfmt::flags_t::thousands = (uint16_t)1 << 6 , jau::cfmt::flags_t::uppercase = (uint16_t)1 << 8
}
 Format flags. More...
 
enum class  jau::LoUpCase : bool { jau::LoUpCase::lower = false , jau::LoUpCase::upper = true }
 
enum class  jau::cfmt::plength_t : uint16_t {
  jau::cfmt::plength_t::none , jau::cfmt::plength_t::hh , jau::cfmt::plength_t::h , jau::cfmt::plength_t::l ,
  jau::cfmt::plength_t::ll , jau::cfmt::plength_t::L , jau::cfmt::plength_t::j , jau::cfmt::plength_t::z ,
  jau::cfmt::plength_t::t
}
 Format length modifiers. More...
 
enum class  jau::PrefixOpt : bool { jau::PrefixOpt::none = false , jau::PrefixOpt::prefix = true }
 
enum class  jau::cfmt::pstate_t : uint16_t {
  jau::cfmt::pstate_t::error , jau::cfmt::pstate_t::outside , jau::cfmt::pstate_t::start , jau::cfmt::pstate_t::field_width ,
  jau::cfmt::pstate_t::precision
}
 

Functions

std::string & jau::appendBitString (std::string &dest, const void *data, const nsize_t length, const bit_order_t bitOrder=bit_order_t::msb, const PrefixOpt prefix=PrefixOpt::prefix, size_t bit_len=0) noexcept
 Appends a binary string representation of the given lsb-first byte values.
 
template<class value_type, std::enable_if_t< std::is_integral_v< value_type >, bool > = true>
std::string & jau::appendDecString (std::string &dest, const value_type &val, const char separator='\'', const uint32_t min_width=0) noexcept
 Appends a decimal integer string representation of an integral integer value with given radix.
 
std::string & jau::appendHexString (std::string &dest, const uint8_t value, const LoUpCase capitalization=LoUpCase::lower) noexcept
 Produce a hexadecimal string representation of the given byte value and appends it to the given string.
 
std::string & jau::appendHexString (std::string &dest, const void *data, const nsize_t length, const lb_endian_t byteOrder=lb_endian_t::big, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix) noexcept
 Appends a hexadecimal string representation of the given lsb-first byte values.
 
template<std::integral value_type>
std::string & jau::appendIntString (std::string &dest, value_type val, const uint32_t radix, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix, const uint32_t min_width=0, const char separator=0, const char padding='0') noexcept
 Appends an integer string representation of an integral integer value with given radix.
 
template<typename CharT, std::convertible_to< CharT >... Rest>
 jau::BasicStringLiteral (CharT, Rest...) -> BasicStringLiteral< CharT, 1+sizeof...(Rest)>
 
template<typename CharT, size_t O>
 jau::BasicStringLiteral (const CharT(&str)[O]) -> BasicStringLiteral< CharT, O - 1 >
 
template<typename... Targs>
consteval_cxx20 ssize_t jau::cfmt::check (std::string_view fmt, const Targs &...) noexcept
 Strict compile-time type validation of deduced argument-types against the format string.
 
template<typename... Targs>
consteval_cxx20 ssize_t jau::cfmt::check2 (std::string_view fmt) noexcept
 Strict compile-time type validation of explicit argument-types against the format string.
 
template<typename... Targs>
consteval_cxx20 int jau::cfmt::check2Line (std::string_view fmt) noexcept
 Strict compile-time type validation of explicit argument-types against the format string.
 
template<typename... Targs>
consteval_cxx20 int jau::cfmt::checkLine (std::string_view fmt, const Targs &...) noexcept
 Strict compile-time type validation of deduced argument-types against the format string.
 
template<typename... Targs>
consteval_cxx20 Result jau::cfmt::checkR (std::string_view fmt, const Targs &...) noexcept
 Strict compile-time type validation of deduced argument-types against the format string.
 
template<typename... Targs>
consteval_cxx20 Result jau::cfmt::checkR2 (std::string_view format) noexcept
 Strict compile-time type validation of explicit argument-types against the format string.
 
constexpr int32_t jau::digit (const uint8_t c, const uint32_t radix=10) noexcept
 Returns digit value of given char c matching the radix 16, 10, 8 or 2, -1 on no match.
 
void jau::unsafe::errPrint (FILE *out, const char *msg, bool addErrno, bool addBacktrace, const char *func, const char *file, const int line, const char *format,...) noexcept
 
template<typename... Targs>
std::string jau::cfmt::format (size_t maxLen, std::string_view fmt, const Targs &...args) noexcept
 Strict format with type validation of arguments against the format string.
 
template<typename... Targs>
std::string jau::cfmt::format (std::string_view fmt, const Targs &...args) noexcept
 Strict format with type validation of arguments against the format string.
 
std::string jau::unsafe::format_string (const char *format,...) noexcept
 Returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument while utilizing the unsafe vsnprintf.
 
std::string jau::unsafe::format_string_h (const std::size_t strLenHint, const char *format,...) noexcept
 Returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument while utilizing the unsafe vsnprintf.
 
std::string jau::unsafe::format_string_n (const std::size_t maxStrLen, const char *format,...) noexcept
 Returns a (potentially truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument while utilizing the unsafe vsnprintf.
 
template<typename... Targs>
Result jau::cfmt::formatR (const std::size_t strLenHint, std::string &s, size_t maxLen, std::string_view fmt, const Targs &...args) noexcept
 Strict format with type validation of arguments against the format string, appending to the given destination.
 
template<typename... Targs>
Result jau::cfmt::formatR (const std::size_t strLenHint, std::string &s, std::string_view fmt, const Targs &...args) noexcept
 Strict format with type validation of arguments against the format string, appending to the given destination.
 
template<typename... Targs>
Result jau::cfmt::formatR (std::string &s, size_t maxLen, std::string_view fmt, const Targs &...args) noexcept
 Strict format with type validation of arguments against the format string, appending to the given destination.
 
template<typename... Targs>
Result jau::cfmt::formatR (std::string &s, std::string_view fmt, const Targs &...args) noexcept
 Strict format with type validation of arguments against the format string, appending to the given destination.
 
UInt64SizeBoolTuple jau::fromBitString (std::string_view const bitstr, const bit_order_t bitOrder=bit_order_t::msb, const Bool checkPrefix=Bool::True) noexcept
 Converts a given binary string representation into a uint64_t value according to bitStringBytes().
 
SizeBoolPair jau::fromBitString (std::vector< uint8_t > &out, const std::string_view bitstr, const bit_order_t bitOrder=bit_order_t::msb, const Bool checkPrefix=Bool::True)
 See fromBitString()
 
SizeBoolPair jau::fromBitString (std::vector< uint8_t > &out, const uint8_t bitstr[], const size_t bitstr_len, const bit_order_t bitOrder=bit_order_t::msb, const Bool checkPrefix=Bool::True)
 Converts a given binary string representation, appending to a byte vector (lsb-first).
 
UInt8PtrSizeBoolPair jau::fromBitString (uint8_t *out, size_t out_len, const std::string_view bitstr, const bit_order_t bitOrder=bit_order_t::msb, const Bool checkPrefix=Bool::True) noexcept
 See fromBitString()
 
UInt8PtrSizeBoolPair jau::fromBitString (uint8_t *out, size_t out_len, const uint8_t bitstr[], const size_t bitstr_len, const bit_order_t bitOrder=bit_order_t::msb, const Bool checkPrefix=Bool::True) noexcept
 Converts a given binary string representation, storing into a byte array(lsb-first).
 
UInt64SizeBoolTuple jau::fromHexString (std::string_view const hexstr, const lb_endian_t byteOrder=lb_endian_t::big, const Bool checkPrefix=Bool::True) noexcept
 Converts a given hexadecimal string representation appending to a uint64_t value according to hexStringBytes().
 
SizeBoolPair jau::fromHexString (std::vector< uint8_t > &out, const std::string_view hexstr, const lb_endian_t byteOrder=lb_endian_t::big, const Bool checkPrefix=Bool::True)
 See hexStringBytes()
 
SizeBoolPair jau::fromHexString (std::vector< uint8_t > &out, const uint8_t hexstr[], const size_t hexstr_len, const lb_endian_t byteOrder=lb_endian_t::big, const Bool checkPrefix=Bool::True)
 Converts a given hexadecimal string representation, appending to a byte vector (lsb-first).
 
UInt8PtrSizeBoolPair jau::fromHexString (uint8_t *out, size_t out_len, const std::string_view hexstr, const lb_endian_t byteOrder=lb_endian_t::big, const Bool checkPrefix=Bool::True) noexcept
 See hexStringBytes()
 
UInt8PtrSizeBoolPair jau::fromHexString (uint8_t *out, size_t out_len, const uint8_t hexstr[], const size_t hexstr_len, const lb_endian_t byteOrder=lb_endian_t::big, const Bool checkPrefix=Bool::True) noexcept
 Converts a given hexadecimal string representation, storing into a byte array(lsb-first).
 
template<std::integral value_type>
constexpr SizeBoolPair jau::fromIntString (value_type &result, const char *str, size_t str_len, uint32_t radix=10, const char separator=0) noexcept
 See fromIntString.
 
template<std::integral value_type>
constexpr SizeBoolPair jau::fromIntString (value_type &result, std::string_view str, uint32_t radix=10, const char separator=0) noexcept
 Converts a given integer string representation to the given result reference, compatible with ::strtoll()
 
std::string jau::get_string (const uint8_t *buffer, nsize_t const buffer_len, nsize_t const max_len)
 Returns a C++ String taken from buffer with maximum length of min(max_len, max_len).
 
constexpr int32_t jau::hexDigit (const uint8_t c) noexcept
 
bool jau::is_ascii_code (int c) noexcept
 
constexpr bool jau::is_digit (const char c, const uint32_t radix=10, const char separator=0) noexcept
 Returns true if given char c matches the char symbol range with the radix 16, 10 (default), 8 or 2.
 
constexpr bool jau::is_space (const char c) noexcept
 Returns true if given char c is one of the following whitespace character:
 
 jau::cfmt::JAU_MAKE_BITFIELD_ENUM_STRING (flags_t, hash, zeropad, left, space, plus, thousands, uppercase)
 
 jau::cfmt::JAU_MAKE_ENUM_STRING (cspec_t, character, string, pointer, signed_int, unsigned_int, floating_point, exp_float, alt_float, hex_float)
 
 jau::cfmt::JAU_MAKE_ENUM_STRING (plength_t, hh, h, l, ll, L, j, z, t)
 
template<typename CharT, std::size_t N, std::size_t O>
constexpr BasicStringLiteral< CharT, N+O-1 > jau::operator+ (const BasicStringLiteral< CharT, N > &lhs, const char(&rhs)[O])
 
template<typename CharT, size_t O, std::size_t N>
constexpr BasicStringLiteral< CharT, N+O-1 > jau::operator+ (const char(&lhs)[O], const BasicStringLiteral< CharT, N > rhs)
 
std::ostream & jau::cfmt::operator<< (std::ostream &out, const FormatOpts &o)
 
std::ostream & jau::cfmt::operator<< (std::ostream &out, const Result &pc)
 
std::vector< std::string > jau::split_string (const std::string &str, const std::string &separator)
 Split given string str at separator into the resulting std::vector excluding the separator sequence .
 
std::string jau::string_noexcept (std::string_view v) noexcept
 No throw std::string(std::string_view) instantiation.
 
template<class UnaryPredicate>
std::string jau::string_noexcept (UnaryPredicate p) noexcept
 No throw wrap for given unary predicate p producing a std::string. Returns an empty string if p causes an exception.
 
template<class value_type, std::enable_if_t< std::is_integral_v< value_type >, bool > = true>
std::string jau::to_decstring (const value_type &v, const char separator='\'', const nsize_t min_width=0) noexcept
 Produces a decimal integer string representation of an integral integer value with given radix.
 
static constexpr const char * jau::cfmt::to_string (pstate_t s) noexcept
 
template<typename CharT, std::size_t N>
constexpr std::string jau::to_string (const CharT(&ref)[N])
 
template<class value_type>
requires std::is_same_v<jau::StringLiteral<value_type::size>, value_type>
constexpr std::string jau::to_string (const value_type &ref)
 
template<class value_type, std::enable_if_t<(std::is_integral_v< value_type > &&!std::is_same_v< bool, std::remove_cv_t< value_type > >)||std::is_floating_point_v< value_type >, bool > = true>
std::string jau::to_string (const value_type &ref)
 
template<typename T>
std::string jau::to_string (std::vector< T > const &list)
 
template<typename T>
std::string jau::to_string (std::vector< T > const &list, const nsize_t radix)
 
template<typename T>
std::string jau::to_string (std::vector< T > const &list, const std::string &delim)
 
template<typename T>
std::string jau::to_string (std::vector< T > const &list, const std::string &delim, const nsize_t radix)
 
template<std::integral value_type>
std::string jau::to_string (value_type v, const uint32_t radix, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix, const uint32_t min_width=0, const char separator=0, const char padding='0') noexcept
 Produces an integer string representation of an integral integer value with given radix.
 
template<class uint8_container_type>
requires jau::req::contiguous_container<uint8_container_type> && std::convertible_to<typename uint8_container_type::value_type, uint8_t>
std::string jau::toBitString (const uint8_container_type &bytes, const bit_order_t bitOrder=bit_order_t::msb, const PrefixOpt prefix=PrefixOpt::prefix, size_t bit_len=0) noexcept
 Produce a binary string representation with leading 0b in MSB of the given uint8_t continuous container values.
 
std::string jau::toBitString (const void *data, const nsize_t length, const bit_order_t bitOrder=bit_order_t::msb, const PrefixOpt prefix=PrefixOpt::prefix, size_t bit_len=0) noexcept
 Produce a binary string representation of the given lsb-first byte values.
 
template<class value_type>
requires jau::req::standard_layout<value_type> && jau::req::trivially_copyable<value_type> && (!jau::req::container<value_type>) && (!jau::req::pointer<value_type>)
std::string jau::toBitString (value_type const &v, const bit_order_t bitOrder=bit_order_t::msb, const PrefixOpt prefix=PrefixOpt::prefix, size_t bit_len=0) noexcept
 Produce a binary string representation with leading 0b in MSB of the given value with standard layout.
 
template<class uint8_container_type>
requires jau::req::contiguous_container<uint8_container_type> && std::convertible_to<typename uint8_container_type::value_type, uint8_t>
std::string jau::toHexString (const uint8_container_type &bytes, const lb_endian_t byteOrder=lb_endian_t::big, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt skipPrefix=PrefixOpt::prefix) noexcept
 Produce a lower-case hexadecimal string representation with leading 0x in MSB of the given uint8_t continuous container values.
 
std::string jau::toHexString (const void *data, const nsize_t length, const lb_endian_t byteOrder=lb_endian_t::big, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix) noexcept
 Produce a hexadecimal string representation of the given lsb-first byte values.
 
template<class value_type>
requires jau::req::pointer<value_type> && (!jau::req::container<value_type>)
std::string jau::toHexString (value_type const &v, const lb_endian_t byteOrder=lb_endian_t::big, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix) noexcept
 Produce a lower-case hexadecimal string representation with leading 0x in MSB of the given pointer.
 
std::string jau::toLower (const std::string &s)
 
std::string & jau::toLowerInPlace (std::string &s) noexcept
 
std::string jau::trim (const std::string &s)
 trim copy
 
void jau::trimInPlace (std::string &s) noexcept
 trim in place
 
std::string jau::unsafe::vformat_string_h (const std::size_t strLenHint, const char *format, va_list args) noexcept
 
std::string jau::unsafe::vformat_string_n (const std::size_t maxStrLen, const char *format, va_list args) noexcept
 

Variables

constexpr const size_t jau::cfmt::default_string_capacity = 511
 Default string reserved capacity w/o EOS (511)
 
constexpr const char * jau::HexadecimalArrayBig = "0123456789ABCDEF"
 
constexpr const char * jau::HexadecimalArrayLow = "0123456789abcdef"
 
constexpr const size_t jau::cfmt::num_max_slen = 31
 Maximum net number string len w/o EOS, up to uint64_t.
 

Detailed Description

String utilities for type conversion and manipulation.

Macro Definition Documentation

◆ jau_format_string

#define jau_format_string ( fmt,
... )
Value:
jau::format_string((fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
#define JAU_NOREF_DECLTYPE_VALUE(type)
#define JAU_FOR_EACH1_LIST(macro,...)
consteval_cxx20 ssize_t check2(std::string_view fmt) noexcept
Strict compile-time type validation of explicit argument-types against the format string.
std::string format_string(std::string_view fmt, const Args &...args) noexcept
Safely returns a (non-truncated) string according to snprintf() formatting rules using a reserved str...

Macro, safely returns a (non-truncated) string according to snprintf() formatting rules using a reserved string length of jau::cfmt::default_string_capacity and variable number of arguments following the fmt argument.

This macro also produces compile time validation using a static_assert against jau::cfmt::check2.

jau::cfmt::formatR() is utilize to validate format against given arguments at runtime.

Resulting string size matches formated output w/o limitation and its capacity is left unchanged.

Use std::string::shrink_to_fit() on the returned string, if you desire efficiency for longer lifecycles.

See jau_cfmt_header for details

Parameters
formatprintf() compliant format string
argsarguments matching the format string
Examples
test_stringfmt_check.cpp, test_stringfmt_format.cpp, and test_stringfmt_perf.cpp.

Definition at line 2030 of file string_cfmt.hpp.

◆ jau_format_string_h

#define jau_format_string_h ( strLenHint,
fmt,
... )
Value:
jau::format_string((strLenHint), (fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 <= jau::cfmt::check2< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));

Macro, safely returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the fmt argument.

This macro also produces compile time validation using a static_assert against jau::cfmt::check2.

jau::cfmt::formatR() is utilize to validate format against given arguments at runtime.

Resulting string size matches formated output w/o limitation and its capacity is left unchanged.

Use std::string::shrink_to_fit() on the returned string, if you desire efficiency for longer lifecycles.

See jau_cfmt_header for details

Parameters
strLenHintinitially used string length w/o EOS
formatprintf() compliant format string
argsarguments matching the format string

Definition at line 2055 of file string_cfmt.hpp.

◆ jau_format_string2

#define jau_format_string2 ( fmt,
... )
Value:
jau::format_string((fmt) __VA_OPT__(,) __VA_ARGS__); \
static_assert(0 == jau::cfmt::check2Line< JAU_FOR_EACH1_LIST(JAU_NOREF_DECLTYPE_VALUE, __VA_ARGS__) >(fmt));
consteval_cxx20 int check2Line(std::string_view fmt) noexcept
Strict compile-time type validation of explicit argument-types against the format string.

Macro, safely returns a (non-truncated) string according to snprintf() formatting rules using a reserved string length of jau::cfmt::default_string_capacity and variable number of arguments following the fmt argument.

This macro also produces compile time validation using a static_assert against jau::cfmt::check2Line.

jau::cfmt::formatR() is utilize to validate format against given arguments at runtime.

Resulting string size matches formated output w/o limitation and its capacity is left unchanged.

Use std::string::shrink_to_fit() on the returned string, if you desire efficiency for longer lifecycles.

See jau_cfmt_header for details

Parameters
formatprintf() compliant format string
argsarguments matching the format string

Definition at line 2080 of file string_cfmt.hpp.

◆ jau_format_check

#define jau_format_check ( fmt,
... )
Value:

Macro produces compile time validation using a static_assert against jau::cfmt::check2.

See jau_cfmt_header for details

Parameters
formatprintf() compliant format string
argsarguments matching the format string
Examples
test_stringfmt_check.cpp, and test_stringfmt_format.cpp.

Definition at line 2093 of file string_cfmt.hpp.

◆ jau_format_checkLine

#define jau_format_checkLine ( fmt,
... )
Value:

Macro produces compile time validation using a static_assert against jau::cfmt::check2Line.

See jau_cfmt_header for details

Parameters
formatprintf() compliant format string
argsarguments matching the format string
Examples
test_stringfmt_check.cpp, and test_stringfmt_format.cpp.

Definition at line 2105 of file string_cfmt.hpp.

Typedef Documentation

◆ StringLiteral

template<size_t N>
using jau::StringLiteral = BasicStringLiteral<char, N>

Definition at line 168 of file string_literal.hpp.

◆ WStringLiteral

template<size_t N>
using jau::WStringLiteral = BasicStringLiteral<wchar_t, N>

Definition at line 171 of file string_literal.hpp.

Enumeration Type Documentation

◆ pstate_t

enum class jau::cfmt::pstate_t : uint16_t
strong
Enumerator
error 
outside 
start 
field_width 
precision 

Definition at line 227 of file string_cfmt.hpp.

◆ flags_t

enum class jau::cfmt::flags_t : uint16_t
strong

Format flags.

Enumerator
none 

no flag

hash 

actual flag #, C99

zeropad 

actual flag 0, C99

left 

actual flag -, C99

space 

actual flag , C99

plus 

actual flag +, C99

thousands 

actual flag ‘&rsquo;`, POSIX

uppercase 

uppercase, via conversion spec

Definition at line 245 of file string_cfmt.hpp.

◆ plength_t

enum class jau::cfmt::plength_t : uint16_t
strong

Format length modifiers.

Enumerator
none 
hh 

char integer

short integer

long integer

ll 

long long integer

long double float

intmax_t or uintmax_t integer

size_t or ssize_t integer

ptrdiff_t

Definition at line 260 of file string_cfmt.hpp.

◆ cspec_t

enum class jau::cfmt::cspec_t : uint16_t
strong

Format conversion specifier (fully defined w/ radix)

Enumerator
none 

none

character 

c

string 

s

pointer 

p

signed_int 

d or i

unsigned_int 

o, x or X, u, b

floating_point 

f or F

exp_float 

e or E

alt_float 

g or G

hex_float 

a or A

Definition at line 274 of file string_cfmt.hpp.

◆ LoUpCase

enum class jau::LoUpCase : bool
strong
Enumerator
lower 
upper 

Definition at line 178 of file string_util.hpp.

◆ PrefixOpt

enum class jau::PrefixOpt : bool
strong
Enumerator
none 
prefix 

Definition at line 183 of file string_util.hpp.

Function Documentation

◆ string_noexcept() [1/2]

template<class UnaryPredicate>
std::string jau::string_noexcept ( UnaryPredicate p)
inlinenoexcept

No throw wrap for given unary predicate p producing a std::string. Returns an empty string if p causes an exception.

Definition at line 509 of file cpp_lang_util.hpp.

Here is the caller graph for this function:

◆ string_noexcept() [2/2]

std::string jau::string_noexcept ( std::string_view v)
inlinenoexcept

No throw std::string(std::string_view) instantiation.

Definition at line 521 of file cpp_lang_util.hpp.

◆ to_string() [1/9]

static constexpr const char * jau::cfmt::to_string ( pstate_t s)
staticconstexprnoexcept

Definition at line 234 of file string_cfmt.hpp.

◆ JAU_MAKE_BITFIELD_ENUM_STRING()

jau::cfmt::JAU_MAKE_BITFIELD_ENUM_STRING ( flags_t ,
hash ,
zeropad ,
left ,
space ,
plus ,
thousands ,
uppercase  )

◆ JAU_MAKE_ENUM_STRING() [1/2]

jau::cfmt::JAU_MAKE_ENUM_STRING ( plength_t ,
hh ,
h ,
l ,
ll ,
L ,
j ,
z ,
t  )

◆ JAU_MAKE_ENUM_STRING() [2/2]

jau::cfmt::JAU_MAKE_ENUM_STRING ( cspec_t ,
character ,
string ,
pointer ,
signed_int ,
unsigned_int ,
floating_point ,
exp_float ,
alt_float ,
hex_float  )

◆ operator<<() [1/2]

std::ostream & jau::cfmt::operator<< ( std::ostream & out,
const FormatOpts & o )
inline

Definition at line 448 of file string_cfmt.hpp.

◆ operator<<() [2/2]

std::ostream & jau::cfmt::operator<< ( std::ostream & out,
const Result & pc )
inline

Definition at line 485 of file string_cfmt.hpp.

◆ format() [1/2]

template<typename... Targs>
std::string jau::cfmt::format ( std::string_view fmt,
const Targs &... args )
inlinenoexcept

Strict format with type validation of arguments against the format string.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack for the given arguments args
Parameters
fmtthe snprintf compliant format string
argspassed arguments, used for template type deduction only
Returns
true if successfully parsed format and arguments, false otherwise.
See also
jau_cfmt_header
Examples
test_stringfmt_perf.cpp.

Definition at line 1592 of file string_cfmt.hpp.

Here is the caller graph for this function:

◆ format() [2/2]

template<typename... Targs>
std::string jau::cfmt::format ( size_t maxLen,
std::string_view fmt,
const Targs &... args )
inlinenoexcept

Strict format with type validation of arguments against the format string.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack for the given arguments args
Parameters
maxLenmaximum string length
fmtthe snprintf compliant format string
argspassed arguments, used for template type deduction only
Returns
true if successfully parsed format and arguments, false otherwise.
See also
jau_cfmt_header

Definition at line 1623 of file string_cfmt.hpp.

◆ formatR() [1/4]

template<typename... Targs>
Result jau::cfmt::formatR ( std::string & s,
size_t maxLen,
std::string_view fmt,
const Targs &... args )
inlinenoexcept

Strict format with type validation of arguments against the format string, appending to the given destination.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack for the given arguments args
Parameters
sdestination string to append the formatted string
maxLenmaximum string length
fmtthe snprintf compliant format string
argspassed arguments, used for template type deduction only
Returns
jau::cfmt::Result instance for further inspection
See also
jau_cfmt_header
Examples
test_stringfmt_check.cpp, test_stringfmt_format.cpp, and test_stringfmt_perf.cpp.

Definition at line 1656 of file string_cfmt.hpp.

Here is the caller graph for this function:

◆ formatR() [2/4]

template<typename... Targs>
Result jau::cfmt::formatR ( std::string & s,
std::string_view fmt,
const Targs &... args )
inlinenoexcept

Strict format with type validation of arguments against the format string, appending to the given destination.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack for the given arguments args
Parameters
sdestination string to append the formatted string
fmtthe snprintf compliant format string
argspassed arguments, used for template type deduction only
Returns
jau::cfmt::Result instance for further inspection
See also
jau_cfmt_header

Definition at line 1686 of file string_cfmt.hpp.

◆ formatR() [3/4]

template<typename... Targs>
Result jau::cfmt::formatR ( const std::size_t strLenHint,
std::string & s,
size_t maxLen,
std::string_view fmt,
const Targs &... args )
inlinenoexcept

Strict format with type validation of arguments against the format string, appending to the given destination.

Resulting string is truncated to min(maxLen, formatLen), with formatLen being the given formatted string length of output w/o limitation and its capacity is left unchanged.

Use std::string::shrink_to_fit() on the returned string, if you desire efficiency for longer lifecycles (assuming maxLen hasn't been reached).

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack for the given arguments args
Parameters
strLenHintinitially used string length w/o EOS
sdestination string to append the formatted string
maxLenmaximum resulting string length including EOS
fmtthe snprintf compliant format string
argsarguments matching the format string

Definition at line 1712 of file string_cfmt.hpp.

◆ formatR() [4/4]

template<typename... Targs>
Result jau::cfmt::formatR ( const std::size_t strLenHint,
std::string & s,
std::string_view fmt,
const Targs &... args )
inlinenoexcept

Strict format with type validation of arguments against the format string, appending to the given destination.

Resulting string size matches formated output w/o limitation and its capacity is left unchanged.

Use std::string::shrink_to_fit() on the returned string, if you desire efficiency for longer lifecycles.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack for the given arguments args
Parameters
strLenHintinitially used string length w/o EOS
fmtthe snprintf compliant format string
argsarguments matching the format string

Definition at line 1748 of file string_cfmt.hpp.

◆ check()

template<typename... Targs>
consteval_cxx20 ssize_t jau::cfmt::check ( std::string_view fmt,
const Targs & ... )
noexcept

Strict compile-time type validation of deduced argument-types against the format string.

In case your can't provide constexpr arguments, use check2(). Types can always be produced, see macro jau_string_checkLine().

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack to be validated against the format string
Parameters
fmtthe snprintf compliant format string
argspassed arguments, used for template type deduction only
Returns
number of parser format arguments if successfully, otherwise negative number indicates first failed argument starting with -1 w/ min(ssize_t) denoting the format string
See also
jau_cfmt_header
Examples
test_stringfmt_check.cpp, test_stringfmt_format.cpp, and test_stringfmt_perf.cpp.

Definition at line 1772 of file string_cfmt.hpp.

Here is the caller graph for this function:

◆ checkLine()

template<typename... Targs>
consteval_cxx20 int jau::cfmt::checkLine ( std::string_view fmt,
const Targs & ... )
noexcept

Strict compile-time type validation of deduced argument-types against the format string.

In case your can't provide constexpr arguments, use check2Line(). Types can always be produced, see macro jau_string_checkLine().

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack to be validated against the format string
Parameters
fmtthe snprintf compliant format string
argspassed arguments, used for template type deduction only
Returns
0 if successfully, otherwise the source code line number detecting the failure
See also
jau_cfmt_header
Examples
test_stringfmt_check.cpp, and test_stringfmt_format.cpp.

Definition at line 1795 of file string_cfmt.hpp.

Here is the caller graph for this function:

◆ check2()

template<typename... Targs>
consteval_cxx20 ssize_t jau::cfmt::check2 ( std::string_view fmt)
noexcept

Strict compile-time type validation of explicit argument-types against the format string.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack to be validated against the format string
Parameters
fmtthe snprintf compliant format string
Returns
number of parser format arguments if successfully, otherwise negative number indicates first failed argument starting with -1 w/ min(ssize_t) denoting the format string
See also
jau_cfmt_header

Definition at line 1816 of file string_cfmt.hpp.

◆ check2Line()

template<typename... Targs>
consteval_cxx20 int jau::cfmt::check2Line ( std::string_view fmt)
noexcept

Strict compile-time type validation of explicit argument-types against the format string.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack to be validated against the format string
Parameters
fmtthe snprintf compliant format string
Returns
0 if successfully, otherwise the source code line number detecting the failure
See also
jau_cfmt_header

Definition at line 1836 of file string_cfmt.hpp.

Here is the caller graph for this function:

◆ checkR()

template<typename... Targs>
consteval_cxx20 Result jau::cfmt::checkR ( std::string_view fmt,
const Targs & ... )
noexcept

Strict compile-time type validation of deduced argument-types against the format string.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack to be validated against the format string
Parameters
fmtthe snprintf compliant format string
argspassed arguments, used for template type deduction only
Returns
jau::cfmt::Result instance for further inspection
See also
jau_cfmt_header
Examples
test_stringfmt_check.cpp, and test_stringfmt_perf.cpp.

Definition at line 1857 of file string_cfmt.hpp.

Here is the caller graph for this function:

◆ checkR2()

template<typename... Targs>
consteval_cxx20 Result jau::cfmt::checkR2 ( std::string_view format)
noexcept

Strict compile-time type validation of explicit argument-types against the format string.

See jau_cfmt_header for details

Template Parameters
Targsthe argument template type pack to be validated against the format string
Parameters
fmtthe snprintf compliant format string
Returns
jau::cfmt::Result instance for further inspection
See also
jau_cfmt_header

Definition at line 1877 of file string_cfmt.hpp.

◆ BasicStringLiteral() [1/2]

template<typename CharT, std::convertible_to< CharT >... Rest>
jau::BasicStringLiteral ( CharT ,
Rest...  ) -> BasicStringLiteral< CharT, 1+sizeof...(Rest)>

◆ BasicStringLiteral() [2/2]

template<typename CharT, size_t O>
jau::BasicStringLiteral ( const CharT(&) str[O]) -> BasicStringLiteral< CharT, O - 1 >

◆ operator+() [1/2]

template<typename CharT, std::size_t N, std::size_t O>
BasicStringLiteral< CharT, N+O-1 > jau::operator+ ( const BasicStringLiteral< CharT, N > & lhs,
const char(&) rhs[O] )
constexpr

Definition at line 158 of file string_literal.hpp.

◆ operator+() [2/2]

template<typename CharT, size_t O, std::size_t N>
BasicStringLiteral< CharT, N+O-1 > jau::operator+ ( const char(&) lhs[O],
const BasicStringLiteral< CharT, N > rhs )
constexpr

Definition at line 163 of file string_literal.hpp.

◆ is_ascii_code()

bool jau::is_ascii_code ( int c)
inlinenoexcept

Definition at line 63 of file string_util.hpp.

◆ is_space()

bool jau::is_space ( const char c)
constexprnoexcept

Returns true if given char c is one of the following whitespace character:

  • space (0x20, )
  • form feed (0x0c, \f)
  • line feed (0x0a, \n)
  • carriage return (0x0d, \r)
  • horizontal tab (0x09, \t)
  • vertical tab (0x0b, \v)

Definition at line 76 of file string_util.hpp.

Here is the caller graph for this function:

◆ is_digit()

bool jau::is_digit ( const char c,
const uint32_t radix = 10,
const char separator = 0 )
constexprnoexcept

Returns true if given char c matches the char symbol range with the radix 16, 10 (default), 8 or 2.

Definition at line 89 of file string_util.hpp.

Here is the caller graph for this function:

◆ digit()

int32_t jau::digit ( const uint8_t c,
const uint32_t radix = 10 )
constexprnoexcept

Returns digit value of given char c matching the radix 16, 10, 8 or 2, -1 on no match.

Definition at line 110 of file string_util.hpp.

Here is the caller graph for this function:

◆ hexDigit()

int32_t jau::hexDigit ( const uint8_t c)
constexprnoexcept

Definition at line 143 of file string_util.hpp.

Here is the caller graph for this function:

◆ get_string()

std::string jau::get_string ( const uint8_t * buffer,
nsize_t const buffer_len,
nsize_t const max_len )

Returns a C++ String taken from buffer with maximum length of min(max_len, max_len).

The maximum length only delimits the string length and does not contain the EOS null byte. An EOS null byte will will be added.

The source string within buffer is not required to contain an EOS null byte;

Definition at line 445 of file basic_types.cpp.

◆ trimInPlace()

void jau::trimInPlace ( std::string & s)
noexcept

trim in place

Definition at line 451 of file basic_types.cpp.

Here is the caller graph for this function:

◆ trim()

std::string jau::trim ( const std::string & s)

trim copy

Definition at line 460 of file basic_types.cpp.

◆ split_string()

std::vector< std::string > jau::split_string ( const std::string & str,
const std::string & separator )

Split given string str at separator into the resulting std::vector excluding the separator sequence .

Definition at line 466 of file basic_types.cpp.

Here is the caller graph for this function:

◆ toLowerInPlace()

std::string & jau::toLowerInPlace ( std::string & s)
noexcept

Definition at line 480 of file basic_types.cpp.

Here is the caller graph for this function:

◆ toLower()

std::string jau::toLower ( const std::string & s)

Definition at line 485 of file basic_types.cpp.

Here is the caller graph for this function:

◆ fromHexString() [1/5]

SizeBoolPair jau::fromHexString ( std::vector< uint8_t > & out,
const uint8_t hexstr[],
const size_t hexstr_len,
const lb_endian_t byteOrder = lb_endian_t::big,
const Bool checkPrefix = Bool::True )

Converts a given hexadecimal string representation, appending to a byte vector (lsb-first).

In case a non valid hexadecimal digit appears in the given string, conversion ends and fills the byte vector up until the violation.

In case hexstr contains an odd number of hex-nibbles, it will be interpreted as follows

  • 0xf[12] = 0x0f12 = { 0x12, 0x0f } - msb, 1st single low-nibble is most significant
  • [12]f = 0xf012 = { 0x12, 0xf0 } - lsb, last single high-nibble is most significant

Even if complete==false, result holds the partial value if consumed_chars>0.

You may use C++17 structured bindings to handle the pair.

Parameters
outthe byte vector sink to append, lsb-first
hexstrthe hexadecimal string representation
hexstr_lenlength of hextstr
byteOrderlb_endian_t::big for big-endian bytes in hexstr (default)
checkPrefixif True, checks for a leading 0x and removes it, otherwise not.
Returns
pair [size_t consumed_chars, bool complete], i.e. consumed characters of string and completed=false if not fully consumed.
Examples
test_basictypeconv.cpp.

Definition at line 683 of file basic_types.cpp.

Here is the caller graph for this function:

◆ fromHexString() [2/5]

SizeBoolPair jau::fromHexString ( std::vector< uint8_t > & out,
const std::string_view hexstr,
const lb_endian_t byteOrder = lb_endian_t::big,
const Bool checkPrefix = Bool::True )
inline

See hexStringBytes()

Definition at line 213 of file string_util.hpp.

◆ fromHexString() [3/5]

UInt8PtrSizeBoolPair jau::fromHexString ( uint8_t * out,
size_t out_len,
const uint8_t hexstr[],
const size_t hexstr_len,
const lb_endian_t byteOrder = lb_endian_t::big,
const Bool checkPrefix = Bool::True )
noexcept

Converts a given hexadecimal string representation, storing into a byte array(lsb-first).

In case a non valid hexadecimal digit appears in the given string, conversion ends and fills the byte vector up until the violation.

In case hexstr contains an odd number of hex-nibbles, it will be interpreted as follows

  • 0xf[12] = 0x0f12 = { 0x12, 0x0f } - msb, 1st single low-nibble is most significant
  • [12]f = 0xf012 = { 0x12, 0xf0 } - lsb, last single high-nibble is most significant

Even if complete==false, result holds the partial value if consumed_chars>0.

You may use C++17 structured bindings to handle the triple.

Parameters
outbyte array pointer to store result, lsb-first
out_lensize of byte array
hexstrthe hexadecimal string representation
hexstr_lenlength of hextstr
byteOrderlb_endian_t::big for big-endian bytes in hexstr (default)
checkPrefixif True, checks for a leading 0x and removes it, otherwise not.
Returns
triple [uint8_t* out_end, size_t consumed_chars, bool complete], i.e. end pointer of out (last write + 1), consumed characters of string and completed=false if not fully consumed.

Definition at line 760 of file basic_types.cpp.

◆ fromHexString() [4/5]

UInt8PtrSizeBoolPair jau::fromHexString ( uint8_t * out,
size_t out_len,
const std::string_view hexstr,
const lb_endian_t byteOrder = lb_endian_t::big,
const Bool checkPrefix = Bool::True )
inlinenoexcept

See hexStringBytes()

Definition at line 245 of file string_util.hpp.

◆ fromHexString() [5/5]

UInt64SizeBoolTuple jau::fromHexString ( std::string_view const hexstr,
const lb_endian_t byteOrder = lb_endian_t::big,
const Bool checkPrefix = Bool::True )
noexcept

Converts a given hexadecimal string representation appending to a uint64_t value according to hexStringBytes().

Even if complete==false, result holds the partial value if consumed_chars>0.

You may use C++17 structured bindings to handle the tuple.

Parameters
hexstrthe hexadecimal string representation
byteOrderlb_endian_t::big for big-endian bytes in hexstr (default)
checkPrefixif True, checks for a leading 0x and removes it, otherwise not.
Returns
tuple [uint64_t result, size_t consumed_chars, bool complete], i.e. consumed characters of string and completed=false if not fully consumed.
See also
hexStringBytes()
to_hexstring()

Definition at line 842 of file basic_types.cpp.

◆ appendHexString() [1/2]

std::string & jau::appendHexString ( std::string & dest,
const void * data,
const nsize_t length,
const lb_endian_t byteOrder = lb_endian_t::big,
const LoUpCase capitalization = LoUpCase::lower,
const PrefixOpt prefix = PrefixOpt::prefix )
noexcept

Appends a hexadecimal string representation of the given lsb-first byte values.

If byteOrder is lb_endian_t::little, orders lsb-byte left, usual for byte streams. Result will not have a leading 0x. Otherwise, lb_endian_t::big (default), orders msb-byte left for integer values. Result will have a leading 0x if !skipPrefix.

Parameters
destthe std::string to append to
datapointer to the first byte to print, lsb-first
lengthnumber of bytes to print
byteOrderlb_endian_t::big for big-endian bytes in resulting hex-string (default). A leading 0x will be prepended if byteOrder == lb_endian_t::big and PrefixOpt::prefix given.
capitalizationLoUpCase capitalization, default is LoUpCase::lower
prefixpass PrefixOpt::prefix (default) to add leading 0x if byteOrder == lb_endian_t::big (default)
Returns
the given string buffer for concatenation

Definition at line 1047 of file basic_types.cpp.

Here is the caller graph for this function:

◆ toHexString() [1/3]

std::string jau::toHexString ( const void * data,
const nsize_t length,
const lb_endian_t byteOrder = lb_endian_t::big,
const LoUpCase capitalization = LoUpCase::lower,
const PrefixOpt prefix = PrefixOpt::prefix )
inlinenoexcept

Produce a hexadecimal string representation of the given lsb-first byte values.

If byteOrder is lb_endian_t::little, orders lsb-byte left, usual for byte streams. Result will not have a leading 0x. Otherwise, lb_endian_t::big (default), orders msb-byte left for integer values. Result will have a leading 0x if !skipPrefix.

Parameters
datapointer to the first byte to print, lsb-first
lengthnumber of bytes to print
byteOrderlb_endian_t::big for big-endian bytes in resulting hex-string (default). A leading 0x will be prepended if byteOrder == lb_endian_t::big and PrefixOpt::prefix given.
capitalizationLoUpCase capitalization, default is LoUpCase::lower
prefixpass PrefixOpt::prefix (default) to add leading 0x if byteOrder == lb_endian_t::big (default)
Returns
the hex-string representation of the data
Examples
test_basictypeconv.cpp.

Definition at line 303 of file string_util.hpp.

Here is the caller graph for this function:

◆ appendHexString() [2/2]

std::string & jau::appendHexString ( std::string & dest,
const uint8_t value,
const LoUpCase capitalization = LoUpCase::lower )
noexcept

Produce a hexadecimal string representation of the given byte value and appends it to the given string.

Parameters
destthe std::string reference destination to append
valuethe byte value to represent
capitalizationLoUpCase capitalization, default is LoUpCase::lower
Returns
the given std::string reference for chaining

Definition at line 1098 of file basic_types.cpp.

◆ toHexString() [2/3]

template<class value_type>
requires jau::req::pointer<value_type> && (!jau::req::container<value_type>)
std::string jau::toHexString ( value_type const & v,
const lb_endian_t byteOrder = lb_endian_t::big,
const LoUpCase capitalization = LoUpCase::lower,
const PrefixOpt prefix = PrefixOpt::prefix )
inlinenoexcept

Produce a lower-case hexadecimal string representation with leading 0x in MSB of the given pointer.

Template Parameters
value_typea pointer type
Parameters
vthe pointer of given pointer type
byteOrderlb_endian_t::big for big-endian bytes in resulting hex-string (default). A leading 0x will be prepended if byteOrder == lb_endian_t::big and PrefixOpt::prefix given.
capitalizationLoUpCase capitalization, default is LoUpCase::lower
prefixpass PrefixOpt::prefix (default) to add leading 0x if byteOrder == lb_endian_t::big (default)
Returns
the hex-string representation of the value
See also
toHexString()
fromHexString()

Definition at line 335 of file string_util.hpp.

◆ toHexString() [3/3]

template<class uint8_container_type>
requires jau::req::contiguous_container<uint8_container_type> && std::convertible_to<typename uint8_container_type::value_type, uint8_t>
std::string jau::toHexString ( const uint8_container_type & bytes,
const lb_endian_t byteOrder = lb_endian_t::big,
const LoUpCase capitalization = LoUpCase::lower,
const PrefixOpt skipPrefix = PrefixOpt::prefix )
inlinenoexcept

Produce a lower-case hexadecimal string representation with leading 0x in MSB of the given uint8_t continuous container values.

Template Parameters
uint8_container_typea uint8_t continuous container type
Parameters
bytesthe value of given uint8_t continuous container type
byteOrderlb_endian_t::big for big-endian bytes in resulting hex-string (default). A leading 0x will be prepended if byteOrder == lb_endian_t::big and PrefixOpt::prefix given.
capitalizationLoUpCase capitalization, default is LoUpCase::lower
prefixpass PrefixOpt::prefix (default) to add leading 0x if byteOrder == lb_endian_t::big (default)
Returns
the hex-string representation of the value
See also
toHexString()
fromHexString()

Definition at line 359 of file string_util.hpp.

◆ fromBitString() [1/5]

SizeBoolPair jau::fromBitString ( std::vector< uint8_t > & out,
const uint8_t bitstr[],
const size_t bitstr_len,
const bit_order_t bitOrder = bit_order_t::msb,
const Bool checkPrefix = Bool::True )

Converts a given binary string representation, appending to a byte vector (lsb-first).

In case a non valid binary digit appears in the given string, conversion ends and fills the byte vector up until the violation.

In case bitstr contains an incomplete number of bit-nibbles, it will be interpreted as follows

  • 0b11[00000001] = 0x0301 = { 0x01, 0x03 } - msb, 1st single low-nibble is most significant
  • 0b[01000000]11 = 0xC040 = { 0x40, 0xC0 } - lsb, last single high-nibble is most significant
    • 11 -> 11000000 -> C0

Even if complete==false, result holds the partial value if consumed_chars>0.

You may use C++17 structured bindings to handle the pair.

Parameters
outthe byte vector sink to append, lsb-first
bitstrthe binary string representation
bitstr_lenlength of bitstr
bitOrderbit_order_t::msb for most significant bits in bitstr first (default)
checkPrefixif True, checks for a leading 0b and removes it, otherwise not.
Returns
pair [size_t consumed_chars, bool complete], i.e. consumed characters of string and completed=false if not fully consumed.
Examples
test_basictypeconv.cpp.

Definition at line 867 of file basic_types.cpp.

Here is the caller graph for this function:

◆ fromBitString() [2/5]

SizeBoolPair jau::fromBitString ( std::vector< uint8_t > & out,
const std::string_view bitstr,
const bit_order_t bitOrder = bit_order_t::msb,
const Bool checkPrefix = Bool::True )
inline

See fromBitString()

Definition at line 428 of file string_util.hpp.

◆ fromBitString() [3/5]

UInt8PtrSizeBoolPair jau::fromBitString ( uint8_t * out,
size_t out_len,
const uint8_t bitstr[],
const size_t bitstr_len,
const bit_order_t bitOrder = bit_order_t::msb,
const Bool checkPrefix = Bool::True )
noexcept

Converts a given binary string representation, storing into a byte array(lsb-first).

In case a non valid binary digit appears in the given string, conversion ends and fills the byte vector up until the violation.

In case bitstr contains an incomplete number of bit-nibbles, it will be interpreted as follows

  • 0b11[00000001] = 0x0301 = { 0x01, 0x03 } - msb, 1st single low-nibble is most significant
  • 0b[01000000]11 = 0xC040 = { 0x40, 0xC0 } - lsb, last single high-nibble is most significant
    • 11 -> 11000000 -> C0

Even if complete==false, result holds the partial value if consumed_chars>0.

You may use C++17 structured bindings to handle the triple.

Parameters
outbyte array pointer to store result, lsb-first
out_lensize of byte array
bitstrthe binary string representation
bitstr_lenlength of bitstr
bitOrderbit_order_t::msb for most significant bits in bitstr first (default)
checkPrefixif True, checks for a leading 0b and removes it, otherwise not.
Returns
triple [uint8_t* out_end, size_t consumed_chars, bool complete], i.e. end pointer of out (last write + 1), consumed characters of string and completed=false if not fully consumed.

Definition at line 946 of file basic_types.cpp.

◆ fromBitString() [4/5]

UInt8PtrSizeBoolPair jau::fromBitString ( uint8_t * out,
size_t out_len,
const std::string_view bitstr,
const bit_order_t bitOrder = bit_order_t::msb,
const Bool checkPrefix = Bool::True )
inlinenoexcept

See fromBitString()

Definition at line 461 of file string_util.hpp.

◆ fromBitString() [5/5]

UInt64SizeBoolTuple jau::fromBitString ( std::string_view const bitstr,
const bit_order_t bitOrder = bit_order_t::msb,
const Bool checkPrefix = Bool::True )
noexcept

Converts a given binary string representation into a uint64_t value according to bitStringBytes().

Even if complete==false, result holds the partial value if consumed_chars>0.

You may use C++17 structured bindings to handle the tuple.

Parameters
bitstrthe binary string representation
checkPrefixif true, checks for a leading 0b and removes it, otherwise not.
bitOrderbit_order_t::msb for most significant bits in bitstr first (default)
Returns
tuple [uint64_t result, size_t consumed_chars, bool complete], i.e. consumed characters of string and completed=false if not fully consumed.
See also
bitStringBytes()
to_bitstring()

Definition at line 1029 of file basic_types.cpp.

◆ appendBitString()

std::string & jau::appendBitString ( std::string & dest,
const void * data,
const nsize_t length,
const bit_order_t bitOrder = bit_order_t::msb,
const PrefixOpt prefix = PrefixOpt::prefix,
size_t bit_len = 0 )
noexcept

Appends a binary string representation of the given lsb-first byte values.

If byteOrder is lb_endian_t::little, orders lsb-byte left, usual for byte streams. Result will not have a leading 0b. Otherwise, lb_endian_t::big (default), orders msb-byte left for integer values. Result will have a leading 0b if !skipPrefix.

Parameters
destthe std::string to append to
datapointer to the first byte to print, lsb-first
lengthnumber of bytes to print
bitOrderbit_order_t::msb for most-significant-bit first in resulting bit-string, bit_order_t::msb is default A leading 0b will be prepended if bitOrder == bit_order_t::msb and PrefixOpt::prefix given.
prefixpass PrefixOpt::prefix (default) to add leading 0b if bitOrder == bit_order_t::msb (default)
bit_lenoptional fixed number of bits to be printed counting from lsb excluding prefix. Pass zero for dropping zero leading bytes (default).
Returns
the given string buffer for concatenation

Definition at line 1108 of file basic_types.cpp.

Here is the caller graph for this function:

◆ toBitString() [1/3]

std::string jau::toBitString ( const void * data,
const nsize_t length,
const bit_order_t bitOrder = bit_order_t::msb,
const PrefixOpt prefix = PrefixOpt::prefix,
size_t bit_len = 0 )
inlinenoexcept

Produce a binary string representation of the given lsb-first byte values.

If byteOrder is lb_endian_t::little, orders lsb-byte left, usual for byte streams. Result will not have a leading 0b. Otherwise, lb_endian_t::big (default), orders msb-byte left for integer values. Result will have a leading 0b if !skipPrefix.

Parameters
datapointer to the first byte to print, lsb-first
lengthnumber of bytes to print
bitOrderbit_order_t::msb for most-significant-bit first in resulting bit-string, bit_order_t::msb is default A leading 0b will be prepended if bitOrder == bit_order_t::msb and PrefixOpt::prefix given.
prefixpass PrefixOpt::prefix (default) to add leading 0b if bitOrder == bit_order_t::msb (default)
bit_lenoptional fixed number of bits to be printed counting from lsb excluding prefix. Pass zero for dropping zero leading bytes (default).
Returns
the bit-string representation of the data
Examples
test_basictypeconv.cpp.

Definition at line 515 of file string_util.hpp.

Here is the caller graph for this function:

◆ toBitString() [2/3]

template<class uint8_container_type>
requires jau::req::contiguous_container<uint8_container_type> && std::convertible_to<typename uint8_container_type::value_type, uint8_t>
std::string jau::toBitString ( const uint8_container_type & bytes,
const bit_order_t bitOrder = bit_order_t::msb,
const PrefixOpt prefix = PrefixOpt::prefix,
size_t bit_len = 0 )
inlinenoexcept

Produce a binary string representation with leading 0b in MSB of the given uint8_t continuous container values.

Template Parameters
uint8_container_typea uint8_t continuous container type
Parameters
bytesthe value of given uint8_t continuous container type
bitOrderbit_order_t::msb for most-significant-bit first in resulting bit-string, bit_order_t::msb is default A leading 0b will be prepended if bitOrder == bit_order_t::msb and PrefixOpt::prefix given.
prefixpass PrefixOpt::prefix (default) to add leading 0b if bitOrder == bit_order_t::msb (default)
bit_lenoptional fixed number of bits to be printed counting from lsb excluding prefix. Pass zero for dropping zero leading bytes (default).
Returns
the bit-string representation of the value
See also
toBitString()
fromBitString()

Definition at line 538 of file string_util.hpp.

◆ toBitString() [3/3]

template<class value_type>
requires jau::req::standard_layout<value_type> && jau::req::trivially_copyable<value_type> && (!jau::req::container<value_type>) && (!jau::req::pointer<value_type>)
std::string jau::toBitString ( value_type const & v,
const bit_order_t bitOrder = bit_order_t::msb,
const PrefixOpt prefix = PrefixOpt::prefix,
size_t bit_len = 0 )
inlinenoexcept

Produce a binary string representation with leading 0b in MSB of the given value with standard layout.

Template Parameters
value_typea standard layout value type
Parameters
vthe value of given standard layout type
bitOrderbit_order_t::msb for most-significant-bit first in resulting bit-string, bit_order_t::msb is default A leading 0b will be prepended if bitOrder == bit_order_t::msb and PrefixOpt::prefix given.
prefixpass PrefixOpt::prefix (default) to add leading 0b if bitOrder == bit_order_t::msb (default)
bit_lenoptional fixed number of bits to be printed counting from lsb excluding prefix. Pass zero for dropping zero leading bytes (default).
Returns
the bit-string representation of the value
See also
toBitString()
fromBitString()

Definition at line 560 of file string_util.hpp.

◆ fromIntString() [1/2]

template<std::integral value_type>
SizeBoolPair jau::fromIntString ( value_type & result,
std::string_view str,
uint32_t radix = 10,
const char separator = 0 )
constexprnoexcept

Converts a given integer string representation to the given result reference, compatible with ::strtoll()

  • Signed value_type: [space][+-][prefix][digits+sep]
  • Unsigned value_type: [space][+][prefix][digits+sep]

Even if complete==false due to empty string, under- or overflow, the result holds the partial value if consumed_chars>0.

Whitespace and non-matching chars

  • Leading and tailing whitespace chars are consumed, see jau::is_space()
  • Tail non-matching chars are ignored: complete is true but consumed_chars is < str.length()

You may use C++17 structured bindings to handle the pair.

  • [size_t consumed_chars, bool complete]
Parameters
resultthe integral reference for the result
strthe decimal string representation
radixbase of the number system, supported: 2 binary, 8 octal, 10 decimal, 16 hexadecimal
separatorseparator character (default 0, none), allowing to ignore like thousand separator characters
Returns
pair [size_t consumed_chars, bool complete], i.e. consumed characters of string and completed=false if not fully consumed.

Definition at line 603 of file string_util.hpp.

Here is the caller graph for this function:

◆ fromIntString() [2/2]

template<std::integral value_type>
SizeBoolPair jau::fromIntString ( value_type & result,
const char * str,
size_t str_len,
uint32_t radix = 10,
const char separator = 0 )
constexprnoexcept

See fromIntString.

Definition at line 675 of file string_util.hpp.

◆ appendIntString()

template<std::integral value_type>
std::string & jau::appendIntString ( std::string & dest,
value_type val,
const uint32_t radix,
const LoUpCase capitalization = LoUpCase::lower,
const PrefixOpt prefix = PrefixOpt::prefix,
const uint32_t min_width = 0,
const char separator = 0,
const char padding = '0' )
noexcept

Appends an integer string representation of an integral integer value with given radix.

[space][-][prefix][zero_padding+sep][digits+sep]

Template Parameters
value_typean integral integer type
Parameters
destthe std::string to append to
valthe unsigned integral integer value
radixbase of the number system, supported: 2 binary, 8 octal, 10 decimal, 16 hexadecimal
capitalizationLoUpCase capitalization, default is LoUpCase::lower
prefixpass PrefixOpt::prefix (default) to add leading prefix for radix. Prefixes: 0x hex, 0 octal and 0b binary.
min_widththe minimum number of characters to be printed including sign and prefix. Add padding if sign+prefix+val-digits are shorter.
separatorseparator character for each decimal 3 or other radix 4. Defaults to 0 for no separator.
paddingpadding character, defaults to '0'. Zero padding w/ '0' includes separator and comes before prefix, otherwise added to the left. See 'min_width' above.
Returns
the given string buffer for concatenation

Definition at line 697 of file string_util.hpp.

Here is the caller graph for this function:

◆ to_string() [2/9]

template<std::integral value_type>
std::string jau::to_string ( value_type v,
const uint32_t radix,
const LoUpCase capitalization = LoUpCase::lower,
const PrefixOpt prefix = PrefixOpt::prefix,
const uint32_t min_width = 0,
const char separator = 0,
const char padding = '0' )
noexcept

Produces an integer string representation of an integral integer value with given radix.

[space][-][prefix][zero_padding+sep][digits+sep]

Template Parameters
value_typean unsigned integral integer type
Parameters
vthe integral integer value
radixbase of the number system, supported: 2 binary, 8 octal, 10 decimal, 16 hexadecimal
capitalizationLoUpCase capitalization, default is LoUpCase::lower
prefixpass PrefixOpt::prefix (default) to add leading prefix for radix. Prefixes: 0x hex, 0 octal and 0b binary.
min_widththe minimum number of characters to be printed including sign and prefix. Add padding if sign+prefix+val-digits are shorter.
separatorseparator character for each decimal 3 or other radix 4. Defaults to 0 for no separator.
paddingpadding character, defaults to '0'. Zero padding w/ '0' includes separator and comes before prefix, otherwise added to the left. See 'min_width' above.
Returns
the string representation of the integral integer value with given radix

Definition at line 813 of file string_util.hpp.

◆ appendDecString()

template<class value_type, std::enable_if_t< std::is_integral_v< value_type >, bool > = true>
std::string & jau::appendDecString ( std::string & dest,
const value_type & val,
const char separator = '\'',
const uint32_t min_width = 0 )
noexcept

Appends a decimal integer string representation of an integral integer value with given radix.

[space][-][digits+sep]

Template Parameters
value_typean integral integer type
Parameters
destthe std::string to append to
valthe unsigned integral integer value
separatorseparator character for each decimal 3. Defaults to ‘’` for no separator.
min_widththe minimum number of characters to be printed including sign. Add left space if sign+val-digits are shorter.
Returns
the given string buffer for concatenation

Definition at line 838 of file string_util.hpp.

Here is the caller graph for this function:

◆ to_decstring()

template<class value_type, std::enable_if_t< std::is_integral_v< value_type >, bool > = true>
std::string jau::to_decstring ( const value_type & v,
const char separator = '\'',
const nsize_t min_width = 0 )
noexcept

Produces a decimal integer string representation of an integral integer value with given radix.

[space][-][digits+sep]

Template Parameters
value_typean integral integer type
Parameters
vthe unsigned integral integer value
separatorseparator character for each decimal 3. Defaults to ‘’` for no separator.
min_widththe minimum number of characters to be printed including sign. Add left space if sign+val-digits are shorter.
Returns
the decimal string representation of the integral integer

Definition at line 901 of file string_util.hpp.

Here is the caller graph for this function:

◆ to_string() [3/9]

template<typename CharT, std::size_t N>
std::string jau::to_string ( const CharT(&) ref[N])
constexpr

Definition at line 914 of file string_util.hpp.

◆ to_string() [4/9]

template<class value_type>
requires std::is_same_v<jau::StringLiteral<value_type::size>, value_type>
std::string jau::to_string ( const value_type & ref)
constexpr

Definition at line 920 of file string_util.hpp.

◆ to_string() [5/9]

template<class value_type, std::enable_if_t<(std::is_integral_v< value_type > &&!std::is_same_v< bool, std::remove_cv_t< value_type > >)||std::is_floating_point_v< value_type >, bool > = true>
std::string jau::to_string ( const value_type & ref)
inline

Definition at line 928 of file string_util.hpp.

◆ to_string() [6/9]

template<typename T>
std::string jau::to_string ( std::vector< T > const & list,
const std::string & delim )

Definition at line 1052 of file string_util.hpp.

◆ to_string() [7/9]

template<typename T>
std::string jau::to_string ( std::vector< T > const & list)

Definition at line 1068 of file string_util.hpp.

◆ to_string() [8/9]

template<typename T>
std::string jau::to_string ( std::vector< T > const & list,
const std::string & delim,
const nsize_t radix )

Definition at line 1071 of file string_util.hpp.

◆ to_string() [9/9]

template<typename T>
std::string jau::to_string ( std::vector< T > const & list,
const nsize_t radix )

Definition at line 1087 of file string_util.hpp.

◆ format_string_n()

std::string jau::unsafe::format_string_n ( const std::size_t maxStrLen,
const char * format,
... )
noexcept

Returns a (potentially truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument while utilizing the unsafe vsnprintf.

This variant doesn't validate format against given arguments, see jau::format_string_n.

Resulting string is truncated to min(maxStrLen, formatLen), with formatLen being the given formatted string length of output w/o limitation.

Parameters
maxStrLenmaximum resulting string length
formatprintf() compliant format string
argsoptional arguments matching the format string

Definition at line 591 of file basic_types.cpp.

◆ vformat_string_n()

std::string jau::unsafe::vformat_string_n ( const std::size_t maxStrLen,
const char * format,
va_list args )
noexcept

Definition at line 565 of file basic_types.cpp.

Here is the caller graph for this function:

◆ format_string_h()

std::string jau::unsafe::format_string_h ( const std::size_t strLenHint,
const char * format,
... )
noexcept

Returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument while utilizing the unsafe vsnprintf.

This variant doesn't validate format against given arguments, see jau::format_string_h.

Resulting string size matches formated output w/o limitation.

Parameters
strLenHintinitially used string length w/o EOS
formatprintf() compliant format string
argsoptional arguments matching the format string

Definition at line 637 of file basic_types.cpp.

◆ vformat_string_h()

std::string jau::unsafe::vformat_string_h ( const std::size_t strLenHint,
const char * format,
va_list args )
noexcept

Definition at line 599 of file basic_types.cpp.

Here is the caller graph for this function:

◆ format_string()

std::string jau::unsafe::format_string ( const char * format,
... )
noexcept

Returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument while utilizing the unsafe vsnprintf.

This variant doesn't validate format against given arguments, see jau::format_string.

Resulting string size matches formated output w/o limitation.

Parameters
formatprintf() compliant format string
argsoptional arguments matching the format string
Examples
test_stringfmt_format.cpp.

Definition at line 645 of file basic_types.cpp.

Here is the caller graph for this function:

◆ errPrint()

void jau::unsafe::errPrint ( FILE * out,
const char * msg,
bool addErrno,
bool addBacktrace,
const char * func,
const char * file,
const int line,
const char * format,
... )
noexcept

Definition at line 653 of file basic_types.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ num_max_slen

const size_t jau::cfmt::num_max_slen = 31
inlineconstexpr

Maximum net number string len w/o EOS, up to uint64_t.

Definition at line 222 of file string_cfmt.hpp.

◆ default_string_capacity

const size_t jau::cfmt::default_string_capacity = 511
inlineconstexpr

Default string reserved capacity w/o EOS (511)

Definition at line 225 of file string_cfmt.hpp.

◆ HexadecimalArrayLow

const char* jau::HexadecimalArrayLow = "0123456789abcdef"
inlineconstexpr

Definition at line 267 of file string_util.hpp.

◆ HexadecimalArrayBig

const char* jau::HexadecimalArrayBig = "0123456789ABCDEF"
inlineconstexpr

Definition at line 268 of file string_util.hpp.