![]() |
Max OS 0.3
|
Dynamically sized string with various operations. More...
#include <string.h>
Public Member Functions | |
| String () | |
| Construct a String, 0 length and only contains the null terminator. | |
| String (char c) | |
| Constructs a String from a single character. | |
| String (char const *string) | |
| Constructs a String from a pointer to an array of chars. | |
| String (uint8_t const *string, int length) | |
| Constructs a string from a an array of bytes (doesnt have to be null terminated) | |
| String (String const &other) | |
| Copy constructor for the string. | |
| String (int value) | |
| Constructs a string from an integer (must be base 10) | |
| String (uint64_t value) | |
| Constructs a string from a hex value (Excludes 0x) | |
| String (bool value) | |
| Constructs a String from a boolean as "true" or "false". | |
| ~String () | |
| Destructor for the string, cleans up memory if needed. | |
| void | copy (String const &other) |
| Copies the other string. | |
| size_t | length (bool count_ansi=true) const |
| Returns the length of the string. | |
| char * | c_str () |
| The char pointer representation of the current string. | |
| const char * | c_str () const |
| Returns the string as a c string. | |
| 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 | substring (size_t start, size_t length) const |
| Get a section of the string. | |
| common::Vector< String > | split (String const &delimiter) const |
| Splits the string by the delimiter. | |
| String | strip (char strip_char=' ') const |
| Strips the string of whitespace. | |
| String | center (size_t width, char fill=' ') const |
| Centers the string in a specified width. | |
| bool | equals (String const &other) const |
| Checks if one string is equal to another. | |
| String & | operator= (String const &other) |
| Sets the string to the other string. | |
| String | operator+ (String const &other) const |
| Adds the other string to the string. | |
| String & | operator+= (String const &other) |
| Adds the other string to the string. | |
| String | operator* (int times) const |
| Returns the string repeated a number of times. | |
| bool | operator== (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. | |
| 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 ascii values of the characters in the other string. | |
| 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 ascii values of the characters in the other string. | |
| 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 sum of the ascii values of the characters in the other 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 sum of the ascii values of the characters in the other string. | |
| char & | operator[] (size_t index) |
| Returns the character at the specified index. | |
| char & | operator[] (size_t index) const |
| Returns the character at the specified index. | |
Static Public Member Functions | |
| static String | formatted (char const *format,...) |
| Creates a formated string. s = string, x = hex, d = decimal. | |
| static String | formatted (char const *format, va_list parameters) |
| Creates a formated string. s = string, x = hex, d = decimal. | |
| String::String | ( | ) |
Construct a String, 0 length and only contains the null terminator.
Definition at line 16 of file string.cpp.
| String::String | ( | char | c | ) |
Constructs a String from a single character.
| c | The character |
Definition at line 30 of file string.cpp.
| String::String | ( | char const * | string | ) |
Constructs a String from a pointer to an array of chars.
| string | An array of chars, must be null terminated and of length less than 10,000 |
Definition at line 47 of file string.cpp.
| String::String | ( | uint8_t const * | string, |
| int | length | ||
| ) |
Constructs a string from a an array of bytes (doesnt have to be null terminated)
| string | The string bytes |
| length | How large the string byte buffer is |
Definition at line 74 of file string.cpp.
References length().
| String::String | ( | String const & | other | ) |
Copy constructor for the string.
| other | String to copy from |
Definition at line 146 of file string.cpp.
References copy().
| String::String | ( | int | value | ) |
Constructs a string from an integer (must be base 10)
| value | The integer value |
Definition at line 92 of file string.cpp.
| String::String | ( | uint64_t | value | ) |
Constructs a string from a hex value (Excludes 0x)
| value | The hex value |
Definition at line 113 of file string.cpp.
| String::String | ( | bool | value | ) |
Constructs a String from a boolean as "true" or "false".
| value | The bool value |
Definition at line 132 of file string.cpp.
| String::~String | ( | ) |
Destructor for the string, cleans up memory if needed.
Definition at line 153 of file string.cpp.
| char * String::c_str | ( | ) |
| const char * String::c_str | ( | ) | const |
Returns the string as a c string.
Definition at line 244 of file string.cpp.
| String String::center | ( | size_t | width, |
| char | fill = ' ' |
||
| ) | const |
Centers the string in a specified width.
| width | The width of the string |
| fill | The character to fill the string with |
Definition at line 563 of file string.cpp.
| void String::copy | ( | String const & | other | ) |
Copies the other string.
| other | The other string |
Definition at line 166 of file string.cpp.
References length().
Referenced by operator+=(), operator=(), String(), and strip().
| bool String::equals | ( | String const & | other | ) | const |
Checks if one string is equal to another.
| other | The other string |
Definition at line 375 of file string.cpp.
References length().
Referenced by operator!=(), and operator==().
|
static |
Creates a formated string. s = string, x = hex, d = decimal.
| format | The string containing the format |
| parameters | The arguments to format into the string |
Definition at line 642 of file string.cpp.
|
static |
Creates a formated string. s = string, x = hex, d = decimal.
| format | The string containing the format |
| ... | The arguments to format into the string |
Definition at line 624 of file string.cpp.
References formatted().
Referenced by MaxOS::Logger::ASSERT(), formatted(), and MaxOS::Logger::printf().
| size_t String::length | ( | bool | count_ansi = true | ) | const |
Returns the length of the string.
| count_ansi | Whether to count the ansi characters (default true) |
Definition at line 344 of file string.cpp.
Referenced by copy(), equals(), operator+(), split(), starts_with(), String(), and substring().
| bool String::operator!= | ( | String const & | other | ) | const |
Checks if one string is not equal to another.
| other | The other string |
Definition at line 409 of file string.cpp.
References equals().
| String String::operator* | ( | int | times | ) | const |
Returns the string repeated a number of times.
| times | The number of times to repeat the string |
Definition at line 536 of file string.cpp.
Adds the other string to the string.
| other | The other string |
Definition at line 472 of file string.cpp.
References length().
Adds the other string to the string.
| other | The other string |
Definition at line 500 of file string.cpp.
References copy().
| bool String::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 ascii values of the characters in the other string.
| other | The other string |
Definition at line 424 of file string.cpp.
| bool String::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 sum of the ascii values of the characters in the other string.
| other | The other string |
Definition at line 448 of file string.cpp.
Sets the string to the other string.
| other | The string for this one to be updated to |
Definition at line 218 of file string.cpp.
References copy().
| bool String::operator== | ( | String const & | other | ) | const |
Checks if one string is equal to another.
| other | The other string |
Definition at line 397 of file string.cpp.
References equals().
| bool String::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 ascii values of the characters in the other string.
| other | The other string |
Definition at line 436 of file string.cpp.
| bool String::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 sum of the ascii values of the characters in the other string.
| other | The other string |
Definition at line 460 of file string.cpp.
| char & String::operator[] | ( | size_t | index | ) |
Returns the character at the specified index.
| index | The index of the character |
Definition at line 515 of file string.cpp.
| char & String::operator[] | ( | size_t | index | ) | const |
Returns the character at the specified index.
| index | The index of the character |
Definition at line 526 of file string.cpp.
| common::Vector< String > String::split | ( | String const & | delimiter | ) | const |
Splits the string by the delimiter.
| delimiter | What to split the string by |
Definition at line 308 of file string.cpp.
References length(), and substring().
| bool String::starts_with | ( | String const & | other | ) |
Checks if the string starts with the other string (must contain the same characters in the same order)
| other | The other string |
Definition at line 255 of file string.cpp.
References length().
| String String::strip | ( | char | strip_char = ' ' | ) | const |
Strips the string of whitespace.
| strip_char | The character to strip (default = ' ') |
Definition at line 597 of file string.cpp.
References copy(), and substring().
| String String::substring | ( | size_t | start, |
| size_t | length | ||
| ) | const |
Get a section of the string.
| start | The start of the substring |
| length | The length of the substring |
Definition at line 277 of file string.cpp.
References length(), and substring().
Referenced by split(), strip(), and substring().