libzed 1.11.4
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
string.hpp
1#pragma once
2
3#include <complex>
4#include <cstring>
5#include <functional>
6#include <initializer_list>
7#include <type_traits>
8#include <utility>
9
10#include <istream>
11#include <ostream>
12
13#include "../encoding.hpp"
14#include "charFunctions.hpp"
15#include "hash32.hpp"
16#include "zstr.hpp"
17
18#include "arrayLike.hpp"
19#include "sizable.hpp"
20
21#include "stringIterator.hpp"
22
23#ifdef __has_include
24#if __has_include(<cereal/cereal.hpp>)
25#include <cereal/types/string.hpp>
26#endif
27#endif
28
29namespace z {
30namespace core {
61template <encoding E = utf8>
62class string final : public sizable, public arrayLike<uint32_t, stringIterator<E>> {
63 friend string<ascii>;
64 friend string<utf8>;
65 friend string<utf16>;
66 friend string<utf32>;
67
68private:
69 uint8_t *data;
70 int data_len;
71 int character_ct;
72
73 void initChar(uint32_t, int) noexcept;
74 int charSize() const noexcept;
75
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;
80
81public:
84
92 explicit string(char chr) noexcept;
93
101 explicit string(wchar_t chr) noexcept;
102
112 string(const uint32_t &chr) noexcept;
113
121 string(const char *str) noexcept;
122
131 string(const char *str, size_t len) noexcept;
132
133#if __cplusplus >= 202002L
134 inline string(const char8_t *const str) noexcept : string((const char *)str) {}
135 string(const char8_t *const str, size_t len) noexcept : string((const char *)str, len) {}
136#endif
137
146 string(const wchar_t *str) noexcept;
147
156 string(const wchar_t *str, size_t len) noexcept;
157
165 string(const std::string &str) noexcept : string(str.c_str(), str.size()) {}
166
181 template <typename INT, typename = typename std::enable_if<std::is_integral<INT>::value && !std::is_same<INT, char>::value && !std::is_same<INT, wchar_t>::value, INT>::type>
182 string(INT value, int base = 10, int padSize = 0) noexcept {
183 this->initInt((long long)value, base, padSize);
184 }
185
186#if __cplusplus < 202002L
197 template <typename PTR, typename = typename std::enable_if<std::is_pointer<PTR>::value && !std::is_same<PTR, char *>::value && !std::is_same<PTR, wchar_t *>::value, PTR>::type>
198 string(PTR pointer) noexcept {
199 this->initPointer((void *)pointer);
200 }
201#else
212 template <typename PTR, typename = typename std::enable_if<std::is_pointer<PTR>::value && !std::is_same<PTR, char *>::value && !std::is_same<PTR, wchar_t *>::value && !std::is_same<PTR, char8_t *>::value, PTR>::type>
213 string(PTR pointer) noexcept {
214 this->initPointer((void *)pointer);
215 }
216#endif
217
237 template <typename FLT, typename = typename std::enable_if<std::is_floating_point<FLT>::value, FLT>::type>
238 string(FLT value, int base = 10, int precision = 0, bool scientific = true, int padSize = 0) noexcept {
239 this->initFloat((double)value, base, precision, scientific, padSize);
240 }
241
260 string(const std::complex<T> &value, int base = 10, int precision = 0, bool scientific = true, int padSize = 0) noexcept {
261 this->initComplex((std::complex<double>)value, base, precision, scientific, padSize);
262 }
263
272 string(const string<ascii> &other) noexcept;
273
282 string(const string<utf8> &other) noexcept;
283
292 string(const string<utf16> &other) noexcept;
293
302 string(const string<utf32> &other) noexcept;
303
311 string(string &&other) noexcept {
312 data = other.data;
313 data_len = other.data_len;
314 character_ct = other.character_ct;
315 other.data = NULL;
316 }
317
326 string &operator=(string &&other) noexcept {
327 if (&other != this) {
328 delete[] data;
329 data = other.data;
330 data_len = other.data_len;
331 character_ct = other.character_ct;
332 other.data = NULL;
333 }
334
335 return *this;
336 }
337
340 if (data) {
341 delete[] data;
342 }
343 }
344
354 void increase(int charCount) noexcept;
355
371 uint32_t at(int index) const noexcept override;
372
379
391
403
411
419
427
436 return E;
437 }
438
453 long integer(int base = 10, uint32_t decimal = '.') const noexcept;
454
459 template <typename INT, typename = typename std::enable_if<std::is_integral<INT>::value, INT>::type>
461 return integer();
462 }
463
475 double floating(int base = 10, uint32_t decimal = '.') const noexcept;
476
482 return floating();
483 }
484
489 explicit operator float() const noexcept {
490 return floating();
491 }
492
497 constexpr explicit operator bool() const noexcept {
498 return length() > 0;
499 }
500
512 std::complex<double> complex(int base = 10, uint32_t decimal = '.') const noexcept;
513
523
537 int find(const string &other, int occurrence = 1) const noexcept {
538 return this->findAfter(other, 0, occurrence);
539 }
540
553 int found(const string &other, int occurrence = 1) const noexcept {
554 return this->findAfter(other, 0, occurrence) >= 0;
555 }
556
570 int findLast(const string &other, int occurrence = 1) const noexcept {
571 return this->findBefore(other, this->character_ct, occurrence);
572 }
573
588 int findAfter(const string &other, int index, int occurrence = 1) const noexcept {
590 for (int i = index; i < character_ct; i++) {
591 if (foundAt(other, i)) {
592 return i;
593 }
594 }
595
596 return -1;
597 }
598
613 int findBefore(const string &other, int index, int occurrence = 1) const noexcept;
614
624 bool foundAt(const string &other, int index) const noexcept;
625
635 bool foundEndAt(const string &other, int index) const noexcept;
636
646 return this->foundAt(other, 0);
647 }
648
657 bool endsWith(const string &other) const noexcept {
658 return this->foundEndAt(other, character_ct - 1);
659 }
660
674 bool isInteger(int base = 10) const noexcept {
675 return type(base) & (zstr::integer);
676 }
677
695 return type(base, decimal) & (zstr::integer | zstr::floating);
696 }
697
714 bool isComplex(int base = 10, uint32_t decimal = '.') const noexcept {
715 return type(base, decimal) & (zstr::integer | zstr::floating | zstr::complex);
716 }
717
731 int type(int base = 10, uint32_t decimal = '.') const noexcept;
732
746 string substr(int index, int count) const noexcept;
747
755 inline string substr(int index) const noexcept {
756 return substr(index, character_ct - index);
757 }
758
768 string &append(const string &other) noexcept {
769 return operator+=(other);
770 }
771
784 string &append(uint32_t chr) noexcept;
785
798 string &insert(const string &other, int index) noexcept;
799
813 string &remove(const string &other, int occurrence = 0) noexcept;
814
826 string &remove(int index, int count) noexcept;
827
839 string &truncate(int index) noexcept;
840
855 string &replace(const string &findStr, const string &replStr, int occurrence = 0) noexcept;
856
869 string &replace(int index, int count, const string &other) noexcept;
870
884 string padLeft(const string &other, int padSize) const noexcept {
885 string newString = *this;
886 return newString.padLeftIn(other, padSize);
887 }
888
902 string &padLeftIn(const string &other, int padSize) noexcept;
903
917 string padRight(const string &other, int padSize) const noexcept {
918 string newString = *this;
919 return newString.padRightIn(other, padSize);
920 }
921
935 string &padRightIn(const string &other, int padSize) noexcept;
936
944 string repeat(int count) const noexcept {
945 string value;
946 value.increase(character_ct * count);
947 for (int i = 0; i < count; ++i) {
948 value.append(*this);
949 }
950 return value;
951 }
952
963 string trimLeft(const string &other = "") const noexcept {
964 if ((character_ct < other.character_ct) || !character_ct) {
965 return *this;
966 }
967
968 int index = 0;
969 if (other.length()) {
970 while (foundAt(other, index)) {
971 index += other.character_ct;
972 }
973 } else {
974 while (isWhiteSpace(at(index))) {
975 ++index;
976 }
977 }
978
979 return substr(index, character_ct - index);
980 }
981
992 string trimRight(const string &other = "") const noexcept {
993 if ((character_ct < other.character_ct) || !character_ct) {
994 return *this;
995 }
996
997 int index = character_ct - 1;
998 if (other.length()) {
999 while (foundEndAt(other, index)) {
1000 index -= other.character_ct;
1001 }
1002 } else {
1003 while (isWhiteSpace(at(index))) {
1004 --index;
1005 }
1006 }
1007
1008 return substr(0, index + 1);
1009 }
1010
1021 string &trimLeftIn(const string &other = "") noexcept {
1022 if ((character_ct < other.character_ct) || !character_ct) {
1023 return *this;
1024 }
1025
1026 int index = 0;
1027 if (other.length()) {
1028 while (foundAt(other, index)) {
1029 index += other.character_ct;
1030 }
1031 } else {
1032 while (isWhiteSpace(this->at(index))) {
1033 ++index;
1034 }
1035 }
1036
1037 return remove(0, index);
1038 }
1039
1050 string &trimRightIn(const string &other = "") noexcept {
1051 if ((character_ct < other.character_ct) || !character_ct) {
1052 return *this;
1053 }
1054
1055 int index = character_ct - 1;
1056 if (other.length()) {
1057 while (foundEndAt(other, index)) {
1058 index -= other.character_ct;
1059 }
1060 } else {
1061 while (isWhiteSpace(at(index))) {
1062 --index;
1063 }
1064 }
1065
1066 return remove(index + 1, character_ct);
1067 }
1068
1079 string trim(const string &other = "") const noexcept {
1080 auto result = trimLeft(other);
1081 return result.trimRightIn(other);
1082 }
1083
1094 string &trimIn(const string &other = "") noexcept {
1096 return trimRightIn(other);
1097 }
1098
1103
1115
1124 return string(*this).toUpper();
1125 }
1126
1135 return string(*this).toLower();
1136 }
1137
1146 return string(*this).toCamel();
1147 }
1148
1157
1166
1175
1189 return filter({first, last}, invert);
1190 }
1191
1203 string filter(const std::pair<uint32_t, uint32_t> &range, bool invert = false) const noexcept {
1204 return filter({range}, invert);
1205 }
1206
1218 string filter(const std::initializer_list<const std::pair<uint32_t, uint32_t>> &list, bool invert = false) const noexcept;
1219
1230 string filter(const string &list, bool invert = false) const noexcept;
1231
1242 string filter(std::function<bool(uint32_t)> lambda) const noexcept;
1243
1260
1273 bool contains(const std::pair<uint32_t, uint32_t> &range, bool exclusive = false) const noexcept {
1274 return contains({range}, exclusive);
1275 }
1276
1289 bool contains(const std::initializer_list<const std::pair<uint32_t, uint32_t>> &list, bool exclusive = false) const noexcept;
1290
1302 bool contains(const string &list, bool exclusive = false) const noexcept;
1303
1315 string cipher(const string &keys, const string &values) const noexcept;
1316
1328 string cipher(std::function<uint32_t(uint32_t)> lambda) const noexcept;
1329
1337 static string words(long long value, bool ordinal = false) noexcept;
1338
1347 static string ordinal(long long value) noexcept;
1348
1357 static inline string precision(double value, int precision, bool forcePrecision = false) noexcept {
1358 return string(value, 10, precision, false, forcePrecision ? precision : 0);
1359 }
1360
1371 static string numberFormat(double value, int precision = 0, bool forcePrecision = false, char decimal = '.', char thousands = ',') noexcept;
1372
1385 string concat(const string &other) const noexcept {
1386 return *this + other;
1387 }
1388
1399 string operator+(const string &other) const noexcept;
1400
1410 string &operator+=(const string &other) noexcept;
1411
1422 string &operator=(const string &other) noexcept;
1423
1431 bool operator==(const string &other) const noexcept;
1432
1440 bool operator!=(const string &other) const noexcept {
1441 return !operator==(other);
1442 }
1443
1451 bool operator>(const string &other) const noexcept;
1452
1460 bool operator>=(const string &other) const noexcept {
1461 return !operator<(other);
1462 }
1463
1471 bool operator<(const string &other) const noexcept;
1472
1480 bool operator<=(const string &other) const noexcept {
1481 return !operator>(other);
1482 }
1483
1496 string &read(std::istream &stream, uint32_t delim = 0) noexcept;
1497
1508 string &readln(std::istream &stream) noexcept;
1509
1520 string &readall(std::istream &stream) noexcept;
1521
1527 void write(std::ostream &stream) const noexcept {
1528 stream << *this << std::flush;
1529 }
1530
1538 void writeln(std::ostream &stream) const noexcept {
1539 stream << *this << std::endl;
1540 }
1541
1551 return stringIterator<E>(data, 0);
1552 }
1553
1563 return stringIterator<E>(data, character_ct);
1564 }
1565
1566#ifdef __has_include
1567#if __has_include(<cereal/cereal.hpp>)
1568
1574 template <class archive>
1575 std::string save_minimal(archive &ar) const {
1576 (void)ar;
1577 return string<utf8>(*this).cstring();
1578 }
1579
1585 template <class archive>
1586 void load_minimal(archive const &ar, std::string const &value) {
1587 (void)ar;
1588 operator=(value.c_str());
1589 }
1590#endif
1591#endif
1592
1599 friend std::ostream &operator<<(std::ostream &ostr, const z::core::string<E> &str) {
1600 return ostr << string<utf8>(str).cstring();
1601 }
1602
1609 friend std::istream &operator>>(std::istream &istr, z::core::string<E> &str) {
1610 std::string s;
1611 istr >> s;
1612
1613 if (s.length()) {
1614 str = s.c_str(); // not efficient to cast strings back & forth, but it works for now.
1615 }
1616 return istr;
1617 }
1618
1623 inline std::string str() const noexcept {
1624 return string<utf8>(*this).cstring();
1625 }
1626
1632};
1633} // namespace core
1634} // namespace z
1635
1636typedef z::core::string<> zstring;
1637typedef z::core::string<z::utf8> zpath;
1638
1639// Custom literals for simple string construction
1640z::core::string<z::utf32> operator""_u32(char value);
1641z::core::string<z::utf32> operator""_u32(wchar_t value);
1642z::core::string<z::utf32> operator""_u32(const char *value);
1643z::core::string<z::utf32> operator""_u32(const char *value, size_t);
1644z::core::string<z::utf32> operator""_u32(const wchar_t *value, size_t);
1645
1646z::core::string<z::utf16> operator""_u16(char value);
1647z::core::string<z::utf16> operator""_u16(wchar_t value);
1648z::core::string<z::utf16> operator""_u16(const char *value);
1649z::core::string<z::utf16> operator""_u16(const char *value, size_t);
1650z::core::string<z::utf16> operator""_u16(const wchar_t *value, size_t);
1651
1652z::core::string<z::utf8> operator""_u8(char value);
1653z::core::string<z::utf8> operator""_u8(wchar_t value);
1654z::core::string<z::utf8> operator""_u8(const char *value);
1655z::core::string<z::utf8> operator""_u8(const char *value, size_t);
1656z::core::string<z::utf8> operator""_u8(const wchar_t *value, size_t);
1657
1658z::core::string<z::ascii> operator""_asc(char value);
1659z::core::string<z::ascii> operator""_asc(wchar_t value);
1660z::core::string<z::ascii> operator""_asc(const char *value);
1661z::core::string<z::ascii> operator""_asc(const char *value, size_t);
1662z::core::string<z::ascii> operator""_asc(const wchar_t *value, size_t);
1663
1664zstring operator""_zs(char value);
1665zstring operator""_zs(wchar_t value);
1666zstring operator""_zs(const char *value);
1667zstring operator""_zs(const char *value, size_t);
1668zstring operator""_zs(const wchar_t *value, size_t);
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.