simstr 1.2.4
Yet another strings library
 
Loading...
Searching...
No Matches
simstr::str_storable< K, Impl, Allocator > Class Template Reference

The base for the objects that own the string. More...

#include <sstring.h>

Inheritance diagram for simstr::str_storable< K, Impl, Allocator >:
simstr::lstring< K, N, forShared, Allocator > simstr::lstring< u8s, N > simstr::lstring< wchar_t, N > simstr::lstring< u16s, N > simstr::lstring< u32s, N > simstr::lstring< u8s, N, true > simstr::lstring< wchar_t, N, true > simstr::lstring< u16s, N, true > simstr::lstring< u32s, N, true > simstr::sstring< K, Allocator > simstr::sstring< u8s > simstr::sstring< wchar_t > simstr::sstring< u16s > simstr::sstring< u32s >

Public Member Functions

template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
constexpr str_storable (Args &&... args) noexcept(std::is_nothrow_constructible_v< allocator_t, Args... >)
 Create an empty object.
 
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
constexpr str_storable (s_str other, Args &&... args)
 A constructor from another string object.
 
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
constexpr str_storable (size_t repeat, s_str pattern, Args &&... args)
 String repetition constructor.
 
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
 str_storable (size_t count, K pad, Args &&... args)
 Character repetition constructor.
 
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
constexpr str_storable (const StrExprForType< K > auto &expr, Args &&... args)
 Constructor from a string expression.
 
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
 str_storable (const From &f, s_str pattern, s_str repl, size_t offset=0, size_t maxCount=0, Args &&... args)
 Constructor from string source with replacement.
 
 operator const K * () const noexcept
 Conversion operator to a null-terminated C string.
 
s_str_nt to_nts (size_t from=0) const
 Get simple_str_nt starting at the given character.
 
 operator s_str_nt () const
 Convert to simple_str_nt.
 

Static Public Member Functions

template<typename T, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type join (const T &strings, s_str delimeter, bool tail=false, bool skip_empty=false, Args &&... args)
 Concatenate strings from the container into one string.
 
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type uppered_only_ascii_from (const From &f, Args &&... args)
 Create a string copy of the passed in uppercase ASCII characters.
 
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type lowered_only_ascii_from (const From &f, Args &&... args)
 Create a copy of the passed string in lowercase ASCII characters.
 
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type uppered_from (const From &f, Args &&... args)
 Create a copy of the passed string in uppercase Unicode characters of the first plane (<0xFFFF).
 
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type lowered_from (const From &f, Args &&... args)
 Create a copy of the passed string in lowercase Unicode characters of the first plane (<0xFFFF).
 
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type replaced_from (const From &f, s_str pattern, s_str repl, size_t offset=0, size_t maxCount=0, Args &&... args)
 Create a copy of the passed string with substrings replaced.
 

Protected Member Functions

allocator_t & allocator ()
 Get the allocator.
 

Detailed Description

template<typename K, typename Impl, typename Allocator>
class simstr::str_storable< K, Impl, Allocator >

The base for the objects that own the string.

Template Parameters
K- character type.
Impl- the final class is the successor.
Allocator- type of allocator.

Still knows nothing about where the heir stores the string and its size. Simply calls its methods to get the space, and fills it as needed. Works only when creating an object, does not work with string modification after its creation and ensures that if these methods are called, the object is only is being created and no data sharing has yet taken place.

These methods must be implemented by the descendant class and are called only when an object is created

  • K* init(size_t size) - allocate space for a line of the specified size, return the address
  • void create_empty() - create an empty object
  • K* set_size(size_t size) - re-allocate space for the line if you didn’t guess correctly when creating the size you need and the space you need is larger or smaller. The contents of the line must be left. Although the allocator type is specified by the template parameter, this is done only for forwarding of its type in constructors, allocator methods are not called. If the heir does not use an allocator, and in init and set_size it somehow allocates space, can indicate the type of the allocator any empty class.

Constructor & Destructor Documentation

◆ str_storable() [1/6]

template<typename K, typename Impl, typename Allocator>
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
simstr::str_storable< K, Impl, Allocator >::str_storable ( Args &&... args)
inlineconstexprnoexcept

Create an empty object.

Parameters
...args- parameters for initializing the allocator.

◆ str_storable() [2/6]

template<typename K, typename Impl, typename Allocator>
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
simstr::str_storable< K, Impl, Allocator >::str_storable ( s_str other,
Args &&... args )
inlineconstexpr

A constructor from another string object.

Parameters
other- another string object, simple_str.
...args- parameters for initializing the allocator.

◆ str_storable() [3/6]

template<typename K, typename Impl, typename Allocator>
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
simstr::str_storable< K, Impl, Allocator >::str_storable ( size_t repeat,
s_str pattern,
Args &&... args )
inlineconstexpr

String repetition constructor.

Parameters
repeat- number of repetitions.
pattern- the line to be repeated.
...args- parameters for initializing the allocator.

◆ str_storable() [4/6]

template<typename K, typename Impl, typename Allocator>
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
simstr::str_storable< K, Impl, Allocator >::str_storable ( size_t count,
K pad,
Args &&... args )
inline

Character repetition constructor.

Parameters
count- number of repetitions.
pad- the character to be repeated.
...args- parameters for initializing the allocator.

◆ str_storable() [5/6]

