chsvlib
chsv helper source code
chsvstringex.h File Reference

High-level mechanisms, dependent upon chsvmem.h, used to manage strings, convert them to different encoding schemes and to manage associated memory. More...

#include "chsvstring.h"
#include "chsvmemex.h"
#include <array>

Classes

class  u8_ch_data
 Holds attributes, including Unicode code point, of a one multi-byte UTF-8 character with the read_u8_char_data function. More...
 
struct  u8_array_from_ucp< ucp >
 A class template which for a given Unicode code point statically defines a constant array holding the corresponding UTF-8 code. More...
 
struct  ucp_literal_type< N >
 Implements a string literal of Unicode 11.0 code points. More...
 
struct  from_chars_result< CharType >
 A type of the return value of the from_chars family of functions. More...
 

Namespaces

 Chusov
 Basic chsvlib namespace.
 
 Chusov::String
 A namespace of string manipulation functions and classes.
 

Macros

#define UCP_LITERAL(str)   unspecified
 Resolves to a constexpr zero-terminated array of ucp_t elements given a classic char-based C string literal. More...
 

Typedefs

typedef std::basic_string< char, std::char_traits< char >, ::Chusov::Memory::allocator< char > > string
 An instantiation of the standard basic_string class template for handling multi-byte strings allocated and freed by functions that facilitate the Chusov::Memory::AllocateData and Chusov::Memory::FreeData functions, e.g. AllocateStringA or FreeStringA.
 
typedef std::basic_string< wchar_t, std::char_traits< wchar_t >, ::Chusov::Memory::allocator< wchar_t > > wstring
 An instantiation of the standard basic_string class template for handling wide strings allocated and freed by functions that facilitate the Chusov::Memory::AllocateData and Chusov::Memory::FreeData functions, e.g. AllocateStringW or FreeStringW.
 
typedef std::basic_string< char, std::char_traits< char >, ::Chusov::Memory::secure_allocator< char > > string_s
 An instantiation of the standard basic_string class template for handling multi-byte strings allocated and securely freed by AllocateStringA and SecureFreeStringA.
 
typedef std::basic_string< wchar_t, std::char_traits< wchar_t >, ::Chusov::Memory::secure_allocator< wchar_t > > wstring_s
 An instantiation of the standard basic_string class template for handling wide strings allocated and securely freed by AllocateStringW and SecureFreeStringW.
 
typedef std::basic_string< char, ci_char_traits< char > > ci_string
 A typedef for case-independent variant of std::basic_string specialized for multibyte characters. More...
 
typedef std::basic_string< wchar_t, ci_char_traits< wchar_t > > ci_wstring
 A typedef for case-independent wide variant of std::basic_string specialized for wide characters. More...
 
typedef std::basic_string_view< char, ci_char_traits< char > > ci_string_view
 A typedef for a case-independent variant of std::basic_string_view specialized for multibyte characters. More...
 
typedef std::basic_string_view< wchar_t, ci_char_traits< wchar_t > > ci_wstring_view
 A typedef for a case-independent variant of std::basic_string_view specialized for wide characters. More...
 
typedef std::basic_string< ucp_t, std::char_traits< ucp_t >, std::allocator< ucp_t > > ucp_string
 Implements a C++ string object with characters of type ucp_t encoding Unicode 11.0 code points. More...
 
typedef std::basic_string< ucp_t, ci_char_traits< ucp_t > > ci_ucp_string
 Implements a C++ case-independent string object with characters of type ucp_t encoding Unicode 11.0 code points. More...
 
typedef std::basic_string_view< ucp_t, std::char_traits< ucp_t > > ucp_string_view
 Implements a C++ string view object with characters of type ucp_t encoding Unicode 11.0 code points. More...
 
typedef std::basic_string_view< ucp_t, ci_char_traits< ucp_t > > ci_ucp_string_view
 Implements a case-independent C++ string view object with characters of type ucp_t encoding Unicode 11.0 code points. More...
 

Functions

ci_string operator""_cis (const char *str, std::size_t count)
 Returns a case-independent string constructed from a C-string literal. More...
 
constexpr ci_string_view operator""_cisv (const char *str, std::size_t count)
 Returns a case-independent string view object constructed from a C-string literal. More...
 
template<class T >
from_string (const char *pszValue)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. . More...
 
