38 m_string[m_length] =
'\0';
51 while (
string[m_length] !=
'\0' && m_length <= 10000)
56 for (
size_t i = 0; i < m_length; i++)
57 m_string[i] =
string[i];
60 const char* warning =
"MAXOS: String length exceeded 10000 - might be a bug";
62 for (
int i = 0; i < 52; i++)
63 m_string[m_length - 52 + i] = warning[i];
65 m_string[m_length] =
'\0';
80 for (
int i = 0; i <
length; i++)
81 m_string[i] =
string[i];
95 const char* str =
itoa(10, value);
102 for (
size_t i = 0; i < m_length; i++)
103 m_string[i] = str[i];
104 m_string[m_length] =
'\0';
116 const char* str =
htoa(value);
123 for (
size_t i = 0; i < m_length; i++)
124 m_string[i] = str[i];
125 m_string[m_length] =
'\0';
169 m_length = other.
length();
173 for (
size_t i = 0; i < m_length; i++)
174 m_string[i] = other[i];
177 m_string[m_length] =
'\0';
187int String::lex_value(
String const&
string) {
191 for (
size_t i = 0; i <
string.length(); i++)
200void String::allocate_self() {
203 if (m_string && !m_using_small)
208 m_string = m_using_small ? m_small_string :
new char[m_length + 1];
258 if (m_length < other.
length())
262 for (
size_t i = 0; i < other.
length(); i++)
263 if (m_string[i] != other[i])
280 if (start >= m_length)
284 if (start +
length > m_length)
293 for (
size_t i = 0; i <
length; i++)
294 substring.m_string[i] = m_string[start + i];
313 for (
size_t i = 0; i <= m_length - delimiter.
length(); i++) {
317 for (
size_t j = 0; j < delimiter.
length(); j++)
318 if (m_string[i + j] != delimiter[j]) {
327 strings.push_back(
substring(start, i - start));
328 start = i + delimiter.
length();
329 i += delimiter.
length() - 1;
333 strings.push_back(
substring(start, m_length - start));
351 int total_length = 0;
352 int clean_length = 0;
353 while (m_string[total_length] !=
'\0') {
356 if (m_string[total_length] ==
'\033')
357 while (m_string[total_length] !=
'm')
378 if (m_length != other.
length())
382 for (
size_t i = 0; i < m_length; i++)
383 if (m_string[i] != other[i])
426 return lex_value(*
this) < lex_value(other);
438 return lex_value(*
this) > lex_value(other);
450 return lex_value(*
this) <= lex_value(other);
462 return lex_value(*
this) >= lex_value(other);
476 concatenated.m_length = m_length + other.
length();
477 concatenated.allocate_self();
480 for (
size_t i = 0; i < m_length; i++)
481 concatenated.m_string[i] = m_string[i];
484 for (
size_t i = 0; i < other.
length(); i++)
485 concatenated.m_string[m_length + i] = other[i];
488 concatenated.m_string[concatenated.m_length] =
'\0';
503 String concatenated = *
this + other;
516 return m_string[index];
527 return m_string[index];
540 repeated.m_length = m_length * times;
541 repeated.allocate_self();
544 for (
int i = 0; i < times; i++)
545 for (
size_t j = 0; j < m_length; j++)
546 repeated.m_string[i * m_length + j] = m_string[j];
549 repeated.m_string[repeated.m_length] =
'\0';
566 size_t add = (width - m_length) / 2;
570 centered.m_length = width;
571 centered.allocate_self();
574 for (
size_t i = 0; i < add; i++)
575 centered.m_string[i] = fill;
578 for (
size_t i = 0; i < m_length; i++)
579 centered.m_string[add + i] = m_string[i];
582 for (
size_t i = add + m_length; i < width; i++)
583 centered.m_string[i] = fill;
586 centered.m_string[width] =
'\0';
601 stripped.
copy(*
this);
604 size_t end = m_length - 1;
605 while (end >= 0 && (m_string[end] == strip_char || m_string[end] ==
'\n' || m_string[end] ==
'\t'))
628 va_start(parameters, format);
647 for (; *format !=
'\0'; format++) {
650 if (*format !=
'%') {
651 out += (
string) (
char) (*format);
660 int number = va_arg (parameters,
int);
666 uint64_t number = va_arg (parameters, uint64_t);
672 char* str = va_arg (parameters,
char*);
691 for (; str[len] !=
'\0'; len++);
703char*
itoa(
int base, int64_t number) {
706 static char buffer[50] = { 0 };
709 bool is_negative = number < 0;
721 for (; number && i; --i, number /= base)
722 buffer[i] =
"0123456789ABCDEF"[number % base];
729 return &buffer[i + 1];
740 static char buffer[50] = { 0 };
752 for (; number && i; --i, number /= 16)
753 buffer[i] =
"0123456789ABCDEF"[number % 16];
755 return &buffer[i + 1];
765bool strcmp(
char const* str1,
char const* str2) {
768 for (
int i = 0; str1[i] !=
'\0' || str2[i] !=
'\0'; i++)
769 if (str1[i] != str2[i])
826bool strncmp(
char const* str1,
char const* str2,
int length) {
829 for (
int i = 0; i < length; i++)
830 if (str1[i] != str2[i])
Creates a string using a using a combination of parts with the '<<' operator. Simmilar to the logger.
StringBuilder & operator<<(char const *str)
Append C-string to the StringBuilder.
String out
The output string.
Dynamically sized string with various operations.
String operator+(String const &other) const
Adds the other string to the string.
bool operator>=(String const &other) const
Checks if the sum of the ascii values of the characters in the string is greater than or equal to the...
bool operator<(String const &other) const
Checks if the sum of the ascii values of the characters in the string is less than the sum of the asc...
bool operator==(String const &other) const
Checks if one string is equal to another.
String strip(char strip_char=' ') const
Strips the string of whitespace.
bool operator<=(String const &other) const
Checks if the sum of the ascii values of the characters in the string is less than or equal to the su...
static String formatted(char const *format,...)
Creates a formated string. s = string, x = hex, d = decimal.
bool operator>(String const &other) const
Checks if the sum of the ascii values of the characters in the string is greater than the sum of the ...
String center(size_t width, char fill=' ') const
Centers the string in a specified width.
void copy(String const &other)
Copies the other string.
common::Vector< String > split(String const &delimiter) const
Splits the string by the delimiter.
String substring(size_t start, size_t length) const
Get a section of the string.
size_t length(bool count_ansi=true) const
Returns the length of the string.
String()
Construct a String, 0 length and only contains the null terminator.
bool starts_with(String const &other)
Checks if the string starts with the other string (must contain the same characters in the same order...
String & operator=(String const &other)
Sets the string to the other string.
String operator*(int times) const
Returns the string repeated a number of times.
bool equals(String const &other) const
Checks if one string is equal to another.
bool operator!=(String const &other) const
Checks if one string is not equal to another.
~String()
Destructor for the string, cleans up memory if needed.
String & operator+=(String const &other)
Adds the other string to the string.
char * c_str()
The char pointer representation of the current string.
char & operator[](size_t index)
Returns the character at the specified index.
Stores the left, top, width and height of a rectangle.
Defines a String class for dynamically sized strings with various operations.
char * itoa(int base, int64_t number)
Converts integer to string.
constexpr int MAX_STRING_SMALL_STORAGE
How many characters can be stored in the small string optimization array.
class MaxOS::String string
Typedef for String.
bool strcmp(char const *str1, char const *str2)
Checks if one string pointer is equal to another string pointer.
bool strncmp(char const *str1, char const *str2, int length)
Checks if one string pointer is equal to another string pointer up to a specified length (each must b...
char * htoa(uint64_t number)
Converts hex to string.
int strlen(const char *str)
Gets the length of a string.