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;
193 this->initPointer((
void *)
pointer);
291 data_len =
other.data_len;
292 character_ct =
other.character_ct;
305 if (&
other !=
this) {
308 data_len =
other.data_len;
309 character_ct =
other.character_ct;
568 for (
int i = index;
i < character_ct;
i++) {
624 return this->
foundAt(other, 0);
653 return type(
base) & (zstr::integer);
693 return type(
base,
decimal) & (zstr::integer | zstr::floating | zstr::complex);
931 if ((character_ct <
other.character_ct) || !character_ct) {
938 index +=
other.character_ct;
946 return substr(index, character_ct - index);
960 if ((character_ct <
other.character_ct) || !character_ct) {
964 int index = character_ct - 1;
967 index -=
other.character_ct;
975 return substr(0, index + 1);
989 if ((character_ct <
other.character_ct) || !character_ct) {
996 index +=
other.character_ct;
1018 if ((character_ct <
other.character_ct) || !character_ct) {
1022 int index = character_ct - 1;
1025 index -=
other.character_ct;
1033 return remove(index + 1, character_ct);
1091 return string(*this).toUpper();
1102 return string(*this).toLower();
1113 return string(*this).toCamel();
1353 return *
this +
other;
1497 stream << *
this << std::flush;
1507 void writeln(std::ostream &stream)
const noexcept {
1508 stream << *
this << std::endl;
1536#if __has_include(<cereal/cereal.hpp>)
1543 template <
class archive>
1554 template <
class archive>
1610z::core::
string<z::utf32>
operator""
_u32(
wchar_t value);
1616z::core::
string<z::utf16>
operator""
_u16(
wchar_t value);
1621z::core::
string<z::utf8>
operator""
_u8(
char value);
1622z::core::
string<z::utf8>
operator""
_u8(
wchar_t value);
1628z::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:72
int length() const noexcept override
Get the length of the array.
Definition array.hpp:1011
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:652
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:238
static string words(long long value, bool ordinal=false) noexcept
Generate an English representation of a given number.
string & trimRightIn(const string &other="") noexcept
Remove padding from the right side of this string.
Definition string.hpp:1017
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:515
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:1407
string padLeft(const string &other, int padSize) const noexcept
Copy this string, left-padded given character count.
Definition string.hpp:851
std::string str() const noexcept
Convert to a std::string.
Definition string.hpp:1592
string(INT value, int base=10, int padSize=0) noexcept
Construct from an integer.
Definition string.hpp:177
void load_minimal(archive const &ar, std::string const &value)
Serialization input.
Definition string.hpp:1555
bool operator>=(const string &other) const noexcept
Greater-than or equal comparison.
Definition string.hpp:1427
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:1568
string trim(const string &other="") const noexcept
Copies this string and removes padding from both sides of the result.
Definition string.hpp:1046
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:1170
string trimLeft(const string &other="") const noexcept
Copies this string and removes padding from the left side of the result.
Definition string.hpp:930
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:635
string padRight(const string &other, int padSize) const noexcept
Copy this string, right-padded given character count.
Definition string.hpp:884
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:1155
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:1240
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:1531
string camel() const noexcept
Get a camelcase version of this string.
Definition string.hpp:1112
int findLast(const string &other, int occurrence=1) const noexcept
Reverse-find a specific occurrence of a sub-string.
Definition string.hpp:548
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:1101
string & append(const string &other) noexcept
Append another string to the end of this one.
Definition string.hpp:735
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:1578
~string() noexcept
Destructor.
Definition string.hpp:317
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:1224
void write(std::ostream &stream) const noexcept
Write string data to a stream in that stream's encoding.
Definition string.hpp:1496
bool isComplex(int base=10, uint32_t decimal='.') const noexcept
Check if this string can convert to a complex value.
Definition string.hpp:692
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 & trimIn(const string &other="") noexcept
Remove padding from the both sides of this string.
Definition string.hpp:1061
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:216
std::string save_minimal(archive &ar) const
Serialization output.
Definition string.hpp:1544
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:1352
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:566
stringIterator< E > begin() const noexcept override
Get an iterator for the beginning of the string.
Definition string.hpp:1519
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:959
int found(const string &other, int occurrence=1) const noexcept
Check if a specific occurrence of a sub-string exists.
Definition string.hpp:531
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:911
string & operator=(string &&other) noexcept
Move assignment operator.
Definition string.hpp:304
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:192
bool beginsWith(const string &other) const noexcept
Check if the string begins with a given sub-string.
Definition string.hpp:623
string upper() const noexcept
Get an uppercase version of this string.
Definition string.hpp:1090
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:988
bool operator<=(const string &other) const noexcept
Less-than or equal comparison.
Definition string.hpp:1447
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:1324
string(string &&other) noexcept
Move constructor.
Definition string.hpp:289
bool operator==(const string &other) const noexcept
Equality comparison.
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:413
void writeln(std::ostream &stream) const noexcept
Write string data to a stream in its format, appending a newline.
Definition string.hpp:1507
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:672
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.