template<class T >
from_string (const wchar_t *pszValue)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. . More...
 
template<class T >
from_string (const char *pszValue, int base=10)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. This template is available (i.e. participates in overload resolution) when the type is integral. . More...
 
template<class T >
from_string (const wchar_t *pszValue, int base=10)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. This template is available (i.e. participates in overload resolution) when the type is integral. . More...
 
constexpr bool u8_check (const char *pStr, std::size_t cbStr) noexcept
 Verifies the validity of a UTF-8 code and its byte size. More...
 
constexpr bool ucp_check (ucp_t ucp) noexcept
 Verifies the validity of a Unicode 11.0 code point. More...
 
template<bool throw_on_failure = true, class InputIteratorBegin , class InputIteratorEnd >
constexpr u8_ch_data read_u8_char_data (InputIteratorBegin begin, InputIteratorEnd end)
 Reads a UTF-8 character addressed by a pair of input iterators and returns a u8_ch_data object with information about it. . More...
 
template<bool throw_on_failure = true, class InputIterator >
CONSTEXPR_CPP14 u8_ch_data read_u8_char_data (InputIterator itSymbol, std::size_t cbSymbol=UTF8_MAX_LEN)
 Reads a UTF-8 character addressed by an input iterator and returns a u8_ch_data object with information about it. . More...
 
template<bool throw_on_failure = true, std::size_t N>
constexpr u8_ch_data read_u8_char_data (const char(&pSymbol)[N]) noexcept(!throw_on_failure)
 Reads a UTF-8 character specified by an array of byte characters and constructs a u8_ch_data object with information about it. More...
 
template<bool throw_on_failure = true, class InputIteratorBegin , class InputIteratorEnd >
constexpr std::pair< u8_ch_data, InputIterator > read_u8_char_data_and_advance (InputIteratorBegin begin, InputIteratorEnd end)
 Reads a UTF-8 character addressed by a pair of input iterators, advances the first one and returns a pair of a u8_ch_data object with information about the character together with the copy of the iterator advances as a result of the reading. . More...
 
template<bool throw_on_failure = true, class InputIterator >
constexpr std::pair< u8_ch_data, InputIterator > read_u8_char_data_and_advance (InputIterator itSymbol, std::size_t cbSymbol=UTF8_MAX_LEN)
 Reads a UTF-8 character addressed by an input iterator, advances it and returns a pair of a u8_ch_data object with information about the character together with the copy of the iterator after the reading. . More...
 
template<bool do_full_checks = true, bool throw_on_failure = true, class InputIterator >
constexpr std::size_t u8blen (InputIterator itSymbol, std::size_t cbSymbol=UTF8_MAX_LEN) noexcept(!throw_on_failure)
 Returns a byte length of a UTF-8 character addressed by an iterator. More...
 
template<bool do_full_checks = true, bool throw_on_failure = true, std::size_t N>
constexpr std::size_t u8blen (const char(&pSymbol)[N]) noexcept(!throw_on_failure)
 Returns a byte size of a UTF-8 character in the specified array of bytes. More...
 
template<bool do_full_checks = true, bool throw_on_failure = true>
constexpr std::size_t u8blen (ucp_t ucp) noexcept(!throw_on_failure)
 Returns the byte size of a UTF-8 representation of a given Unicode code point. More...
 
template<bool do_full_checks = true, bool throw_on_failure = true, class InputIterator >
constexpr ucp_t u8_to_ucp (InputIterator itSymbol, std::size_t cbSymbol=UTF8_MAX_LEN) noexcept(!throw_on_failure)
 Converts a UTF-8 code referenced by an iterator to a Unicode 11.0 code point. More...
 
template<bool do_full_checks = true, bool throw_on_failure = true, std::size_t N>
constexpr ucp_t u8_to_ucp (const char(&pSymbol)[N]) noexcept(!throw_on_failure)
 Converts a UTF-8 code read from an array of bytes to a Unicode 11.0 code point. More...
 
template<bool do_full_checks = true, bool throw_on_failure = true, class InputIterator >
constexpr std::pair< ucp_t, InputIterator > u8_to_ucp_advance (InputIterator itSymbol, std::size_t cbSymbol=UTF8_MAX_LEN) noexcept(!throw_on_failure)
 Converts a UTF-8 code referenced by an iterator to a Unicode 11.0 code point and returns it together with a copy of the iterator in the state immediately following the acquisition of the UTF-8 code. More...
 
