6#include <initializer_list>
13#include "../encoding.hpp"
14#include "charFunctions.hpp"
18#include "arrayLike.hpp"
21#include "stringIterator.hpp"
24#if __has_include(<cereal/cereal.hpp>)
25#include <cereal/types/string.hpp>
61template <encoding E = utf8>
73 void initChar(
uint32_t,
int)
noexcept;
74 int charSize()
const noexcept;
76 void initInt(
long long,
int,
int)
noexcept;
77 void initFloat(
double,
int,
int,
bool,
int)
noexcept;
78 void initPointer(
void *)
noexcept;
79 void initComplex(
const std::complex<double> &,
int,
int,
bool,
int)
noexcept;
133#if __cplusplus >= 202002L
186#if __cplusplus < 202002L
199 this->initPointer((
void *)
pointer);
214 this->initPointer((
void *)
pointer);
237 template <typename FLT, typename = typename std::enable_if<std::is_floating_point<FLT>::value, FLT>
::type>
313 data_len =
other.data_len;
314 character_ct =
other.character_ct;
327 if (&
other !=
this) {
330 data_len =
other.data_len;
331 character_ct =
other.character_ct;
590 for (
int i = index;
i < character_ct;
i++) {
646 return this->
foundAt(other, 0);
675 return type(
base) & (zstr::integer);
715 return type(
base,
decimal) & (zstr::integer | zstr::floating | zstr::complex);
756 return substr(index, character_ct - index);
964 if ((character_ct <
other.character_ct) || !character_ct) {
971 index +=
other.character_ct;
979 return substr(index, character_ct - index);
993 if ((character_ct <
other.character_ct) || !character_ct) {
997 int index = character_ct - 1;
1000 index -=
other.character_ct;
1008 return substr(0, index + 1);
1022 if ((character_ct <
other.character_ct) || !character_ct) {
1029 index +=
other.character_ct;
1051 if ((character_ct <
other.character_ct) || !character_ct) {
1055 int index = character_ct - 1;
1058 index -=
other.character_ct;
1066 return remove(index + 1, character_ct);
1124 return string(*this).toUpper();
1135 return string(*this).toLower();
1146 return string(*this).toCamel();
1386 return *
this +
other;
1528 stream << *
this << std::flush;
1538 void writeln(std::ostream &stream)
const noexcept {
1539 stream << *
this << std::endl;
1567#if __has_include(<cereal/cereal.hpp>)
1574 template <
class archive>
1585 template <
class archive>
1586 void load_minimal(archive
const &ar, std::string
const &value) {
1641z::core::
string<z::utf32>
operator""
_u32(
wchar_t value);
1647z::core::
string<z::utf16>
operator""
_u16(
wchar_t value);
1652z::core::
string<z::utf8>
operator""
_u8(
char value);
1653z::core::
string<z::utf8>
operator""
_u8(
wchar_t value);
1659z::core::
string<z::ascii>
operator""
_asc(
wchar_t value);
An interface for all objects that can be both iterated over and directly indexed.
Definition arrayLike.hpp:13
A wrapper for std::vector.
Definition array.hpp:38
int length() const noexcept override
Get the length of the array.
Definition array.hpp:1041
An interface for getting an object's size.
Definition sizable.hpp:13
A template class for character strings.
Definition string.hpp:62
bool isInteger(int base=10) const noexcept
Check if this string can convert to an integer.
Definition string.hpp:674
string(const std::complex< T > &value, int base=10, int precision=0, bool scientific=true, int padSize=0) noexcept
Construct from complex number.
Definition string.hpp:260
static string words(long long value, bool ordinal=false) noexcept
Generate an English representation of a given number.
string(const std::string &str) noexcept
Construct from a std::string.
Definition string.hpp:165
string & trimRightIn(const string &other="") noexcept
Remove padding from the right side of this string.
Definition string.hpp:1050
string & toLower() noexcept
Convert all characters in the string to lowercase.
int count(const string &other) const noexcept
Count the occurrences of a sub-string.
string & cutDuplicates(const string &other) noexcept
Remove all sequential duplicates from this string.
int find(const string &other, int occurrence=1) const noexcept
Find a specific occurrence of a sub-string.
Definition string.hpp:537
string & padRightIn(const string &other, int padSize) noexcept
Right-pad this string up to a given character count.
size_t size() const noexcept override
Get the size of the string in memory.
bool operator!=(const string &other) const noexcept
Inequality comparison.
Definition string.hpp:1440
string padLeft(const string &other, int padSize) const noexcept
Copy this string, left-padded given character count.
Definition string.hpp:884
std::string str() const noexcept
Convert to a std::string.
Definition string.hpp:1623
string(INT value, int base=10, int padSize=0) noexcept
Construct from an integer.
Definition string.hpp:182
bool operator>=(const string &other) const noexcept
Greater-than or equal comparison.
Definition string.hpp:1460
string operator+(const string &other) const noexcept
Concatenate two strings.
string(const string< ascii > &other) noexcept
Construct from an ASCII string.
string & toCamel() noexcept
Convert all characters in the string to camelcase.
bool foundEndAt(const string &other, int index) const noexcept
Check if a sub-string ends at the given index.
int length() const noexcept override
Get the character count of the string.
friend std::ostream & operator<<(std::ostream &ostr, const z::core::string< E > &str)
Stream output operator.
Definition string.hpp:1599
string trim(const string &other="") const noexcept
Copies this string and removes padding from both sides of the result.
Definition string.hpp:1079
static string numberFormat(double value, int precision=0, bool forcePrecision=false, char decimal='.', char thousands=',') noexcept
Create a string from a number with thousands separators.
string & replace(const string &findStr, const string &replStr, int occurrence=0) noexcept
Replace occurrences of the given sub-string.
string filter(const std::pair< uint32_t, uint32_t > &range, bool invert=false) const noexcept
Filter out all characters not in the given range.
Definition string.hpp:1203
string trimLeft(const string &other="") const noexcept
Copies this string and removes padding from the left side of the result.
Definition string.hpp:963
double floating(int base=10, uint32_t decimal='.') const noexcept
Convert this string to a floating-point value.
bool endsWith(const string &other) const noexcept
Check if the string ends with a given sub-string.
Definition string.hpp:657
string padRight(const string &other, int padSize) const noexcept
Copy this string, right-padded given character count.
Definition string.hpp:917
long integer(int base=10, uint32_t decimal='.') const noexcept
Convert this string to an integer.
string filter(uint32_t first, uint32_t last, bool invert=false) const noexcept
Filter out all characters not in the given range.
Definition string.hpp:1188
const uint16_t * nstring() const noexcept
Get the two-byte cstring pointer.
bool contains(const std::pair< uint32_t, uint32_t > &range, bool exclusive=false) const noexcept
Check if this string contains any characters in the given range.
Definition string.hpp:1273
uint32_t at(int index) const noexcept override
Get the character at the given index.
string & readln(std::istream &stream) noexcept
Read string data from a stream until a newline is encountered.
stringIterator< E > end() const noexcept override
Get an iterator for the end of the string.
Definition string.hpp:1562
string camel() const noexcept
Get a camelcase version of this string.
Definition string.hpp:1145
int findLast(const string &other, int occurrence=1) const noexcept
Reverse-find a specific occurrence of a sub-string.
Definition string.hpp:570
static string ordinal(long long value) noexcept
Get the ordinal suffix of a given integer.
bool operator>(const string &other) const noexcept
Greater-than comparison.
string(const string< utf32 > &other) noexcept
Construct from a UTF32 string.
const uint32_t * wstring() const noexcept
Get the four-byte cstring pointer.
string & operator=(const string &other) noexcept
Assign the contents of this string.
string lower() const noexcept
Get a lowercase version of this string.
Definition string.hpp:1134
string & append(const string &other) noexcept
Append another string to the end of this one.
Definition string.hpp:768
string & remove(const string &other, int occurrence=0) noexcept
Remove occurrences of the given sub-string.
const char * cstring() const noexcept
Get the single-byte cstring pointer.
friend std::istream & operator>>(std::istream &istr, z::core::string< E > &str)
Stream input operator.
Definition string.hpp:1609
~string() noexcept
Destructor.
Definition string.hpp:339
bool contains(uint32_t first, uint32_t last, bool exclusive=false) const noexcept
Check if this string contains any characters in the given range.
Definition string.hpp:1257
void write(std::ostream &stream) const noexcept
Write string data to a stream in that stream's encoding.
Definition string.hpp:1527
bool isComplex(int base=10, uint32_t decimal='.') const noexcept
Check if this string can convert to a complex value.
Definition string.hpp:714
string cipher(const string &keys, const string &values) const noexcept
Convert this string from one set of characters to another.
string() noexcept
Default string constructor.
string(const string< utf16 > &other) noexcept
Construct from a UTF16 string.
string & operator+=(const string &other) noexcept
Append another string to the end of this one.
string(const wchar_t *str, size_t len) noexcept
Construct from a cstring of wide characters, with a known length.
string & trimIn(const string &other="") noexcept
Remove padding from the both sides of this string.
Definition string.hpp:1094
int type(int base=10, uint32_t decimal='.') const noexcept
Determine the most basic type that this string can cast to.
string(FLT value, int base=10, int precision=0, bool scientific=true, int padSize=0) noexcept
Construct from floating-point.
Definition string.hpp:238
string(const string< utf8 > &other) noexcept
Construct from a UTF-8 string.
string concat(const string &other) const noexcept
Concatenate two strings.
Definition string.hpp:1385
string & append(uint32_t chr) noexcept
Append a single character to the end of the string.
string & readall(std::istream &stream) noexcept
Read an entire stream's contents into this string.
int findAfter(const string &other, int index, int occurrence=1) const noexcept
Find a specific occurrence of a sub-string.
Definition string.hpp:588
stringIterator< E > begin() const noexcept override
Get an iterator for the beginning of the string.
Definition string.hpp:1550
string filter(const std::initializer_list< const std::pair< uint32_t, uint32_t > > &list, bool invert=false) const noexcept
Filter out all characters not in the given range.
string trimRight(const string &other="") const noexcept
Copies this string and removes padding from the right side of the result.
Definition string.hpp:992
int found(const string &other, int occurrence=1) const noexcept
Check if a specific occurrence of a sub-string exists.
Definition string.hpp:553
int findBefore(const string &other, int index, int occurrence=1) const noexcept
Reverse-find a specific occurrence of a sub-string.
string substr(int index, int count) const noexcept
Get a sub-string from this string.
std::complex< double > complex(int base=10, uint32_t decimal='.') const noexcept
Convert this string to a complex value.
bool operator<(const string &other) const noexcept
Less-than comparison.
string repeat(int count) const noexcept
Repeat this string a specific number of times.
Definition string.hpp:944
string & operator=(string &&other) noexcept
Move assignment operator.
Definition string.hpp:326
bool contains(const std::initializer_list< const std::pair< uint32_t, uint32_t > > &list, bool exclusive=false) const noexcept
Check if this string contains any characters in the given ranges.
void clear() noexcept
Reset to a null string.
string & toUpper() noexcept
Convert all characters in the string to uppercase.
string(PTR pointer) noexcept
Construct from a pointer.
Definition string.hpp:198
bool beginsWith(const string &other) const noexcept
Check if the string begins with a given sub-string.
Definition string.hpp:645
string upper() const noexcept
Get an uppercase version of this string.
Definition string.hpp:1123
void increase(int charCount) noexcept
Increase the space allocated for this string.
string & trimLeftIn(const string &other="") noexcept
Remove padding from the left side of this string.
Definition string.hpp:1021
bool operator<=(const string &other) const noexcept
Less-than or equal comparison.
Definition string.hpp:1480
string & read(std::istream &stream, uint32_t delim=0) noexcept
Read string data from a stream until the given delimiter is encountered.
string & truncate(int index) noexcept
Remove all characters from a given index to the end of the string.
bool foundAt(const string &other, int index) const noexcept
Check if a sub-string is found at the given index.
int chars() const noexcept
Get the individual character count of the string.
static string precision(double value, int precision, bool forcePrecision=false) noexcept
Create a string from a number with a fixed number of decimal places.
Definition string.hpp:1357
string(string &&other) noexcept
Move constructor.
Definition string.hpp:311
bool operator==(const string &other) const noexcept
Equality comparison.
string(const wchar_t *str) noexcept
Construct from a cstring of wide characters.
string & insert(const string &other, int index) noexcept
Insert another string into this one.
constexpr encoding format() const noexcept
Get the encoding of this string.
Definition string.hpp:435
void writeln(std::ostream &stream) const noexcept
Write string data to a stream in its format, appending a newline.
Definition string.hpp:1538
string & padLeftIn(const string &other, int padSize) noexcept
Left-pad this string up to a given character count.
hash32 hash() const noexcept
Compute the CRC32 hash of this string.
bool isFloating(int base=10, uint32_t decimal='.') const noexcept
Check if this string can convert to a floating-point value.
Definition string.hpp:694
encoding
Supported string encoding schemes.
Definition encoding.hpp:12
bool isWhiteSpace(uint32_t ch) noexcept
Check if the given character is white space.
generator< long, long > range(long begin, long end, long step=1) noexcept
Generate a sequence of integers in a specified range.