jaulib v1.4.0-2-g788cf73
Jau Support Library (C++, Java, ..)
Loading...
Searching...
No Matches
string_util.hpp File Reference
#include <algorithm>
#include <concepts>
#include <cstdarg>
#include <cstdint>
#include <cstring>
#include <string>
#include <string_view>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "jau/basic_types.hpp"
#include "jau/type_info.hpp"
#include <jau/byte_util.hpp>
#include <jau/cpp_lang_util.hpp>
#include <jau/int_math.hpp>
#include <jau/int_types.hpp>
#include <jau/packed_attribute.hpp>
#include <jau/string_cfmt.hpp>
#include <jau/type_traits_queries.hpp>
#include <jau/type_concepts.hpp>
Include dependency graph for string_util.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  jau::string_hash
 C++20: Heterogeneous Lookup in (Un)ordered Containers. More...
 

Namespaces

namespace  jau
 __pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
 
namespace  jau::impl
 

Macros

#define jau_format_string_static(...)
 

Typedefs

template<typename T>
using jau::StringHashMap = std::unordered_map<std::string, T, string_hash, std::equal_to<>>
 
using jau::StringHashSet = std::unordered_set<std::string, string_hash, std::equal_to<>>
 

Enumerations

enum class  jau::LoUpCase : bool { jau::LoUpCase::lower = false , jau::LoUpCase::upper = true }
 
enum class  jau::PrefixOpt : bool { jau::PrefixOpt::none = false , jau::PrefixOpt::prefix = true }
 

Functions

std::string & jau::appendToHexString (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.
 
template<StringLiteral format, typename... Args>
consteval_cxx20 std::string jau::format_string (const Args &...args)
 Safely returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument.
 
template<typename... Args>
constexpr std::string jau::format_string (const std::string_view format, const Args &...args)
 Safely returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument.
 
template<typename... Args>
constexpr std::string jau::format_string_h (const std::size_t strLenHint, const std::string_view format, const Args &...args)
 Safely returns a (non-truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument.
 
template<typename... Args>
constexpr std::string jau::impl::format_string_h (const std::size_t strLenHint, const std::string_view format, const Args &...args)
 
template<StringLiteral format, typename... Args>
consteval_cxx20 std::string jau::format_string_n (const std::size_t maxStrLen, const Args &...args)
 Safely returns a (potentially truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument.
 
template<typename... Args>
constexpr std::string jau::format_string_n (const std::size_t maxStrLen, const std::string_view &format, const Args &...args)
 Safely returns a (potentially truncated) string according to snprintf() formatting rules and variable number of arguments following the format argument.
 
template<typename... Args>
constexpr std::string jau::impl::format_string_n (const std::size_t maxStrLen, const std::string_view &format, const Args &...args)
 
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) noexcept
 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) noexcept
 Converts a given binary string representation into a byte vector, 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 into 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) noexcept
 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) noexcept
 Converts a given hexadecimal string representation into a byte vector, lsb-first.
 
std::string jau::get_string (const uint8_t *buffer, nsize_t const buffer_len, nsize_t const max_len) noexcept
 Returns a C++ String taken from buffer with maximum length of min(max_len, max_len).
 
bool jau::is_ascii_code (int c) noexcept
 
std::vector< std::string > jau::split_string (const std::string &str, const std::string &separator) noexcept
 Split given string str at separator into the resulting std::vector excluding the separator sequence .
 
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 width=0) noexcept
 Produce a decimal string representation of an integral integer value.
 
Int64SizeBoolTuple jau::to_integer (const char *str, size_t str_len, const nsize_t radix=10, const char limiter='\0', const char *limiter_pos=nullptr)
 Returns tuple [int64_t result, size_t consumed_chars, bool complete] of string to integer conversion via std::strtoll.
 
Int64SizeBoolTuple jau::to_integer (const std::string_view str, const nsize_t radix=10, const char limiter='\0', const char *limiter_pos=nullptr)
 Returns tuple [int64_t result, size_t consumed_chars, bool complete] of string to integer conversion via std::strtoll.
 
template<class value_type, std::enable_if_t<(std::is_integral_v< value_type > &&!std::is_same_v< bool, 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<class value_type, std::enable_if_t< std::is_integral_v< value_type > &&std::is_unsigned_v< value_type >, bool > = true>
std::string jau::to_string (value_type v, const nsize_t radix, const PrefixOpt prefix=PrefixOpt::prefix, size_t min_width=0, const char separator=0, const char padding='0') noexcept
 Produce a string representation of an unsigned 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.
 
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::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 value with standard layout.
 
std::string jau::toLower (const std::string &s) noexcept
 
std::string & jau::toLowerInPlace (std::string &s) noexcept
 
std::string jau::trim (const std::string &s) noexcept
 trim copy
 
void jau::trimInPlace (std::string &s) noexcept
 trim in place
 

Variables

constexpr const char * jau::HexadecimalArray = "0123456789abcdef"
 

Macro Definition Documentation

◆ jau_format_string_static

#define jau_format_string_static ( ...)
Value:
jau::format_string(__VA_ARGS__); \
static_assert(0 <= jau::cfmt::checkR(__VA_ARGS__).argCount());
constexpr std::string format_string(const std::string_view format, const Args &...args)
Safely returns a (non-truncated) string according to snprintf() formatting rules and variable number ...
constexpr PResult checkR(const std::string_view fmt, const Targs &...) noexcept
Strict type validation of arguments against the format string.

Definition at line 875 of file string_util.hpp.