template<bool do_full_checks = true, bool throw_on_failure = true, class OutputIterator >
constexpr OutputIterator ucp_to_u8 (OutputIterator it, ucp_t ucp) noexcept(!throw_on_failure)
 Converts a given Unicode 11.0 code point to a sequence of bytes representing the corresponding UTF-8 multi-byte character and writes the bytes to a given output iterator. More...
 
template<class CharTraits = std::char_traits<ucp_t>, class Allocator = std::allocator<ucp_t>, class InputIterator >
std::basic_string< ucp_t, CharTraits, Allocator > u8_decode_string (InputIterator it, std::size_t cbAvail)
 Produces a C++ string of Unicode 11.0 code points from bytes of UTF-8 encoded characters. More...
 
template<class CharTraits = std::char_traits<ucp_t>, class Allocator = std::allocator<ucp_t>, class CPtr >
std::basic_string< ucp_t, CharTraits, Allocator > u8_decode_string (CPtr &&pszUtf8)
 Produces a C++ string of Unicode 11.0 code points from bytes of a UTF-8 encoded zero-terminated string. More...
 
template<class CharTraits = std::char_traits<ucp_t>, class Allocator = std::allocator<ucp_t>, std::size_t N>
std::basic_string< ucp_t, CharTraits, Allocator > u8_decode_string (const char(&pUtf8)[N])
 Produces a C++ string of Unicode 11.0 code points from an array of bytes encoding a UTF-8 string. . More...
 
template<class CharTraitsTo = std::char_traits<ucp_t>, class AllocatorTo = std::allocator<ucp_t>, class Container >
std::basic_string< ucp_t, CharTraitsTo, AllocatorTo > u8_decode_string (const Container &str)
 Produces a C++ string of Unicode 11.0 code points from bytes of a C++ container with a UTF-8 encoded string. . More...
 
template<class CharTraitsTo , class AllocatorTo , class BasicStringType >
std::basic_string< ucp_t, CharTraitsTo, AllocatorTo > u8_decode_string (const BasicStringType &str)
 Produces a C++ string of Unicode 11.0 code points from a C++ UTF-8 encoded string with custom char-traits and allocator classes. . More...
 
template<class CharTraitsTo , class BasicStringType >
std::basic_string< ucp_t, CharTraitsTo, ReboundAllocator > u8_decode_string (const BasicStringType &str)
 Produces a C++ string of Unicode 11.0 code points from a C++ UTF-8 encoded string with a custom char-traits class. . More...
 
template<class AllocatorTo , class BasicStringType >
std::basic_string< ucp_t, ReboundCharTraits, AllocatorTo > u8_decode_string (const BasicStringType &str)
 Produces a C++ string of Unicode 11.0 code points from a C++ UTF-8 encoded string with a custom type of allocator. . More...
 
template<class BasicStringType >
std::basic_string< ucp_t, ReboundCharTraits, ReboundAllocator > u8_decode_string (const BasicStringType &str)
 Produces a C++ string of Unicode 11.0 code points from a C++ UTF-8 encoded string. . More...
 
template<class CharTraits = std::char_traits<char>, class Allocator = std::allocator<char>, class InputIterator >
std::basic_string< char, CharTraits, Allocator > u8_encode_string (InputIterator it, std::size_t count)
 Converts a given string of Unicode code points to its UTF-8 representation and returns the latter as a C++ string object. More...
 
template<class CharTraits = std::char_traits<char>, class Allocator = std::allocator<char>, class CPtr >
std::basic_string< char, CharTraits, Allocator > u8_encode_string (CPtr &&pszUcp)
 Converts a given zero-terminated string of Unicode code points to its UTF-8 representation and returns the latter as a C++ string object. More...
 
template<class CharTraits = std::char_traits<char>, class Allocator = std::allocator<char>, std::size_t N>
std::basic_string< char, CharTraits, Allocator > u8_encode_string (const ucp_t(&pUcp)[N])
 Converts a given array with a string of Unicode code points to the corresponding UTF-8 representation and returns the latter as a C++ string object. . More...
 
template<class CharTraitsTo = std::char_traits<char>, class AllocatorTo = std::allocator<char>, class Container >
std::basic_string< char, CharTraitsTo, AllocatorTo > u8_encode_string (const Container &str)
 Converts a given container with a sequence of Unicode code points to the corresponding UTF-8 representation and returns the latter as a C++ string object. . More...
 
