Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Functions
String Utilities

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

Functions

std::string & jau::byteHexString (std::string &dest, const uint8_t value, const bool lowerCase) noexcept
 Produce a hexadecimal string representation of the given byte value. More...
 
template<class uint8_container_type , std::enable_if_t< std::is_integral_v< typename uint8_container_type::value_type > &&std::is_convertible_v< typename uint8_container_type::value_type, uint8_t >, bool > = true>
std::string jau::bytesHexString (const uint8_container_type &bytes, const bool lsbFirst, const bool lowerCase=true) noexcept
 
std::string jau::bytesHexString (const void *data, const nsize_t offset, const nsize_t length, const bool lsbFirst, const bool lowerCase=true) noexcept
 Produce a hexadecimal string representation of the given byte values. More...
 
std::string jau::format_string (const char *format,...) noexcept
 Returns a string according to printf() formatting rules and variable number of arguments following the format argument. More...
 
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). More...
 
size_t jau::hexStringBytes (std::vector< uint8_t > &out, const std::string &hexstr, const bool lsbFirst, const bool checkLeading0x) noexcept
 Converts a given hexadecimal string representation into a byte vector. More...
 
size_t jau::hexStringBytes (std::vector< uint8_t > &out, const uint8_t hexstr[], const size_t hexstr_len, const bool lsbFirst, const bool checkLeading0x) noexcept
 See hexStringBytes() More...
 
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 . More...
 
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. More...
 
template<class value_type , std::enable_if_t< std::is_pointer_v< value_type >, bool > = true>
std::string jau::to_hexstring (value_type const &v) noexcept
 Produce a lower-case hexadecimal string representation of the given pointer. More...
 
bool jau::to_integer (long long &result, const char *str, size_t str_len, const char limiter='\0', const char *limiter_pos=nullptr)
 
bool jau::to_integer (long long &result, const std::string &str, const char limiter='\0', const char *limiter_pos=nullptr)
 
template<class value_type , std::enable_if_t< std::is_integral_v< 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 std::string &delim)
 
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 More...
 
void jau::trimInPlace (std::string &s) noexcept
 trim in place More...
 
std::string jau::vformat_string (const char *format, va_list ap) noexcept
 Returns a string according to vprintf() formatting rules using va_list instead of a variable number of arguments. More...
 

Detailed Description

String utilities for type conversion and manipulation.

Function Documentation

◆ get_string()

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).

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 249 of file basic_types.cpp.

◆ trimInPlace()

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

trim in place

Definition at line 255 of file basic_types.cpp.

Here is the caller graph for this function:

◆ trim()

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

trim copy

Definition at line 264 of file basic_types.cpp.

◆ split_string()

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 .

Definition at line 270 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 284 of file basic_types.cpp.

Here is the caller graph for this function:

◆ toLower()

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

Definition at line 289 of file basic_types.cpp.

Here is the caller graph for this function:

◆ hexStringBytes() [1/2]

size_t jau::hexStringBytes ( std::vector< uint8_t > &  out,
const std::string &  hexstr,
const bool  lsbFirst,
const bool  checkLeading0x 
)
noexcept

Converts a given hexadecimal string representation into a byte vector.

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

Parameters
outthe byte vector sink
hexstrthe hexadecimal string representation
lsbFirstlow significant byte first
checkLeading0xif true, checks for a leading 0x and removes it, otherwise not.
Returns
the length of the matching byte vector
Examples
test_basictypeconv.cpp.

Definition at line 414 of file basic_types.cpp.

Here is the caller graph for this function:

◆ hexStringBytes() [2/2]

size_t jau::hexStringBytes ( std::vector< uint8_t > &  out,
const uint8_t  hexstr[],
const size_t  hexstr_len,
const bool  lsbFirst,
const bool  checkLeading0x 
)
noexcept

See hexStringBytes()

Definition at line 417 of file basic_types.cpp.

◆ bytesHexString() [1/2]

std::string jau::bytesHexString ( const void *  data,
const nsize_t  offset,
const nsize_t  length,
const bool  lsbFirst,
const bool  lowerCase = true 
)
noexcept

Produce a hexadecimal string representation of the given byte values.

If lsbFirst is true, orders LSB left -> MSB right, usual for byte streams. Result will not have a leading 0x.
Otherwise orders MSB left -> LSB right, usual for readable integer values. Result will have a leading 0x.

