![]() |
Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
|
Extensions of std::string.

Classes | |
| struct | elementa::base::is_charlike< T > |
| Return TRUE if type T is char, wchar_t, char16_t or char32_t. More... | |
| struct | elementa::base::is_charlike< char > |
| Specialization of is_charlike for char. More... | |
| struct | elementa::base::is_charlike< wchar_t > |
| Specialization of is_charlike for wchar_t. More... | |
| struct | elementa::base::is_charlike< char16_t > |
| Specialization of is_charlike for char16_t. More... | |
| struct | elementa::base::is_charlike< char32_t > |
| Specialization of is_charlike for char32_t. More... | |
| struct | elementa::base::IsStringHelperPriv< T > |
| A struct with a void member. More... | |
| struct | elementa::base::is_string< T, Enable > |
| Template class to check whether T is derived from std::basic_string. More... | |
| struct | elementa::base::is_string< T, typename IsStringHelperPriv< typename T::value_type, typename T::traits_type, typename T::allocator_type >::type > |
| class | elementa::base::Strings |
| A number of strings. More... | |
Functions | |
| bool | elementa::base::is_all_upper (const std::string &s) noexcept |
| Return TRUE if all characters in S are uppercase. More... | |
| bool | elementa::base::is_all_lower (const std::string &s) noexcept |
| Return TRUE if all characters in S are lowercase. More... | |
| constexpr bool | elementa::base::is_hex_digit (char c) noexcept |
| Return TRUE if C is an hexadecimal digit, either in lower or uppercase. More... | |
| bool | elementa::base::is_identifier (const std::string &s) |
| Return TRUE if S is a standard identifier. More... | |
| bool | elementa::base::is_number (const std::string &s, uint8_t base=10, bool onlyint=false) |
| Return TRUE if S contains a number (possibly with sign) in some base. More... | |
| constexpr bool | elementa::base::is_linechanger (char c) |
| Return TRUE if C is a character involved in changing to new lines of text. More... | |
| constexpr bool | elementa::base::is_blank (char c) |
| Return TRUE if C is a tab or space character. More... | |
| constexpr bool | elementa::base::is_separator (char c) |
| Return TRUE if C is a separator character. More... | |
| const std::vector< uint8_t > & | elementa::base::bytes_for_eol (void) |
| Return a vector containing the bytes that form std::endl in this machine. | |
| template<typename NumType > | |
| std::string | elementa::base::to_string_dec (NumType n, bool padding=true) |
| Convert an integral number to string in decimal format. More... | |
| template<> | |
| std::string | elementa::base::to_string_dec (uint8_t n, bool padding) |
| Convert an integral number to string in decimal format. More... | |
| template<typename NumType > | |
| std::string | elementa::base::to_string_hex (NumType n, bool padding=true) |
| Convert an integral number to string in hexadecimal format, without preffix. More... | |
| template<typename NumType > | |
| std::string | elementa::base::to_string_bin (NumType n, bool padding=true) |
| Convert an integral number to string in binary format. More... | |
| template<typename NumType > | |
| std::string | elementa::base::to_string_oct (NumType n, bool padding=true) |
| Convert an integral number to string in octal format. More... | |
| template<typename NumType > | |
| NumType | elementa::base::from_string_hex (const std::string &txt) |
| Return the unsigned int. value of a number expressed in hexadecimal form. More... | |
| template<typename NumType > | |
| NumType | elementa::base::from_string_bin (const std::string &txt) |
| Return the unsigned int. value of a number expressed in binary form. More... | |
| std::string | elementa::base::real_to_string (LongestReal n) |
| Convert a N to string with high precision. More... | |
| std::string | elementa::base::real_to_string_fixdec (LongestReal n, unsigned ds) |
| Convert N to string with a fixed number of decimal digits. */. | |
| std::string | elementa::base::char_to_string (char c) |
| Convert a char to a string of 1 char. More... | |
| template<typename PointedType > | |
| std::string | elementa::base::hexdump (const PointedType *data, size_t howmany, bool toupp=true, bool sepelems=true) |
| Return a string that represents all hex codes of the pointed bytes. More... | |
| std::string | elementa::base::toCase (const std::string &s, char to) |
| Convert a string into upper ('U') or lower ('L') case. | |
| std::string & | elementa::base::ltrim_mut (std::string &s) |
| Remove left space-like characters, modifying the input string directly. More... | |
| std::string | elementa::base::ltrim (const std::string &s) |
| Remove left space-like characters, creating a new string with the result. More... | |
| std::string & | elementa::base::rtrim_mut (std::string &s) |
| Remove right space-like characters, modifying the input string directly. More... | |
| std::string | elementa::base::rtrim (const std::string &s) |
| Remove right space-like characters, creating a new string with the result. More... | |
| std::string & | elementa::base::trim_mut (std::string &s) |
| Remove both right and left space-like characters, directly on input string. More... | |
| std::string | elementa::base::trim (const std::string &s) |
| Remove both right and left space-like characters, creating new string. More... | |
| void | elementa::base::pad (std::string &s, size_t len, bool leftorright=false, char padding=' ') |
| Pad S with character PADDING if shorter than LEN. More... | |
| void | elementa::base::chop (std::string &s, size_t len, char excess=0x00, bool leftorright=false, char padding=' ') |
| Chop S to a string of length LEN, padding it if necessary. More... | |
| std::vector< std::string > | elementa::base::split (const std::string &s, char delim) |
| Split a string through a given delimiter. More... | |
| std::string | elementa::base::concatWithMiddle (const std::string &s1, const std::string &s2, const std::string &m=". ") |
| Concatenate two strings putting a middle one only if the second is not empty. | |
| std::string | elementa::base::indentlinedtext (const std::string &txt, bool atstarttoo=false, std::string::size_type maxlinelength=80, const std::string &newlinepreffix=" ", const std::string &newlinetext="\n") |
| Return a string after splitting it into a number of indented lines. More... | |
| struct elementa::base::is_charlike |
Return TRUE if type T is char, wchar_t, char16_t or char32_t.
This is the general case of the template, for when T is not any of those.
Static Public Attributes | |
| static constexpr bool | value = false |
|
staticconstexpr |
| struct elementa::base::is_charlike< char > |
Specialization of is_charlike for char.
Static Public Attributes | |
| static constexpr bool | value = true |
|
staticconstexpr |
| struct elementa::base::is_charlike< wchar_t > |
Specialization of is_charlike for wchar_t.
Static Public Attributes | |
| static constexpr bool | value = true |
|
staticconstexpr |
| struct elementa::base::is_charlike< char16_t > |
Specialization of is_charlike for char16_t.
Static Public Attributes | |
| static constexpr bool | value = true |
|
staticconstexpr |
| struct elementa::base::is_charlike< char32_t > |
Specialization of is_charlike for char32_t.
Static Public Attributes | |
| static constexpr bool | value = true |
|
staticconstexpr |
| struct elementa::base::IsStringHelperPriv |
| struct elementa::base::is_string |
Template class to check whether T is derived from std::basic_string.