template<class CharTraitsTo , class AllocatorTo , class BasicStringType >
std::basic_string< char, CharTraitsTo, AllocatorTo > u8_encode_string (const BasicStringType &str)
 Converts a given C++ string of Unicode code points to the corresponding UTF-8 representation as another C++ string object with custom char-traits policy and an allocator. . More...
 
template<class CharTraitsTo , class BasicStringType >
std::basic_string< char, CharTraitsTo, ReboundAllocator > u8_encode_string (const BasicStringType &str)
 Converts a given C++ string of Unicode code points to the corresponding UTF-8 representation as another C++ string object with a custom char-traits policy. . More...
 
template<class AllocatorTo , class BasicStringType >
std::basic_string< char, ReboundCharTraits, AllocatorTo > u8_encode_string (const BasicStringType &str)
 Converts a given C++ string of Unicode code points to the corresponding UTF-8 representation as another C++ string object with a custom allocator. . More...
 
template<class BasicStringType >
std::basic_string< char, ReboundCharTraits, ReboundAllocator > u8_encode_string (const BasicStringType &str)
 Converts a given C++ string of Unicode code points to the corresponding UTF-8 representation. . More...
 
ucp_string to_ucp_string (int value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
ucp_string to_ucp_string (long value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
ucp_string to_ucp_string (long long value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
ucp_string to_ucp_string (unsigned value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
ucp_string to_ucp_string (unsigned long value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
ucp_string to_ucp_string (unsigned long long value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
ucp_string to_ucp_string (double value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
ucp_string to_ucp_string (long double value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
ucp_string to_ucp_string (float value)
 Converts the specified numerical value to a Unicode string of the ucp_string type. More...
 
int stoi (const ucp_string &str, std::size_t *restrict pos=nullptr, int base=10)
 Converts a UCP string to int. More...
 
long stol (const ucp_string &str, std::size_t *restrict pos=nullptr, int base=10)
 Converts a UCP string to long. More...
 
long long stoll (const ucp_string &str, std::size_t *restrict pos=nullptr, int base=10)
 Converts a UCP string to long long. More...
 
unsigned long stoul (const ucp_string &str, std::size_t *restrict pos=nullptr, int base=10)
 Converts a UCP string to unsigned long. More...
 
unsigned long long stoull (const ucp_string &str, std::size_t *restrict pos=nullptr, int base=10)
 Converts a UCP string to unsigned long long. More...
 
template<class T >
from_string (const ucp_t *pszValue)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. More...
 
template<class T >
from_string (const ucp_t *pszValue, int base=10)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. This template is available (i.e. participates in overload resolution) when the type is integral. More...
 
template<class T , class CharT , class TraitsT , class AllocT >
from_string (const std::basic_string< CharT, TraitsT, AllocT > &strValue)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. . More...
 
template<class T , class CharT , class TraitsT , class AllocT >
from_string (std::basic_string< CharT, TraitsT, AllocT > &&strValue)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. . More...
 
template<class T , class CharT , class TraitsT , class AllocT >
from_string (const std::basic_string< CharT, TraitsT, AllocT > &strValue, int base=10)
 A set of templates providing an interface to convert an argument specifying a C or C++ string to a value of a specified type. This template is available (i.e. participates in overload resolution) when the type is integral. . More...
 

from_chars

A set of overloads and ancilliary components which implement C++17 std::from_chars using C++14 means.

enum class  chars_format { scientific = 1 , fixed = 2 , general , hex }
 An enumeration used to specify fromatting of the from_chars floating-point conversion function. More...
 
template<class CharType , class IntegralType >
from_chars_result< CharType > from_chars (const CharType *first, const CharType *last, IntegralType &value, int base=10) noexcept
 Converts a string representation of an integral value to the specified integral representation. More...
 
template<class CharType , class FloatingPointType >
from_chars_result< CharType > from_chars (const CharType *first, const CharType *last, FloatingPointType &value, chars_format fmt=chars_format::general) noexcept
 Converts a string representation of a floating-point value to the specified numeric representation. . More...
 

Detailed Description

High-level mechanisms, dependent upon chsvmem.h, used to manage strings, convert them to different encoding schemes and to manage associated memory.