Parameters
datapointer to the first byte to print, less offset
offsetoffset to bytes pointer to the first byte to print
lengthnumber of bytes to print
lsbFirsttrue having the least significant byte printed first (lowest addressed byte to highest), otherwise have the most significant byte printed first (highest addressed byte to lowest). A leading 0x will be prepended if lsbFirst == false.
lowerCasetrue to use lower case hex-chars, otherwise capital letters are being used.
Returns
the hex-string representation of the data
Examples
test_basictypeconv.cpp.

Definition at line 466 of file basic_types.cpp.

Here is the caller graph for this function:

◆ bytesHexString() [2/2]

template<class uint8_container_type , std::enable_if_t< std::is_integral_v< typename uint8_container_type::value_type > &&std::is_convertible_v< typename uint8_container_type::value_type, uint8_t >, bool > = true>
std::string jau::bytesHexString ( const uint8_container_type &  bytes,
const bool  lsbFirst,
const bool  lowerCase = true 
)
noexcept

Definition at line 121 of file string_util.hpp.

◆ byteHexString()

std::string & jau::byteHexString ( std::string &  dest,
const uint8_t  value,
const bool  lowerCase 
)
noexcept

Produce a hexadecimal string representation of the given byte value.

Parameters
destthe std::string reference destination to append
valuethe byte value to represent
lowerCasetrue to use lower case hex-chars, otherwise capital letters are being used.
Returns
the given std::string reference for chaining

Definition at line 503 of file basic_types.cpp.

Here is the caller graph for this function:

◆ to_hexstring()

template<class value_type , std::enable_if_t< std::is_pointer_v< value_type >, bool > = true>
std::string jau::to_hexstring ( value_type const &  v)
inlinenoexcept

Produce a lower-case hexadecimal string representation of the given pointer.

Produce a lower-case hexadecimal string representation of the given value with standard layout.

Template Parameters
value_typea pointer type
Parameters
vthe pointer of given pointer type
Returns
the hex-string representation of the value
See also
bytesHexString()
Template Parameters
value_typea standard layout value type
Parameters
vthe value of given standard layout type
Returns
the hex-string representation of the value
See also
bytesHexString()
Examples
dbt_peripheral00.cpp, dbt_repeater00.cpp, dbt_scanner10.cpp, and test_basictypeconv.cpp.

Definition at line 145 of file string_util.hpp.

◆ 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  width = 0 
)
noexcept

Produce a decimal string representation of an integral integer value.

Template Parameters
Tan integral integer type
Parameters
vthe integral integer value
separatorif not 0, use as separation character, otherwise no separation characters are being used
widththe minimum number of characters to be printed. Add padding with blank space if result is shorter.
Returns
the string representation of the integral integer value
Examples
dbt_peripheral00.cpp, test_cow_darray_perf01.cpp, test_cow_iterator_01.cpp, and test_intdecstring01.cpp.

Definition at line 184 of file string_util.hpp.

Here is the caller graph for this function:

◆ vformat_string()

std::string jau::vformat_string ( const char *  format,
va_list  ap 
)
noexcept

Returns a string according to vprintf() formatting rules using va_list instead of a variable number of arguments.

Parameters
formatprintf() compliant format string
apva_list arguments

Definition at line 367 of file basic_types.cpp.

Here is the caller graph for this function:

◆ format_string()

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

Returns a string according to printf() formatting rules and variable number of arguments following the format argument.

Parameters
formatprintf() compliant format string

Definition at line 392 of file basic_types.cpp.

Here is the caller graph for this function:

◆ to_string() [1/3]

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

Definition at line 242 of file string_util.hpp.

◆ to_string() [2/3]

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

Definition at line 333 of file string_util.hpp.

◆ to_string() [3/3]

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

Definition at line 350 of file string_util.hpp.

Here is the caller graph for this function:

◆ to_integer() [1/2]

bool jau::to_integer ( long long &  result,
const std::string &  str,
const char  limiter = '\0',
const char *  limiter_pos = nullptr 
)

Definition at line 587 of file basic_types.cpp.

Here is the caller graph for this function:

◆ to_integer() [2/2]

bool jau::to_integer ( long long &  result,
const char *  str,
size_t  str_len,
const char  limiter = '\0',
const char *  limiter_pos = nullptr 
)

Definition at line 549 of file basic_types.cpp.