jaulib v1.4.1-17-gd77ace3-dirty
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 <limits>
#include <string>
#include <string_view>
#include <type_traits>
#include <vector>
#include "jau/type_info.hpp"
#include <jau/byte_util.hpp>
#include <jau/cpp_lang_util.hpp>
#include <jau/packed_attribute.hpp>
#include <jau/int_math.hpp>
#include <jau/int_types.hpp>
#include <jau/string_literal.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.

Namespaces

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

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

template<std::integral value_type>
std::string & jau::append_string (std::string &dest, value_type val, const nsize_t radix, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix, const nsize_t min_width=0, const char separator=0, const char padding='0') noexcept
 Appends a string representation of an integral integer value with given radix.
 
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.
 
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
 
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<class value_type>
requires jau::req::signed_integral<value_type>
constexpr bool jau::from_chars (value_type &result, std::string_view str) noexcept
 
template<class value_type>
requires jau::req::unsigned_integral<value_type>
constexpr bool jau::from_chars (value_type &result, std::string_view str) noexcept
 
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
 
constexpr bool jau::is_digit (char 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) noexcept
 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) noexcept
 Returns tuple [int64_t result, size_t consumed_chars, bool complete] of string to integer conversion via std::strtoll.
 
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 nsize_t radix, const LoUpCase capitalization=LoUpCase::lower, const PrefixOpt prefix=PrefixOpt::prefix, const nsize_t min_width=0, const char separator=0, const char padding='0') noexcept
 Produce a 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.
 
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
 
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 char * jau::HexadecimalArrayBig = "0123456789ABCDEF"
 
constexpr const char * jau::HexadecimalArrayLow = "0123456789abcdef"