| struct elementa::base::is_string< T, typename IsStringHelperPriv< typename T::value_type, typename T::traits_type, typename T::allocator_type >::type > |


| class elementa::base::Strings |


Public Types | |
| using | Base = std::vector< std::string > |
Public Attributes | |
| T | elements |
| STL member. | |
Public Member Functions | |
| std::string | to_string (const std::string &preffix="", const std::string &beg="{", const std::string &end="}") const |
| Return a string formed by all the strings as a set. More... | |
| using elementa::base::Strings::Base = std::vector<std::string> |
| std::string elementa::base::Strings::to_string | ( | const std::string & | preffix = "", |
| const std::string & | beg = "{", |
||
| const std::string & | end = "}" |
||
| ) | const |
Return a string formed by all the strings as a set.
Creates a string that contains the sequece of strings separated by ", " and with PREFFIX appended before each of the strings. The result begins with BEG and ends with END.
|
noexcept |
#include <elementa/base/strings.h>
Return TRUE if all characters in S are uppercase.
Characters that cannot be upper or lower case (e.g., space, digits, underscore) are ignored. An empty S produces TRUE.
|
noexcept |
#include <elementa/base/strings.h>
Return TRUE if all characters in S are lowercase.
Characters that cannot be upper or lower case (e.g., space, digits, underscore) are ignored. An empty S produces TRUE.
|
constexprnoexcept |
#include <elementa/base/strings.h>
Return TRUE if C is an hexadecimal digit, either in lower or uppercase.
| bool elementa::base::is_identifier | ( | const std::string & | s | ) |
#include <elementa/base/strings.h>
Return TRUE if S is a standard identifier.
A standard identifier is an non-empty, any-length string that only contains digits, letters (upper or lower) and '_', and does not begin with a digit.
| bool elementa::base::is_number | ( | const std::string & | s, |
| uint8_t | base = 10, |
||
| bool | onlyint = false |
||
| ) |
#include <elementa/base/strings.h>
Return TRUE if S contains a number (possibly with sign) in some base.
Return FALSE if S is empty.
| base | is the base. It can be 2,8,10,16. |
| onlyint | indicates whether to test for integers only, or also for reals. It is ignored and testing done only for integers in the case that base is not 10. |
|
constexpr |
#include <elementa/base/strings.h>
Return TRUE if C is a character involved in changing to new lines of text.
Definition at line 174 of file strings.h.
Referenced by elementa::base::is_separator().
|
constexpr |
#include <elementa/base/strings.h>
Return TRUE if C is a tab or space character.
Definition at line 178 of file strings.h.
Referenced by elementa::base::is_separator().
|
constexpr |
#include <elementa/base/strings.h>
Return TRUE if C is a separator character.
Definition at line 182 of file strings.h.
References elementa::base::is_blank(), and elementa::base::is_linechanger().
| std::string elementa::base::to_string_dec | ( | NumType | n, |
| bool | padding = true |
||
| ) |
#include <elementa/base/strings.h>
Convert an integral number to string in decimal format.
If PADDING, fill with 0 the most significant part of the number up to the length of the greatest number of that size; otherwise, get rid of those 0's.
| std::string elementa::base::to_string_dec | ( | uint8_t | n, |
| bool | padding | ||
| ) |
#include <elementa/base/strings.h>
Convert an integral number to string in decimal format.
If PADDING, fill with 0 the most significant part of the number up to the length of the greatest number of that size; otherwise, get rid of those 0's.
| std::string elementa::base::to_string_hex | ( | NumType | n, |
| bool | padding = true |
||
| ) |
#include <elementa/base/strings.h>
Convert an integral number to string in hexadecimal format, without preffix.
If PADDING, fill with 0 the most significant part of the number up to the length of the greatest number of that size; otherwise, get rid of those 0's.
Definition at line 234 of file strings.h.
Referenced by elementa::base::hexdump().
| std::string elementa::base::to_string_bin | ( | NumType | n, |
| bool | padding = true |
||
| ) |
#include <elementa/base/strings.h>
Convert an integral number to string in binary format.
If PADDING, fill with 0 the most significant part of the number up to the length of the greatest number of that size; otherwise, get rid of those 0's.
| std::string elementa::base::to_string_oct | ( | NumType | n, |
| bool | padding = true |
||
| ) |
#include <elementa/base/strings.h>
Convert an integral number to string in octal format.
If PADDING, fill with 0 the most significant part of the number up to the length of the greatest number of that size; otherwise, get rid of those 0's.
| NumType elementa::base::from_string_hex | ( | const std::string & | txt | ) |
#include <elementa/base/strings.h>
Return the unsigned int. value of a number expressed in hexadecimal form.
The hexadecimal string may contain letters a-f in upper or lower case, and the calculation ends when, scanning from its end to its start, a non-digit, non a-f character is found.
| NumType elementa::base::from_string_bin | ( | const std::string & | txt | ) |
#include <elementa/base/strings.h>
Return the unsigned int. value of a number expressed in binary form.
The binary string may contain digits 0-1 only, and the calculation ends when, scanning from its end to its start, a non-0-1-digit is found.
| std::string elementa::base::real_to_string | ( | LongestReal | n | ) |
#include <elementa/base/strings.h>
Convert a N to string with high precision.
The std::to_string only works with 6 decimal places.
| std::string elementa::base::char_to_string | ( | char | c | ) |
#include <elementa/base/strings.h>
Convert a char to a string of 1 char.
This methods should only be used to create a char into a new string; for concatenating a char to an existing string, just use the string '+' operator.
| std::string elementa::base::hexdump | ( | const PointedType * | data, |
| size_t | howmany, | ||
| bool | toupp = true, |
||
| bool | sepelems = true |
||
| ) |
#include <elementa/base/strings.h>
Return a string that represents all hex codes of the pointed bytes.
Each element is separated from the next one by a space if SEPELEMS == TRUE.
Definition at line 349 of file strings.h.
References elementa::base::to_string_hex().
|
inline |
#include <elementa/base/strings.h>
Remove left space-like characters, modifying the input string directly.
Definition at line 400 of file strings.h.
Referenced by elementa::base::ltrim(), and elementa::base::trim_mut().
|
inline |
#include <elementa/base/strings.h>
Remove left space-like characters, creating a new string with the result.
Definition at line 413 of file strings.h.
References elementa::base::ltrim_mut().
|
inline |
#include <elementa/base/strings.h>
Remove right space-like characters, modifying the input string directly.
Definition at line 425 of file strings.h.
Referenced by elementa::base::rtrim(), and elementa::base::trim_mut().
|
inline |
#include <elementa/base/strings.h>
Remove right space-like characters, creating a new string with the result.
Definition at line 433 of file strings.h.
References elementa::base::rtrim_mut().
|
inline |
#include <elementa/base/strings.h>
Remove both right and left space-like characters, directly on input string.
Definition at line 441 of file strings.h.
References elementa::base::ltrim_mut(), and elementa::base::rtrim_mut().
Referenced by elementa::base::trim().
|
inline |
#include <elementa/base/strings.h>
Remove both right and left space-like characters, creating new string.
Definition at line 447 of file strings.h.
References elementa::base::trim_mut().
| void elementa::base::pad | ( | std::string & | s, |
| size_t | len, | ||
| bool | leftorright = false, |
||
| char | padding = ' ' |
||
| ) |
#include <elementa/base/strings.h>
Pad S with character PADDING if shorter than LEN.
Pad to the right if LEFTORRIGHT == FALSE or to the left if TRUE. If the size of the string is greater or equal to LEN, do nothing.
| void elementa::base::chop | ( | std::string & | s, |
| size_t | len, | ||
| char | excess = 0x00, |
||
| bool | leftorright = false, |
||
| char | padding = ' ' |
||
| ) |
#include <elementa/base/strings.h>
Chop S to a string of length LEN, padding it if necessary.
If EXCESS is not 0x00 and S is longer than LEN, the last character will be EXCESS after chopping to LEN characters.
| std::vector< std::string > elementa::base::split | ( | const std::string & | s, |
| char | delim | ||
| ) |
#include <elementa/base/strings.h>
Split a string through a given delimiter.
Split a given (immutable) string into several ones, guided by a delimiter character. The delimiter is not included in the resulting strings. A delimiter followed by the end of the string and an empty part followed by a delimiter are counted as parts of the splitting.
Referenced by elementa::base::EnumExtPriv< BaseID, HelperIDString >::IdName().
| std::string elementa::base::indentlinedtext | ( | const std::string & | txt, |
| bool | atstarttoo = false, |
||
| std::string::size_type | maxlinelength = 80, |
||
| const std::string & | newlinepreffix = " ", |
||
| const std::string & | newlinetext = "\n" |
||
| ) |
#include <elementa/base/strings.h>
Return a string after splitting it into a number of indented lines.
This routine is very useful to format tabulated long texts with limited number of columns. It scans the original text to produce the split one. It substitutes any sequence of blanks (the ones identified by is_blank()) by 1 space, and then make the splitting. If it finds a line changing character (is_linechanger()) forces a splitting there, dropping that character and any other consecutive one that is also line changing but different (i.e., sequences "'\n\r'" or "'\r\n'"). Any other character is considered a non-separator.
If a line scanned that way extends beyond MAXLINELENGTH characters, or a line changing char is found, the text NEWLINETEXT + NEWLINEPREFFIX will substitute the previous last found separator along the line. NEWLINEPREFFIX cannot contain line changing characters.
Notice that this way of working prevents the recursive use of this function to split/indent already split/indented texts.
An exception is thrown if there is no separators along a line that needs to be splitted, since in that case no place to do the splitting can be chosen.
If MAXLINELENGTH == 0, no split will be done after any length.
If ATSTARTTOO == TRUE, NEWLINEPREFFIX will be also inserted at the beginning of the text.
Examples:
\code
// This prints in console a text tabulated 4 spaces before each line,
// including the first one, but without maximum length in lines:
// (note that any ending \n in TXT will do the newline PLUS adding the
// tabs in that new line.
std:: cout << indentboundtext(txt,true,0," ");
// This prints in console a text splitted at correct word-endings with
// longest lines of 80 characters, and tabulated 8 spaces each line,
// without indenting the first one:
std::cout << indentboundtext(txt,false,80," ");
\endcode