NDEVR
API Documentation
String.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: String
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include "DLLInfo.h"
34#include <NDEVR/Buffer.h>
35#include <NDEVR/StringStream.h>
36#include <NDEVR/StringView.h>
37#include <cmath>
38#include <utility>
39namespace NDEVR
40{
41 //Specialized Class to help return correct item
42 template<class t_type>
43 struct FromStringItemReturn
44 {
45 t_type get(const String& s)
46 {
47 t_type value;
48 StringStream<t_type>::fromString(StringView(s), value);
49 return value;
50 }
51 };
52 template<>
53 struct FromStringItemReturn<String>
54 {
55 const String& get(const String& s) { return s; }
56 };
57 template<>
58 struct FromStringItemReturn<StringView>
59 {
60 StringView get(const String& s) { return StringView(s); }
61 };
93
94 class String : public Buffer<char, BufferAllocator<char, 0, true, uint04, true>>
95 {
96 public:
97 friend class StringView;
101 constexpr String() noexcept
102 : Buffer()
103 {}
104
107 constexpr String(const String& string)
108 : Buffer(string)
109 {}
110
114 constexpr explicit String(const StringView& string)
115 : Buffer(string.begin(), string.size())
116 {}
117
121 constexpr String(String&& string) noexcept
122 : Buffer(std::move(string))
123 {
124 //lib_assert(!contains('\0'), "Invalid string");
125 }
126
131 template<std::size_t N>
132 constexpr explicit String(const char (&string)[N])
133 : Buffer(string, str_len(string))
134 {}
135
139 template<std::size_t N>
140 explicit String(const wchar(&string)[N])
141 {
142 addUTF16AsUTF8(string);
143 }
144
149 explicit String(const char* string)
150 : Buffer(string, string == nullptr ? 0 : str_len(string))
151 {}
152
158 constexpr String(const char* const string, uint04 size)
159 : Buffer(string, size)
160 {
161 //lib_assert(!contains('\0'), "Tried to create string with terminator");
162 }
163
169 constexpr String(uint04 size, const char& value)
170 : Buffer(size, value)
171 {}
172
178 template<class t_type>
179 explicit String(const t_type& value);
180
181
187 template<class t_type>
188 [[nodiscard]] decltype(auto) getAs() const
189 {
190 return FromStringItemReturn<t_type>().get(*this);
191 }
192 template<class t_type>
193 void setFrom(const t_type& value)
194 {
195 clear();
196 append(value);
197 }
203 template<class t_type>
204 static TranslatedString DisplayString(const t_type& value);
211 NDEVR_BASE_API bool beginsWith(const StringView& s, bool ignore_case = false) const;
212
219 NDEVR_BASE_API bool endsWith(const StringView& s, bool ignore_case = false) const;
220
227 NDEVR_BASE_API bool hasSubString(const StringView& sub_string, bool ignore_case = false, uint04 start_idx = 0) const;
228
237 NDEVR_BASE_API uint04 indexOf(const StringView& sub_string, bool ignore_case = false, uint04 start_index = 0) const;
238
247 NDEVR_BASE_API uint04 indexOf(const String& sub_string, bool ignore_case = false, uint04 start_index = 0) const;
248
255 NDEVR_BASE_API uint04 indexOf(const char& sub_string) const { return Buffer::indexOf(sub_string); }
256
264 NDEVR_BASE_API uint04 indexOf(const char& sub_string, uint04 start_pos) const { return Buffer::indexOf(sub_string, start_pos); }
265
275 NDEVR_BASE_API uint04 indexOf(const char& sub_string, uint04 start_pos, uint04 size) const { return Buffer::indexOf(sub_string, start_pos, size); }
276
285 NDEVR_BASE_API uint04 indexOf(const char* sub_string, bool ignore_case = false, uint04 start_index = 0) const;
286
297 NDEVR_BASE_API uint04 indexOf(const char* sub_string, bool ignore_case, uint04 start_index, uint04 size) const;
298
308 NDEVR_BASE_API uint04 indexOf(const char* sub_string, char escape_char, bool ignore_case = false, uint04 start_index = 0) const;
309
317 NDEVR_BASE_API uint04 lastIndexOf(const char* sub_string, bool ignore_case = false) const;
318
326 NDEVR_BASE_API uint04 lastIndexOf(const StringView& sub_string, bool ignore_case = false) const;
327
335 NDEVR_BASE_API uint04 lastIndexOf(const char value, bool ignore_case = false) const;
336
345 NDEVR_BASE_API String& replace(const StringView& sub_string, const StringView& replace_sub_string, bool ignore_case = false, uint04 start_index = 0);
346
357 NDEVR_BASE_API String& replace(const StringViewBuffer& sub_string, const StringViewBuffer& replace_sub_string, bool ignore_case = false, uint04 start_index = 0);
358
369 NDEVR_BASE_API String& replace(const StringViewBuffer& sub_string, const StringBuffer& replace_sub_string, bool ignore_case = false, uint04 start_index = 0);
370
383 NDEVR_BASE_API [[nodiscard]] StringViewBuffer split(char delimiter, bool preserve_empty = true) const;
384
385
386 NDEVR_BASE_API [[nodiscard]] StringView splitPart(char delimiter, uint04 index) const;
397 NDEVR_BASE_API [[nodiscard]] StringViewBuffer split(const Buffer<char>& delimiter, bool preserve_empty = true) const;
398
407 NDEVR_BASE_API void splitString(char delimiter, StringViewBuffer& strings, bool preserve_empty = true) const;
408
417 NDEVR_BASE_API void splitString(const Buffer<char>& delimiter, StringViewBuffer& strings, bool preserve_empty = true) const;
418
423 constexpr const char* c_str() const
424 {
425 return Buffer::begin();
426 }
427
433 NDEVR_BASE_API bool isSameNoCase(const StringView& s) const;
434
441 NDEVR_BASE_API bool matchesWildcard(const StringView& pattern) const;
447 NDEVR_BASE_API String& append(const StringView& string);
448
454 NDEVR_BASE_API String& append(char value)
455 {
456 add(value);
457 return *this;
458 }
459
464 template<class t_type>
465 String& append(const t_type& value);
471 template<size_t t_size>
472 inline String& append(const char(&value)[t_size])
473 {
474 addAll(value);
475 return *this;
476 }
477
482 inline String& append(const char* value)
483 {
484 addAll(value);
485 return *this;
486 }
487
492 template<size_t t_size>
493 inline String& append(const wchar(&value)[t_size])
494 {
495 addUTF16AsUTF8(value);
496 return *this;
497 }
498
503 inline String& append(const wchar* value)
504 {
505 addUTF16AsUTF8(value);
506 return *this;
507 }
508
513 inline String& append(const wchar value)
514 {
515 addWChar(value);
516 return *this;
517 }
518
524 constexpr uint08 hash() const
525 {
526 return StringView::hash(c_str());
527 }
528
533 NDEVR_BASE_API uint08 hashUpper() const;
539 NDEVR_BASE_API uint08 hashLower() const;
545 NDEVR_BASE_API StringView substr(uint04 start) const;
553 NDEVR_BASE_API StringView substr(uint04 start, uint04 end) const;
558 NDEVR_BASE_API String& trimWhiteSpace();
569 NDEVR_BASE_API String& addWhiteSpace(uint04 desired_string_size, uint04 desired_right_alignment_location = 0, char whitespace = ' ');
577 NDEVR_BASE_API String& formatNumberString(uint04 decimals);
588 NDEVR_BASE_API String& formatNumberString(bool add_comma, uint04 decimals);
600 NDEVR_BASE_API String& formatNumberString(bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, char decimal = '.', char comma = ',');
605 NDEVR_BASE_API String toTitleString() const;
615 NDEVR_BASE_API String& removeNonAlphaNumeric(bool remove_tab = true, bool remove_space = true, bool remove_new_line = true, bool remove_r = true, bool remove_numbers = false);
620 NDEVR_BASE_API String& removeNonNumeric();
627 NDEVR_BASE_API StringAllocatingView shortenString(uint04 size) const;
634 NDEVR_BASE_API String insertNewLines(uint04 max_line_size) const;
641 NDEVR_BASE_API String predictNextStringIncrement() const;
646 NDEVR_BASE_API StringAllocatingView toUpper() const;
647 NDEVR_BASE_API String& makeUpper(uint04 offset = 0);
652 NDEVR_BASE_API StringAllocatingView toLower() const;
653 NDEVR_BASE_API String& makeLower(uint04 offset = 0);
658 NDEVR_BASE_API bool isNumeric() const;
664 static NDEVR_BASE_API bool IsNumeric(char value);
669 NDEVR_BASE_API uint04 fromHex() const;
675 NDEVR_BASE_API void addUTF16AsUTF8(const wchar* unicode);
683 NDEVR_BASE_API bool addUTF16CharAsUTF8(const wchar* unicode, uint04& advance);
689 void addWChar(const wchar& object);
690
691 String& operator=(const String& value)
692 {
693 Buffer::operator=(value);
694 return *this;
695 }
696
697 String& operator=(String&& value) noexcept
698 {
699 Buffer::operator=(std::move(value));
700 return *this;
701 }
702 String& operator=(const StringView& value)
703 {
704 if (value.begin() == begin())
705 {
706 setSize(value.size());
707 return *this;
708 }
709 if (value.size() > size())
710 setSize(value.size());//this is safe because a stringview referenceing us can't be larger than us
711 memmove(begin(), value.begin(), sizeof(char) * value.size());
712 if (value.size() < size())
713 setSize(value.size());//do this after in case referencing us
714 return *this;
715 }
716 String& operator=(const char* value)
717 {
718 setSize(str_len(value));
719 memmove(begin(), value, sizeof(char) * size());
720 return *this;
721 }
722 template<std::size_t N>
723 String& operator=(const char (&value)[N])
724 {
725 setSize(str_len(value));
726 memmove(begin(), value, sizeof(char) * size());
727 return *this;
728 }
729 template<std::size_t N>
730 String& operator=(const wchar(&value)[N])
731 {
732 clear();
733 addUTF16AsUTF8(value);
734 return *this;
735 }
736 bool operator==(const String& value) const
737 {
738 if (value.size() != size())
739 return false;
740 for (uint04 i = 0; i < size(); i++)
741 {
742 if (value[i] != (*this)[i])
743 return false;
744 }
745 return true;
746 }
747 bool operator==(const StringView& value) const
748 {
749 if (value.size() != size())
750 return false;
751 for (uint04 i = 0; i < size(); i++)
752 {
753 if (value[i] != (*this)[i])
754 return false;
755 }
756 return true;
757 }
758 bool operator==(const char* const value) const
759 {
760 for (uint04 i = 0; i < size(); i++)
761 {
762 if (value[i] != (*this)[i])
763 return false;
764 }
765 return value[size()] == '\0';//check if strings are same size
766 }
767 template<size_t t_size>
768 bool operator==(const char(&string)[t_size])
769 {
770 if (t_size <= size())
771 return false;
772 if (string[size()] != '\0')
773 return false;
774 return memcmp(string, begin(), sizeof(char) * size()) == 0;
775 }
776
777 bool operator!=(const char* const value) const
778 {
779 for (uint04 i = 0; i < size(); i++)
780 {
781 if (value[i] != (*this)[i])
782 return true;
783 }
784 return value[size()] != '\0';//check if strings are same size
785 }
786 template<std::size_t t_size>
787 bool operator!=(const char(&string)[t_size])
788 {
789 if (t_size <= size())
790 return true;
791 if (string[size()] != '\0')
792 return true;
793 return memcmp(string, begin(), sizeof(char) * size()) != 0;
794 }
795 bool operator!=(const String& value) const
796 {
797 if (value.size() != size())
798 return true;
799 for (uint04 i = 0; i < size(); i++)
800 {
801 if (value[i] != (*this)[i])
802 return true;
803 }
804 return false;//check if strings are same size
805 }
806 bool operator!=(const StringView& value) const
807 {
808 if (value.size() != size())
809 return true;
810 for (uint04 i = 0; i < size(); i++)
811 {
812 if (value[i] != (*this)[i])
813 return true;
814 }
815 return false;
816 }
817
818 NDEVR_BASE_API bool operator<(const String& value) const;
819 NDEVR_BASE_API bool operator>(const String& value) const;
820 NDEVR_BASE_API bool isLessNoCase(const StringView& other) const;
821 NDEVR_BASE_API bool isGreaterNoCase(const StringView& other) const;
822 operator StringView() const
823 {
824 return StringView(*this);
825 }
826 public:
831 NDEVR_BASE_API static String ToAlphaString(uint04 number);
838 NDEVR_BASE_API static String UTF16toUTF8(const wchar* unicode, uint04& advance);
844 NDEVR_BASE_API static bool IsWhiteSpace(char s);
857 NDEVR_BASE_API static String NumberString(fltp08 value, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, char decimal = '.', char comma = ',');
867 NDEVR_BASE_API static wchar UTF8toUTF16(const char* utf8, uint04& advance);
873 static constexpr Vector<2, char> ToHexVec(uint01 value)
874 {
875 return Vector<2, char>(BinaryToHexChar(value >> 4), BinaryToHexChar(value & 0x0F));
876 }
877
882 static constexpr Vector<2, char> ToHexVec(char value)
883 {
884 return ToHexVec(rcast<uint01>(value));
885 }
886
887
888
894 static String ToHex(uint01 value)
895 {
896 auto vec = ToHexVec(value);
897 return String({ vec[0], vec[1], '\0'});
898 }
899
904 static String ToHex(char value)
905 {
906 auto vec = ToHexVec(value);
907 return String({ vec[0], vec[1], '\0' });
908 }
909
914 template<class t_object>
915 static typename std::enable_if<ObjectInfo<t_object>::Integer, String>::type ToHex(t_object value)
916 {
917 String hex;
918 uint04 byte_size = cast<uint04>(sizeof(t_object));
919 hex.setSize(2 * byte_size);
920 for (uint04 i = 0; i < byte_size; i++)
921 {
922 auto local_hex = ToHexVec(rcast<uint01>(value % 256));
923 hex[2 * (byte_size - i - 1) + 0] = local_hex[0];
924 hex[2 * (byte_size - i - 1) + 1] = local_hex[1];
925 value /= cast<t_object>(256);
926 }
927 return hex;
928 }
929
934 template<class t_object, class t_allocator>
936 {
937 String hex;
938 hex.ensureCapacity(values.size() * 2 * sizeof(t_object));
939 for (uint04 i = 0; i < values.size(); i++)
940 {
941 hex += ToHex(values[i]);
942 }
943 return hex;
944 }
945
950 static String ToHex(const StringView& values)
951 {
952 String hex;
953 hex.setSize(values.size() * 2);
954 for (uint04 i = 0; i < values.size(); i++)
955 {
956 auto hex_vec = ToHexVec(values[i]);
957 hex[2 * i + 0] = hex_vec[0];
958 hex[2 * i + 1] = hex_vec[1];
959 }
960 return hex;
961 }
962
967 template<uint01 t_size, class t_type>
968 static String ToHex(const Vector<t_size, t_type>& values)
969 {
970 String hex;
971 hex.ensureCapacity(cast<uint04>(t_size) * 2 * sizeof(t_type));
972 for (uint01 i = 0; i < t_size; i++)
973 {
974 hex += ToHex(values[i]);
975 }
976 return hex;
977 }
978
982 NDEVR_BASE_API static bool AlphaNumericCompare(const StringView& left, const StringView& right);
983
989 static constexpr uint04 str_len(const char* value)
990 {
991 const char* n_value = value;
992 for (; *n_value; ++n_value)
993 {
994 }
995 return cast<uint04>(n_value - value);
996 }
997
1004 static constexpr uint04 str_len(const wchar* value)
1005 {
1006 uint04 count = 0;
1007 const wchar* n_value = value;
1008 for (; *n_value; ++n_value)
1009 {
1010 if (*n_value < 0x80)
1011 {
1012 count += 1;
1013 }
1014 else if (*n_value < 0x800)
1015 {
1016 count += 2;
1017 }
1018 else
1019 {
1020 uint04 cp = (*n_value << 16);
1021 ++n_value;
1022 cp += *n_value;
1023 if (cp < 0x10000)
1024 count += 3;
1025 else
1026 count += 4;
1027 }
1028 }
1029 return count;
1030 }
1031#if _MSC_VER
1032#pragma warning( disable : 4307)
1033#endif
1041 static constexpr uint08 hash(const char* value)
1042 {
1043 return StringView::hash(value);
1044 }
1045 private:
1046 static constexpr char BinaryToHexChar(uint01 value)
1047 {
1048 return "0123456789ABCDEF"[value];
1049 }
1050 // The preprocessing function for Boyer Moore's bad character heuristic
1051 static void BadCharHeuristic(const char* str, uint04 size, sint04 badchar[256], bool ignore_case);
1052 static uint04 Search(const char* txt, const char* pat, uint04 size_m, uint04 size_n, bool ignore_case);
1053 };
1054 constexpr StringView::StringView(const String& s)
1055 : m_start(s.c_str())
1056 , m_size(s.size())
1057 {}
1058 inline String operator+(const String& string_a, const String& string_b)
1059 {
1060 String s;
1061 s.ensureCapacity(string_a.size() + string_b.size());
1062 s.addAll(string_a);
1063 s.addAll(string_b);
1064 return s;
1065 }
1066 inline String operator+(const StringView& string_a, const StringView& string_b)
1067 {
1068 String s;
1069 s.ensureCapacity(string_a.size() + string_b.size());
1070 s.append(string_a);
1071 s.append(string_b);
1072 return s;
1073 }
1074 inline String operator+(const StringView& string_a, const String& string_b)
1075 {
1076 String s;
1077 s.ensureCapacity(string_a.size() + string_b.size());
1078 s.append(string_a);
1079 s.addAll(string_b);
1080 return s;
1081 }
1082 inline String operator+(const String& string_a, const StringView& string_b)
1083 {
1084 String s;
1085 s.ensureCapacity(string_a.size() + string_b.size());
1086 s.addAll(string_a);
1087 s.append(string_b);
1088 return s;
1089 }
1090 inline String operator+(String&& v1, const String& v2)
1091 {
1092 v1.addAll(v2);
1093 return std::move(v1);
1094 }
1095 inline String operator+(String&& v1, String&& v2)
1096 {
1097 v1.addAll(v2);
1098 return std::move(v1);
1099 }
1100
1101 inline String operator+(String&& v1, const char*& v2)
1102 {
1103 v1.addAll(v2, cast<uint04>(String::str_len(v2)));
1104 return std::move(v1);
1105 }
1106 inline String operator+(const char*& v1, const String& v2)
1107 {
1108 String s;
1110 s.ensureCapacity(v2.size() + size);
1111 s.addAll(v1, size);
1112 s.addAll(v2);
1113 return s;
1114 }
1115 inline String operator+(const char*& v1, const StringView& v2)
1116 {
1117 String s;
1118 uint04 size = String::str_len(v1);
1119 s.ensureCapacity(v2.size() + size);
1120 s.addAll(v1, size);
1121 s.append(v2);
1122 return s;
1123 }
1124 template<size_t t_size>
1125 inline String operator+(String&& v1, const char(&v2)[t_size])
1126 {
1127 v1.addAll(v2, cast<uint04>(String::str_len(v2)));
1128 return std::move(v1);
1129 }
1130
1131 template<size_t t_size>
1132 inline String operator+(const String& v1, const char(&v2)[t_size])
1133 {
1134 String combined;
1135 uint04 length = String::str_len(v2);
1136 combined.ensureCapacity(v1.size() + length);
1137 combined.append(v1);
1138 combined.addAll(v2, length);
1139 return combined;
1140 }
1141 template<size_t t_size>
1142 inline String operator+(const StringView& v1, const char(&v2)[t_size])
1143 {
1144 String combined;
1145 uint04 length = String::str_len(v2);
1146 combined.ensureCapacity(v1.size() + length);
1147 combined.append(v1);
1148 combined.addAll(v2, length);
1149 return combined;
1150 }
1151 template<size_t t_size>
1152 inline String operator+(const char(&v1)[t_size], const StringView& v2)
1153 {
1154 String combined;
1155 uint04 length = String::str_len(v1);
1156 combined.ensureCapacity(v2.size() + length);
1157 combined.addAll(v1, length);
1158 combined.append(v2);
1159 return combined;
1160 }
1161 inline String operator+(const String& v1, char v2)
1162 {
1163 String s;
1164 s.ensureCapacity(v1.size() + 1);
1165 s.addAll(v1);
1166 s.add(v2);
1167 return s;
1168 }
1169 inline String operator+(const char v1, const String& v2)
1170 {
1171 String s;
1172 s.ensureCapacity(v2.size() + 1);
1173 s.add(v1);
1174 s.addAll(v2);
1175 return s;
1176 }
1177 inline String& operator+=(String& string, const wchar* value)
1178 {
1179 string.addUTF16AsUTF8(value);
1180 return string;
1181 }
1182 inline String& operator+=(String& string, const String& value)
1183 {
1184 string.addAll(value);
1185 return string;
1186 }
1187 inline String& operator+=(String& string, const StringView& value)
1188 {
1189 string.append(value);
1190 return string;
1191 }
1192 template<size_t t_size>
1193 inline String& operator+=(String& v1, const char(&v2)[t_size])
1194 {
1195 v1.addAll(v2);
1196 return v1;
1197 }
1198 inline String& operator+=(String& v1, const char* v2)
1199 {
1200 v1.addAll(v2);
1201 return v1;
1202 }
1203 inline String& operator+=(String& v1, char v2)
1204 {
1205 v1.add(v2);
1206 return v1;
1207 }
1208 template<size_t t_size>
1209 inline String operator+(const char(&v1)[t_size], const String& v2)
1210 {
1211 String s;
1212 uint04 size = String::str_len(v1);
1213 s.ensureCapacity(v2.size() + size);
1214 s.addAll(v1, size);
1215 s.addAll(v2);
1216 return s;
1217 }
1218 template<size_t t_size>
1219 inline bool operator==(const char(&v1)[t_size], const String& v2)
1220 {
1221 return v2 == v1;
1222 }
1223 inline bool operator==(const char*& v1, const String& v2)
1224 {
1225 return v2 == v1;
1226 }
1227 template<size_t t_size>
1228 inline String operator+(const char(&v1)[t_size], String&& v2)
1229 {
1230 String s;
1231 uint04 size = String::str_len(v1);
1232 s.ensureCapacity(v2.size() + size);
1233 s.addAll((char*)v1, size);
1234 s.addAll(v2);
1235 return s;
1236 }
1237 template<class t_to>
1238 constexpr t_to cast(const String& value)
1239 {
1240 return static_cast<t_to>(value.getAs<t_to>());
1241 }
1242 template<>
1243 struct ObjectInfo<String, false, true>
1244 {
1245 static const uint01 Dimensions = 0;
1246 static const bool Vector = false;
1247 static const bool Buffer = true;
1248 static const bool Primitive = false;
1249 static const bool Pointer = false;
1250 static const bool Unsigned = false;
1251 static const bool Float = false;
1252 static const bool Integer = false;
1253 static const bool Number = false;
1254 static const bool Enum = false;
1255 static const bool String = true;
1256 static const bool Color = false;
1257 static const bool Boolean = false;
1258 static constexpr ObjectInfo<char, false, false> VectorSub() { return ObjectInfo<char, false, false>(); }
1259 };
1260
1261 template<> inline const String Constant<String>::Invalid = String();
1262 template<>
1263 constexpr bool IsInvalid(const String& value)
1264 {
1265 return value.size() == 0;
1266 }
1267 template<>
1268 constexpr bool IsValid(const String& value)
1269 {
1270 return value.size() > 0;
1271 }
1277 class StringAllocatingView : public StringView
1278 {
1279 public:
1280 friend class String;
1281 friend class StringAllocation;
1282 constexpr StringAllocatingView()
1283 {}
1284 StringAllocatingView(const StringAllocatingView& other) noexcept
1285 {
1286 if (other.m_allocated_string.size() > 0)
1287 allocate(other);
1288 else
1289 reference(other);
1290 }
1291 template<size_t N>
1292 constexpr StringAllocatingView(const char(&string)[N]) noexcept
1293 : StringView(string, str_len(string))
1294 {}
1295 StringAllocatingView(StringAllocatingView&& other) noexcept
1296 : StringView(other)
1297 {
1298 std::swap(other.m_allocated_string, m_allocated_string);
1299 }
1300 constexpr StringAllocatingView(String&& other) noexcept
1301 : StringView(other)
1302 , m_allocated_string(std::move(other))
1303 {}
1304 template<class t_type>
1305 StringAllocatingView(const t_type& value)
1306 {
1307 StringStream<t_type>::toString(value, *this);
1308 }
1317 NDEVR_BASE_API StringAllocatingView& replace(const StringView& sub_string, const StringView& replace_sub_string, bool ignore_case = false, uint04 start_index = 0);
1318
1329 NDEVR_BASE_API StringAllocatingView& replace(const Buffer<StringView>& sub_string, const Buffer<String>& replace_sub_string, bool ignore_case = false, uint04 start_index = 0);
1330 NDEVR_BASE_API StringAllocatingView& insert(uint04 i, char value);
1331 void clear()
1332 {
1333 m_allocated_string.clear();
1334 m_start = nullptr;
1335 m_size = 0;
1336 }
1337 constexpr void allocate(const StringView& value)
1338 {
1339 m_allocated_string.clear();
1340 m_allocated_string.addAll(value.begin(), value.size());
1341 m_start = m_allocated_string.begin();
1342 m_size = value.size();
1343 }
1344 constexpr void allocate(const String& value)
1345 {
1346 allocate(StringView(value.begin(), value.size()));
1347 }
1348 constexpr void allocate(const StringAllocatingView& value)
1349 {
1350 allocate(StringView(value.begin(), value.size()));
1351 }
1352 template<size_t N>
1353 constexpr void allocate(const char(&string)[N]) noexcept
1354 {
1355 allocate(StringView(string, str_len(string)));
1356 }
1357 template<class t_type>
1358 void allocate(const t_type& value)
1359 {
1360 clear();
1361 StringStream<t_type>::toString(value, *this);
1362 allocate();
1363 }
1364 inline void allocate()
1365 {
1366 if (m_size > 0)
1367 {
1368 if (m_allocated_string.size() == 0)
1369 {
1370 m_allocated_string = *this;
1371 m_start = m_allocated_string.begin();
1372 }
1373 else //clean off end of string for appends
1374 {
1375 uint04 offset = cast<uint04>(m_start - m_allocated_string.begin());
1376 m_allocated_string.setSize(m_size - offset);
1377 }
1378 }
1379 }
1380 inline void allocateWithExtra(uint04 extra_size)
1381 {
1382 if (m_allocated_string.size() == 0)
1383 {
1384 m_allocated_string.ensureCapacity(extra_size + m_size);
1385 m_allocated_string.addAll(begin(), m_size);
1386 m_start = m_allocated_string.begin();
1387 }
1388 else //clean off end of string for appends
1389 {
1390 uint04 offset = cast<uint04>(m_start - m_allocated_string.begin());
1391 uint04 new_allocation_size = cast<uint04>(m_size - offset);
1392 m_allocated_string.ensureCapacity(extra_size + new_allocation_size);
1393 m_allocated_string.setSize(new_allocation_size);
1394 m_start = m_allocated_string.begin();
1395 }
1396 }
1397 void ensureNullTerminated()
1398 {
1399 StringView::ensureNullTerminated(m_allocated_string);
1400 }
1401 StringAllocatingView& operator=(StringAllocatingView&& other) noexcept
1402 {
1403 m_start = other.m_start;
1404 m_size = other.m_size;
1405 std::swap(other.m_allocated_string, m_allocated_string);
1406 return *this;
1407 }
1408 StringAllocatingView& operator=(const StringAllocatingView& other) noexcept
1409 {
1410 if (other.m_allocated_string.size() > 0)
1411 {
1412 allocate(other);
1413 }
1414 else
1415 {
1416 m_start = other.m_start;
1417 m_size = other.m_size;
1418 }
1419 return *this;
1420 }
1421 NDEVR_BASE_API void removeElement(char c, uint04 start);
1422 template<size_t N>
1423 constexpr void reference(const char(&string)[N]) noexcept
1424 {
1425 m_allocated_string.clear();
1426 m_start = string;
1427 m_size = str_len(string);
1428 }
1429 constexpr void reference(const StringView& value)
1430 {
1431 m_allocated_string.clear();
1432 m_start = value.begin();
1433 m_size = value.size();
1434 }
1435 template<class t_type>
1436 void append(const t_type& value)
1437 {
1438 StringStream<t_type>::toString(value, *this);
1439 }
1440 void addSpace(uint04 size)
1441 {
1442 m_allocated_string.addSpace<true>(size);
1443 m_start = m_allocated_string.begin();
1444 m_size += size;
1445 }
1446 void ensureCapacity(uint04 size)
1447 {
1448 m_allocated_string.ensureCapacity(size);
1449 m_start = m_allocated_string.begin();
1450 }
1451 NDEVR_BASE_API StringAllocatingView& makeLower(uint04 offset = 0);
1452 NDEVR_BASE_API StringAllocatingView& makeUpper(uint04 offset = 0);
1453 void append(const char& value)
1454 {
1455 if (m_allocated_string.size() == 0)
1456 allocateWithExtra(1);
1457 m_allocated_string.add(value);
1458 m_start = m_allocated_string.begin();
1459 ++m_size;
1460 }
1461 template<size_t N>
1462 constexpr void append(const char(&string)[N]) noexcept
1463 {
1464 append(StringView(string, str_len(string)));
1465 }
1466 constexpr void append(const StringView& value)
1467 {
1468 if (value.size() == 0)
1469 return;
1470 lib_assert(value.end() < StringView::begin() || value.begin() > StringView::end(), "Cannot append to self" );
1471 if (m_size > 0 && m_allocated_string.size() == 0)
1472 {
1473 allocate();
1474 m_allocated_string.addAll(value.begin(), value.size());
1475 }
1476 else
1477 {
1478 lib_assert(value.end() < m_allocated_string.begin() || value.begin() > m_allocated_string.end(), "Cannot append to self" );
1479 m_allocated_string.addAll(value.begin(), value.size());
1480 }
1481 m_start = m_allocated_string.begin();
1482 m_size += value.size();
1483 }
1484 constexpr void append(const String& value)
1485 {
1486 append(StringView(value));
1487 }
1488 constexpr void append(const StringAllocatingView& value)
1489 {
1490 append(StringView(value));
1491 }
1492 void referencedAppend(const char& value)
1493 {
1494 if (m_size > 0)
1495 {
1496 append(value);
1497 }
1498 else
1499 {
1500 m_start = &value;
1501 m_size = 1U;
1502 }
1503 }
1504 constexpr void referencedAppend(const StringView& value)
1505 {
1506 if (value.size() == 0)
1507 return;
1508 if (m_size > 0)
1509 append(value);
1510 else
1511 reference(value);
1512 }
1513 constexpr void referencedAppend(const String& value)
1514 {
1515 if (value.size() == 0)
1516 return;
1517 if (m_size > 0)
1518 append(value);
1519 else
1520 reference(value);
1521 }
1522 void referencedAppend(const String&& value) = delete;
1523 void referencedAppend(char&& value) = delete;
1524 [[nodiscard]] constexpr char* allocationPtr()
1525 {
1526 lib_assert(m_allocated_string.size() > 0, "Bad Allocation");
1527 return m_allocated_string.begin();
1528 }
1529 [[nodiscard]] constexpr char* allocationPtr(uint04 idx_offset)
1530 {
1531 lib_assert(m_allocated_string.size() > 0, "Bad Allocation");
1532 return m_allocated_string.begin(idx_offset);
1533 }
1534 void replaceIndexRange(uint04 offset, uint04 replace_size, const char* buffer, uint04 buffer_size)
1535 {
1536 allocate();
1537 uint04 reference_offset = cast<uint04>(m_start - m_allocated_string.begin());
1538 lib_assert(offset + replace_size <= size(), "invalid replace");
1539 m_allocated_string.replaceIndexRange(offset + reference_offset, replace_size, buffer, buffer_size);
1540 m_start = m_allocated_string.begin();
1541 m_size = m_allocated_string.size();
1542 }
1543 template<class t_string_type>
1544 static StringAllocatingView Reference(const t_string_type& value)
1545 {
1546 StringAllocatingView view;
1547 view.reference(StringView(value));
1548 return view;
1549 }
1550 template<class t_type>
1551 static StringAllocatingView Allocate(const t_type& value)
1552 {
1553 StringAllocatingView view;
1554 view.allocate(value);
1555 return view;
1556 }
1557 protected:
1558 String m_allocated_string;
1559 };
1560 template<>
1561 struct ObjectInfo<StringAllocatingView, false, false>
1562 {
1563 static const uint01 Dimensions = 0;
1564 static const bool Vector = false;
1565 static const bool Buffer = true;
1566 static const bool Primitive = false;
1567 static const bool Pointer = false;
1568 static const bool Unsigned = false;
1569 static const bool Float = false;
1570 static const bool Integer = false;
1571 static const bool Number = false;
1572 static const bool Enum = false;
1573 static const bool String = true;
1574 static const bool Color = false;
1575 static const bool Boolean = false;
1576 static constexpr ObjectInfo<char, false, false> VectorSub() { return ObjectInfo<char, false, false>(); }
1577 };
1578 template<class t_type>
1579 String::String(const t_type& value)
1580 {
1582 StringStream<t_type>::toString(value, view);
1583 if (view.m_allocated_string.size() > 0)
1584 *this = std::move(view.m_allocated_string);
1585 else if (view.size() > 0)
1586 addAll(view.begin(), view.size());
1587 }
1588 class StringAllocation final
1589 {
1590 public:
1591 explicit StringAllocation(StringAllocatingView& s) noexcept
1592 : m_reference(s)
1593 {
1594 if (s.m_allocated_string.size() > 0)
1595 {
1596 m_start_offset = cast<uint04>(s.m_start - s.m_allocated_string.begin());
1597 }
1598 else
1599 {
1600 m_start_offset = 0;
1601 m_reference.allocate();
1602 }
1603 //lib_assert(m_reference.m_allocated_string.size() == s.size(), "Can only be used with complete allocation");
1604
1605 }
1606
1607 ~StringAllocation() noexcept
1608 {
1609 m_reference.m_start = m_start_offset + m_reference.m_allocated_string.begin();
1610 m_reference.m_size = cast<uint04>(m_reference.m_allocated_string.size() - m_start_offset);
1611 }
1612
1613 operator String&() noexcept { return m_reference.m_allocated_string; }
1614 operator const String&() const noexcept { return m_reference.m_allocated_string; }
1615 String& operator*() noexcept { return m_reference.m_allocated_string; }
1616 const String& operator*() const noexcept { return m_reference.m_allocated_string; }
1617 StringAllocation(const StringAllocation&) = delete;
1618 StringAllocation& operator=(const StringAllocation&) = delete;
1619 StringAllocation(StringAllocation&&) = delete;
1620 StringAllocation& operator=(StringAllocation&&) = delete;
1621 String* operator->() noexcept { return &m_reference.m_allocated_string; }
1622 const String* operator->() const noexcept { return &m_reference.m_allocated_string; }
1623 private:
1624 StringAllocatingView& m_reference;
1625 uint04 m_start_offset = 0;
1626 };
1627 class StringWrappedAllocation : public StringAllocatingView
1628 {
1629 public:
1630 StringWrappedAllocation(String& s)
1631 : reference(s)
1632 {
1633 std::swap(m_allocated_string, reference);
1634 }
1635 ~StringWrappedAllocation()
1636 {
1637 if (m_allocated_string.size() > 0)
1638 reference = std::move(m_allocated_string);
1639 else if (size() > 0)
1640 reference.addAll(begin(), size());
1641 }
1642 String& reference;
1643 };
1644 template<class t_type>
1645 String& String::append(const t_type& value)
1646 {
1648 if(size() > 0)
1649 {
1650 std::swap(view.m_allocated_string, *this);
1651 view.m_start = view.m_allocated_string.begin();
1652 view.m_size = view.m_allocated_string.size();
1653 }
1654 StringStream<t_type>::toString(value, view);
1655 if (view.m_allocated_string.size() > 0)
1656 *this = std::move(view.m_allocated_string);
1657 else if (view.size() > 0)
1658 addAll(view.begin(), view.size());
1659 return *this;
1660 }
1661};
1662
1663
1664namespace std//Define things to allow use within std libs
1665{
1666 template<>
1667 struct equal_to<NDEVR::String>
1668 {
1669 using is_transparent = std::true_type;
1670 bool operator()(const String& a, const StringView& b) const { return a == b; }
1671 bool operator()(const StringView& a, const String& b) const { return a == b; }
1672 bool operator()(const String& a, const String& b) const { return a == b; }
1673 bool operator()(const String& a, const char* b) const { return a == b; }
1674 bool operator()(const char* a, const String& b) const { return a == b; }
1675 template<std::size_t N>
1676 bool operator()(const String& a, const char(&b)[N]) const { return a == b; }
1677 template<std::size_t N>
1678 bool operator()(const char(&a)[N], const String& b) const { return a == b; }
1679 };
1680 template<>
1681 struct equal_to<StringAllocatingView>
1682 {
1683 using is_transparent = std::true_type;
1684 bool operator()(const String& a, const StringView& b) const { return a == b; }
1685 bool operator()(const StringView& a, const String& b) const { return a == b; }
1686 bool operator()(const StringAllocatingView& a, const String& b) const { return a == b; }
1687 bool operator()(const String& a, const StringAllocatingView& b) const { return a == b; }
1688 bool operator()(const StringAllocatingView& a, const StringView& b) const { return a == b; }
1689 bool operator()(const StringView& a, const StringAllocatingView& b) const { return a == b; }
1690 bool operator()(const StringAllocatingView& a, const StringAllocatingView& b) const { return a == b; }
1691 bool operator()(const String& a, const String& b) const { return a == b; }
1692 bool operator()(const StringView& a, const StringView& b) const { return a == b; }
1693 bool operator()(const String& a, const char* b) const { return a == b; }
1694 bool operator()(const char* a, const String& b) const { return a == b; }
1695 template<std::size_t N>
1696 bool operator()(const String& a, const char(&b)[N]) const { return a == b; }
1697 template<std::size_t N>
1698 bool operator()(const char(&a)[N], const String& b) const { return a == b; }
1699 };
1700 template <>
1701 struct hash<String>
1702 {
1703 using is_transparent = std::true_type;
1704 size_t operator()(const String& s) const noexcept
1705 {
1706 return static_cast<size_t>(s.hash());
1707 }
1708 constexpr size_t operator()(const StringView& s) const noexcept
1709 {
1710 return static_cast<size_t>(s.hash());
1711 }
1712 constexpr size_t operator()(const char* s) const noexcept
1713 {
1714 return static_cast<size_t>(String::hash(s));
1715 }
1716 template<size_t N>
1717 constexpr size_t operator()(const char(&s)[N]) const noexcept
1718 {
1719 return static_cast<size_t>(String::hash(s));
1720 }
1721 };
1722 template <>
1723 struct hash<StringAllocatingView>
1724 {
1725 using is_transparent = std::true_type;
1726 size_t operator()(const String& s) const noexcept
1727 {
1728 return static_cast<size_t>(s.hash());
1729 }
1730 constexpr size_t operator()(const StringView& s) const noexcept
1731 {
1732 return static_cast<size_t>(s.hash());
1733 }
1734 constexpr size_t operator()(const StringAllocatingView& s) const noexcept
1735 {
1736 return static_cast<size_t>(s.hash());
1737 }
1738 constexpr size_t operator()(const char* s) const noexcept
1739 {
1740 return static_cast<size_t>(String::hash(s));
1741 }
1742 template<size_t N>
1743 constexpr size_t operator()(const char(&s)[N]) const noexcept
1744 {
1745 return static_cast<size_t>(String::hash(s));
1746 }
1747 };
1748 NDEVR_BASE_API istream& operator>>(istream& in, String& string);
1749 NDEVR_BASE_API ostream& operator<<(ostream& in, const StringView& string);
1750 NDEVR_BASE_API ostream& operator<<(ostream& in, const String& string);
1751};
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
This class is like a string view, but may optionally store the data internally Useful if the return t...
Definition String.h:1278
StringAllocatingView & replace(const Buffer< StringView > &sub_string, const Buffer< String > &replace_sub_string, bool ignore_case=false, uint04 start_index=0)
Replaces ALL instances of the given substrings with the provided replacements.
StringAllocatingView & replace(const StringView &sub_string, const StringView &replace_sub_string, bool ignore_case=false, uint04 start_index=0)
Replaces ALL instances of a given substring with the provided replacement.
static void fromString(const StringView &string, t_type &value)
Logic for converting an object from an NDEVR API String allowing it to be used automatically with get...
static void toString(const t_type &value, StringAllocatingView &string)
Logic for converting an object to an NDEVR API String allowing it to be used automatically with the S...
The core String View class for the NDEVR API.
Definition StringView.h:58
static constexpr uint04 str_len(const char *value)
constexpr method to get the length of a null-terminated string at compile time
Definition StringView.h:723
constexpr const char * end() const
Returns a pointer to one past the last character of the string data.
Definition StringView.h:657
const char * m_start
Pointer to the beginning of the string data.
Definition StringView.h:774
constexpr StringView()
Constructor used to create an empty StringView.
Definition StringView.h:64
constexpr const char * begin() const
Returns a pointer to the beginning of the string data.
Definition StringView.h:640
uint04 m_size
The byte length of the string view.
Definition StringView.h:775
constexpr uint08 hash() const
Creates a simple, quick hash of the object.
Definition StringView.h:330
void ensureNullTerminated(String &s)
This makes the string null terminated, if needed, using the provided string as the new buffer.
constexpr uint04 size() const
Returns the byte size of this string view.
Definition StringView.h:435
The core String class for the NDEVR API.
Definition String.h:95
StringView substr(uint04 start) const
Creates a substring from a given start position, to the end of the string.
constexpr String(const String &string)
Copy Constructor.
Definition String.h:107
String(const wchar(&string)[N])
String Constructor for static wchar arrays of UTF16 data.
Definition String.h:140
StringAllocatingView shortenString(uint04 size) const
Shortens the string to the max size provided.
static constexpr Vector< 2, char > ToHexVec(char value)
Converts the memory of the given object into a hexidecimal string.
Definition String.h:882
static constexpr Vector< 2, char > ToHexVec(uint01 value)
Converts the memory of the given object into a hexidecimal string.
Definition String.h:873
String & append(const char(&value)[t_size])
Appends a string to the back of this string.
Definition String.h:472
String & removeNonNumeric()
Removes anything that is not a number or decimal ('0'-'9' or .).
uint08 hashLower() const
Creates a simple, quick hash of the object.
void splitString(const Buffer< char > &delimiter, StringViewBuffer &strings, bool preserve_empty=true) const
Given multiple delimiter, breaks the string into subsections, and APPENDS each substring to the given...
static constexpr uint08 hash(const char *value)
constexpr method to hash a value.
Definition String.h:1041
constexpr String(uint04 size, const char &value)
String Constructor creates a string of a size and fills it with a character.
Definition String.h:169
uint04 indexOf(const char *sub_string, bool ignore_case, uint04 start_index, uint04 size) const
Given a substring specified by the input, returns the first index of that string, if it exists.
uint04 indexOf(const char *sub_string, bool ignore_case=false, uint04 start_index=0) const
Given a substring specified by the input, returns the first index of that string, if it exists.
String & append(const StringView &string)
Appends a string to the back of this string.
uint04 indexOf(const StringView &sub_string, bool ignore_case=false, uint04 start_index=0) const
Given a substring specified by the input, returns the first index of that string, if it exists.
void addWChar(const wchar &object)
Converts a single unicode character UTF16 character into one or more UTF8 characters and appends them...
String & formatNumberString(bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, char decimal='.', char comma=',')
Modifies the contents of this string, that represents a given number using the provided rules.
static constexpr uint04 str_len(const wchar *value)
constexpr method to get the UTF8 length of a null-terminated string at compile time
Definition String.h:1004
static std::enable_if< ObjectInfo< t_object >::Integer, String >::type ToHex(t_object value)
Converts the memory of the given object into a hexidecimal string.
Definition String.h:915
static wchar UTF8toUTF16(const char *utf8, uint04 &advance)
Converts a unicode null terminated string of chars into a UTF16 wchar and increments advance by the a...
uint04 indexOf(const String &sub_string, bool ignore_case=false, uint04 start_index=0) const
Given a substring specified by the input, returns the first index of that string, if it exists.
StringView substr(uint04 start, uint04 end) const
Creates a substring from a given start position, to the given end position, non-inclusive of the end ...
uint04 fromHex() const
Converts a hex value into an unsigned 4 byte number.
StringViewBuffer split(const Buffer< char > &delimiter, bool preserve_empty=true) const
Given multiple delimiter, breaks the string into subsections, returning an array of each subsection.
String insertNewLines(uint04 max_line_size) const
Finds key areas to insert new lines such that the rows are at most, the length provided.
String & append(const wchar(&value)[t_size])
Appends a string to the back of this string.
Definition String.h:493
constexpr String(const char(&string)[N])
String Constructor for static char arrays.
Definition String.h:132
String & replace(const StringViewBuffer &sub_string, const StringViewBuffer &replace_sub_string, bool ignore_case=false, uint04 start_index=0)
Replaces ALL instances of the given substrings with the provided replacements.
uint04 indexOf(const char &sub_string, uint04 start_pos, uint04 size) const
Given a substring specified by the input, returns the first index of that string, if it exists.
Definition String.h:275
String & formatNumberString(uint04 decimals)
For a string representing a number, makes the decimals equal to the the provided value Example: Strin...
static String ToHex(const Vector< t_size, t_type > &values)
Converts a vector into a hex representation.
Definition String.h:968
decltype(auto) getAs() const
Converts a string into an object.
Definition String.h:188
constexpr const char * c_str() const
Used to access the raw memory of this string.
Definition String.h:423
constexpr uint08 hash() const
Creates a simple, quick hash of the object.
Definition String.h:524
static String ToHex(const Buffer< t_object, t_allocator > &values)
Converts a buffer of objects into a hexidecimal string.
Definition String.h:935
String & append(const wchar *value)
Appends a string to the back of this string.
Definition String.h:503
String & removeNonAlphaNumeric(bool remove_tab=true, bool remove_space=true, bool remove_new_line=true, bool remove_r=true, bool remove_numbers=false)
Removes any characters that aren't numbers or letters with other options available.
static bool IsNumeric(char value)
Checks to see if the char is a numeric string.
String & formatNumberString(bool add_comma, uint04 decimals)
For a string representing a number, makes the decimals equal to the the provided value and adds comma...
static String NumberString(fltp08 value, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, char decimal='.', char comma=',')
Creates a string from a given number using the provided rules.
bool endsWith(const StringView &s, bool ignore_case=false) const
Tests if this String ends with the specified suffix.
uint04 lastIndexOf(const char value, bool ignore_case=false) const
Given a value specified by the input, returns the last index of that char, if it exists.
String & trimWhiteSpace()
Trims any white space (tabs, spaces, etc) from the beginning and end of the string.
static String ToAlphaString(uint04 number)
Converts a number into a char string.
uint08 hashUpper() const
Creates a simple, quick hash of the object.
static String UTF16toUTF8(const wchar *unicode, uint04 &advance)
Converts a single unicode character at advance into UTF8 and and returns it as a String.
static String ToHex(const StringView &values)
Converts a string of any type of data (assumed to be binary) into a hex representation.
Definition String.h:950
constexpr String(const char *const string, uint04 size)
String Constructor char arrays when the size is known.
Definition String.h:158
bool isNumeric() const
Checks to see if the string is a numeric string.
bool hasSubString(const StringView &sub_string, bool ignore_case=false, uint04 start_idx=0) const
Tests if this String contains the specified substring.
bool beginsWith(const StringView &s, bool ignore_case=false) const
Tests if this String starts with the specified prefix.
String predictNextStringIncrement() const
Looks in the string for key markers that might be an index, and attempts to increment the index.
String & append(const char *value)
Appends a string to the back of this string.
Definition String.h:482
bool matchesWildcard(const StringView &pattern) const
Checks whether two strings match allowing '' to be used as a wildcard pattern.
String & replace(const StringViewBuffer &sub_string, const StringBuffer &replace_sub_string, bool ignore_case=false, uint04 start_index=0)
Replaces ALL instances of the given substrings with the provided replacements.
static bool AlphaNumericCompare(const StringView &left, const StringView &right)
Compares two strings given their alpha-numeric determined value.
StringAllocatingView toUpper() const
changes all lower case characters into upper case characters.
constexpr String(String &&string) noexcept
Move contructor (No new memory allocation).
Definition String.h:121
StringAllocatingView toLower() const
changes all upper case characters into lower case characters.
StringViewBuffer split(char delimiter, bool preserve_empty=true) const
Given a delimiter, breaks the string into subsections, returning an array of each subsection.
uint04 indexOf(const char *sub_string, char escape_char, bool ignore_case=false, uint04 start_index=0) const
Given a substring specified by the input, returns the first index of that string, if it exists.
static String ToHex(char value)
Converts the memory of the given object into a hexidecimal string.
Definition String.h:904
static TranslatedString DisplayString(const t_type &value)
Converts an object into a TranslatedString.
bool addUTF16CharAsUTF8(const wchar *unicode, uint04 &advance)
Converts a single unicode character at advance into UTF8 and appends it to the end of the String.
String(const char *string)
String Constructor for null terminated array of chars.
Definition String.h:149
static bool IsWhiteSpace(char s)
Checks whether a given character is a whitespace character or not.
uint04 indexOf(const char &sub_string, uint04 start_pos) const
Given a substring specified by the input, returns the first index of that string, if it exists.
Definition String.h:264
String & replace(const StringView &sub_string, const StringView &replace_sub_string, bool ignore_case=false, uint04 start_index=0)
Replaces ALL instances of a given substring with the provided replacement.
constexpr String() noexcept
Constructor used to create an empty String*.
Definition String.h:101
uint04 indexOf(const char &sub_string) const
Given a substring specified by the input, returns the first index of that string, if it exists.
Definition String.h:255
String toTitleString() const
Formats the string to be a title, capitalizing important characters and replacing underscores with sp...
void addUTF16AsUTF8(const wchar *unicode)
Converts a unicode null terminated string of UTF16 wchars into UTF8 and appends it to the end of the ...
constexpr String(const StringView &string)
Constructor for string view.
Definition String.h:114
void splitString(char delimiter, StringViewBuffer &strings, bool preserve_empty=true) const
Given multiple delimiter, breaks the string into subsections, and APPENDS each substring to the given...
uint04 lastIndexOf(const char *sub_string, bool ignore_case=false) const
Given a substring specified by the input, returns the last index of that string, if it exists.
String & append(char value)
Appends an object to the back of this string.
Definition String.h:454
String & append(const wchar value)
Appends a wchar utf16 to the back of this string as utf8.
Definition String.h:513
bool isSameNoCase(const StringView &s) const
Checks whether two strings match in a case-insensitive way.
static constexpr uint04 str_len(const char *value)
constexpr method to get the length of a null-terminated string at compile time
Definition String.h:989
static String ToHex(uint01 value)
Converts the memory of the given object into a hexidecimal string.
Definition String.h:894
String & addWhiteSpace(uint04 desired_string_size, uint04 desired_right_alignment_location=0, char whitespace=' ')
Used for formatting, will, if necessary, add white space so that the string becomes a certain length.
uint04 lastIndexOf(const StringView &sub_string, bool ignore_case=false) const
Given a substring specified by the input, returns the last index of that string, if it exists.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
Definition Model.h:58
@ Color
Per-vertex RGBA color.
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
Definition Angle.h:398
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
constexpr t_to & rcast(t_from &value)
Casts the given value.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr Angle< t_angle_type > & operator+=(Angle< t_angle_type > &angle, const Angle< t_angle_type > &add)
Addition assignment operator for Angles.
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
Definition Angle.h:388
AlocatingAlignedBuffer< String, sizeof(char *)==4 ? 8 :16 > StringBuffer
A Buffer of String objects using aligned allocation optimized for pointer size.
Definition StringView.h:42
static constexpr Angle< t_type > operator+(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Addition operator.
@ extra_size
An additional size parameter for the effect.
Definition Effect.h:55
wchar_t wchar
Allias for wchar_t, a value that represents a character of two bytes in size.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
STL namespace.
istream & operator>>(istream &in, StringView &string)
Stream extraction operator for reading into an StringView.
Information about the object.
Definition ObjectInfo.h:55