qxLib
Macros | Functions
string_utils.h File Reference
#include <qx/macros/config.h>
#include <qx/typedefs.h>

Go to the source code of this file.

Macros

#define QX_TO_WSTRING(str)   _QX_TO_WSTRING(str)
 Convert char* to wchar_t*. More...
 
#define QX_STR_PREFIX(value_t, str)   qx::details::choose_str_prefix<value_t>(str, QX_TO_WSTRING(str))
 Chose witch of prefixes add to string : L or none. More...
 
#define QX_CHAR_PREFIX(value_t, ch)   qx::details::choose_char_prefix<value_t>(ch, _QX_TO_WCHAR(ch))
 Chose witch of prefixes add to char : L or none. More...
 

Functions

template<class value_t >
constexpr size_t qx::djb2a_hash (const value_t *pszStr, size_t nSeed, size_t nLen)
 djb2a hash More...
 
template<class value_t >
constexpr size_t qx::djb2a_hash (const value_t *pszStr, size_t nSeed)
 djb2a hash More...
 
template<class value_t >
constexpr size_t qx::murmur_32_hash (const value_t *pStr, size_t nSeed, size_t nLen) noexcept
 Murmur nHash. More...
 
template<class fwd_it_1_t , class fwd_it_2_t >
constexpr int qx::iter_strcmp (fwd_it_1_t itBegin1, fwd_it_1_t itEnd1, fwd_it_2_t itBegin2, fwd_it_2_t itEnd2) noexcept
 Compares string 1 with string 2. More...
 
template<class value_t >
constexpr int qx::strcmp (const value_t *pszLeft, const value_t *pszRight)
 Constexpr compare two strings. More...
 
template<class value_t , class T >
constexpr auto qx::get_format_specifier () noexcept
 Get format specifier for type. More...
 
template<class value_t >
constexpr std::size_t qx::strlen (const value_t *psz)
 Naive but constexpr string length algorithm, for runtime prefer std::strlen as there are may be a lot of optimizations. More...
 

Detailed Description

Author
Khrapov
Date
17.10.2020

Definition in file string_utils.h.

Macro Definition Documentation

◆ QX_CHAR_PREFIX

#define QX_CHAR_PREFIX (   value_t,
  ch 
)    qx::details::choose_char_prefix<value_t>(ch, _QX_TO_WCHAR(ch))

Chose witch of prefixes add to char : L or none.

Parameters
value_t- char type
ch- string to apply

Definition at line 257 of file string_utils.h.

◆ QX_STR_PREFIX

#define QX_STR_PREFIX (   value_t,
  str 
)    qx::details::choose_str_prefix<value_t>(str, QX_TO_WSTRING(str))

Chose witch of prefixes add to string : L or none.

Parameters
value_t- char type
str- string to apply

Definition at line 249 of file string_utils.h.

◆ QX_TO_WSTRING

#define QX_TO_WSTRING (   str)    _QX_TO_WSTRING(str)

Convert char* to wchar_t*.

Parameters
str- string to apply

Definition at line 241 of file string_utils.h.

Function Documentation

◆ djb2a_hash() [1/2]

template<class value_t >
constexpr size_t qx::djb2a_hash ( const value_t *  pszStr,
size_t  nSeed 
)
constexpr

djb2a hash

Template Parameters
value_t- char type
Parameters
pszStr- string for hashing (zero terminated)
nSeed- seed for hashing
Return values
-32bit unsigned value

Definition at line 44 of file string_utils.h.

◆ djb2a_hash() [2/2]

template<class value_t >
constexpr size_t qx::djb2a_hash ( const value_t *  pszStr,
size_t  nSeed,
size_t  nLen 
)
constexpr

djb2a hash

Template Parameters
value_t- char type
Parameters
pszStr- string for hashing
nSeed- seed for hashing
nLen- string length
Return values
-32bit unsigned value

Definition at line 26 of file string_utils.h.

◆ get_format_specifier()

template<class value_t , class T >
constexpr auto qx::get_format_specifier ( )
constexprnoexcept

Get format specifier for type.

Template Parameters
value_t- char type
T- target type
Return values
-format specifier or nullptr

Definition at line 283 of file string_utils.h.

◆ iter_strcmp()

template<class fwd_it_1_t , class fwd_it_2_t >
constexpr int qx::iter_strcmp ( fwd_it_1_t  itBegin1,
fwd_it_1_t  itEnd1,
fwd_it_2_t  itBegin2,
fwd_it_2_t  itEnd2 
)
constexprnoexcept

Compares string 1 with string 2.

Template Parameters
fwd_it_1_t- string 1 iterator type
fwd_it_2_t- string 2 iterator type
Parameters
itBegin1- string 1 begin iterator
itEnd1- string 1 end iterator
itBegin2- string 2 begin iterator
itEnd2- string 2 end iterator
Return values
-< 0 the first character that does not match has a lower value in str 1 than in str 2 0 the contents of both strings are equal > 0 the first character that does not match has a greater value in str 1 than in str 2

Definition at line 150 of file string_utils.h.

◆ murmur_32_hash()

template<class value_t >
constexpr size_t qx::murmur_32_hash ( const value_t *  pStr,
size_t  nSeed,
size_t  nLen 
)
constexprnoexcept

Murmur nHash.

https://en.wikipedia.org/wiki/MurmurHash https://softwareengineering.stackexchange.com/questions/49550/which-hashing-algorithm-is-best-for-uniqueness-and-speed

Template Parameters
value_t- char type
Parameters
pStr- string for hashing
nSeed- seed for hashing
nLen- string length
Return values
-32bit unsigned value

Definition at line 65 of file string_utils.h.

◆ strcmp()

template<class value_t >
constexpr int qx::strcmp ( const value_t *  pszLeft,
const value_t *  pszRight 
)
constexpr

Constexpr compare two strings.

Template Parameters
value_t- char type
Parameters
pszLeft- first string (zero terminated)
pszRight- second string (zero terminated)
Return values
-< 0 the first character that does not match has a lower value in ptr1 than in ptr2 0 the contents of both strings are equal > 0 the first character that does not match has a greater value in ptr1 than in ptr2

Definition at line 179 of file string_utils.h.

◆ strlen()

template<class value_t >
constexpr std::size_t qx::strlen ( const value_t *  psz)
constexpr

Naive but constexpr string length algorithm, for runtime prefer std::strlen as there are may be a lot of optimizations.

Template Parameters
value_t- char type
Parameters
psz- pointer to string zero terminated
Return values
-string length

Definition at line 369 of file string_utils.h.