template<typename K, typename Impl, typename Allocator>
template<typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
simstr::str_storable< K, Impl, Allocator >::str_storable ( const StrExprForType< K > auto & expr,
Args &&... args )
inlineconstexpr

Constructor from a string expression.

Parameters
expr- string expression.
...args- parameters for initializing the allocator.

The constructor queries the string expression length(), allocates memory of the required size, and calls the place() method to allocate result in buffer.

◆ str_storable() [6/6]

template<typename K, typename Impl, typename Allocator>
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
simstr::str_storable< K, Impl, Allocator >::str_storable ( const From & f,
s_str pattern,
s_str repl,
size_t offset = 0,
size_t maxCount = 0,
Args &&... args )
inline

Constructor from string source with replacement.

Parameters
f- the string object from which the source string is taken.
pattern- substring to be replaced.
repl- the string to be replaced with.
offset- starting position for searching substrings.
maxCount- maximum number of replacements, 0 - no restrictions.
...args- parameters for initializing the allocator.

Member Function Documentation

◆ join()

template<typename K, typename Impl, typename Allocator>
template<typename T, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type simstr::str_storable< K, Impl, Allocator >::join ( const T & strings,
s_str delimeter,
bool tail = false,
bool skip_empty = false,
Args &&... args )
inlinestatic

Concatenate strings from the container into one string.

Parameters
strings- container with strings.
delimeter- delimiter added between lines.
tail- add a separator after the last line.
skip_empty- skip empty lines without adding a separator.
...args- parameters for initializing the allocator.

The function is used to merge a container of strings into one delimited string.

std::vector<ssa> strings = get_strings();
ssa delim = get_current_delimeter();
auto line = lstringa<200>::join(strings, delimeter);
static my_type join(const T &strings, s_str delimeter, bool tail=false, bool skip_empty=false, Args &&... args)
Definition sstring.h:3180

It is worth noting that if the separator is known in advance, it is better to use the string expression e_join.

std::vector<ssa> strings = get_strings();
lstringa<200> line{e_join(strings, "/")};
constexpr auto e_join(const T &s, L &&d)
Get a string expression concatenating the strings in the container into a single string with the give...
Definition sstring.h:5867

In this case, the compiler can better optimize the string merging code.

◆ lowered_from()

template<typename K, typename Impl, typename Allocator>
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type simstr::str_storable< K, Impl, Allocator >::lowered_from ( const From & f,
Args &&... args )
inlinestatic

Create a copy of the passed string in lowercase Unicode characters of the first plane (<0xFFFF).

Parameters
f- source string.
...args- parameters for initializing the allocator.

Case is changed by simplified tables, where one code_point is always changed to one code_point (but for UTF-8 it is possible that the length in code units will change).

◆ lowered_only_ascii_from()

template<typename K, typename Impl, typename Allocator>
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type simstr::str_storable< K, Impl, Allocator >::lowered_only_ascii_from ( const From & f,
Args &&... args )
inlinestatic

Create a copy of the passed string in lowercase ASCII characters.

Parameters
f- source string.
...args- parameters for initializing the allocator.

◆ operator const K *()

template<typename K, typename Impl, typename Allocator>
simstr::str_storable< K, Impl, Allocator >::operator const K * ( ) const
inlinenoexcept

Conversion operator to a null-terminated C string.

Returns
const K* - pointer to the beginning of the line.

◆ operator s_str_nt()

template<typename K, typename Impl, typename Allocator>
simstr::str_storable< K, Impl, Allocator >::operator s_str_nt ( ) const
inline

Convert to simple_str_nt.

Returns
simple_str_nt.

◆ replaced_from()

template<typename K, typename Impl, typename Allocator>
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type simstr::str_storable< K, Impl, Allocator >::replaced_from ( const From & f,
s_str pattern,
s_str repl,
size_t offset = 0,
size_t maxCount = 0,
Args &&... args )
inlinestatic

Create a copy of the passed string with substrings replaced.

Parameters
f- source string.
pattern- substring to be replaced.
repl- the string to be replaced with.
offset- starting position for searching substrings.
maxCount- maximum number of replacements, 0 - no restrictions.
...args- parameters for initializing the allocator.

◆ to_nts()

template<typename K, typename Impl, typename Allocator>
s_str_nt simstr::str_storable< K, Impl, Allocator >::to_nts ( size_t from = 0) const
inline

Get simple_str_nt starting at the given character.

Parameters
from- position of the starting character, default 0.
Returns
simple_str_nt,

◆ uppered_from()

template<typename K, typename Impl, typename Allocator>
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type simstr::str_storable< K, Impl, Allocator >::uppered_from ( const From & f,
Args &&... args )
inlinestatic

Create a copy of the passed string in uppercase Unicode characters of the first plane (<0xFFFF).

Parameters
f- source string.
...args- parameters for initializing the allocator.

Case is changed by simplified tables, where one code_point is always changed to one code_point (but for UTF-8 it is possible that the length in code units will change).

◆ uppered_only_ascii_from()

template<typename K, typename Impl, typename Allocator>
template<StrType< K > From, typename... Args>
requires std::is_constructible_v<allocator_t, Args...>
static my_type simstr::str_storable< K, Impl, Allocator >::uppered_only_ascii_from ( const From & f,
Args &&... args )
inlinestatic

Create a string copy of the passed in uppercase ASCII characters.

Parameters
f- source string.
...args- parameters for initializing the allocator.

The documentation for this class was generated from the following file: