The Pedigree Project
0.1
|
#include <String.h>
Public Member Functions | |
String () | |
String (const char *s) | |
String (const char *s, size_t length) | |
String (const String &x) | |
String (String &&x) | |
String & | operator= (String &&x) |
String & | operator= (const String &x) |
String & | operator= (const char *s) |
operator const char * () const | |
operator StringView () const | |
String & | operator+= (const String &x) |
String & | operator+= (const char *s) |
bool | operator== (const String &s) const |
bool | operator== (const StringView &s) const |
bool | operator== (const char *s) const |
size_t | length () const |
size_t | size () const |
uint32_t | hash () const |
uint32_t | hash () |
size_t | nextCharacter (size_t c) const |
size_t | prevCharacter (size_t c) const |
void | lchomp () |
void | chomp () |
void | strip () |
void | lstrip () |
void | rstrip () |
String | split (size_t offset) |
void | split (size_t offset, String &back) |
Vector< String > | tokenise (char token) |
void | tokenise (char token, Vector< String > &output) const |
void | tokenise (char token, Vector< StringView > &output) const |
void | Format (const char *format,...) FORMAT(printf |
void void | assign (const String &x) |
void | assign (const char *s, size_t len=0, bool unsafe=false) |
void | reserve (size_t size) |
void | free () |
bool | endswith (const char c) const |
bool | endswith (const String &s) const |
bool | endswith (const char *s, size_t len=0) const |
bool | startswith (const char c) const |
bool | startswith (const String &s) const |
bool | startswith (const char *s, size_t len=0) const |
ssize_t | find (const char c) const |
ssize_t | rfind (const char c) const |
String | copy () const |
StringView | view () const |
Static Public Member Functions | |
static size_t | Utf32ToUtf8 (uint32_t utf32, char *utf8) |
Private Member Functions | |
void | reserve (size_t size, bool zero) |
char * | extract () const |
void | computeHash () |
uint32_t | computeHash () const |
void | move (String &&other) |
bool | iswhitespace (const char c) const |
Private Attributes | |
char * | m_Data |
const char * | m_ConstData |
size_t | m_Length |
size_t | m_Size |
char | m_Static [StaticSize] |
bool | m_HeapData |
uint32_t | m_Hash |
Static Private Attributes | |
static constexpr const size_t | StaticSize = 64 |
String::String | ( | ) |
void String::assign | ( | const char * | s, |
size_t | len = 0 , |
||
bool | unsafe = false |
||
) |
Assign a buffer to this string. Optionally, unsafe can be passed which will completely trust the len parameter. This may be useful for cases where the input string is not necessarily known to have a null terminator, as otherwise assign() will attempt to find the length of the given string to reduce memory usage.
Definition at line 290 of file String.cc.
References assert, computeHash(), m_ConstData, m_Data, m_Hash, m_HeapData, m_Length, m_Size, m_Static, and StaticSize.
void String::chomp | ( | ) |
Removes the last character from the string.
Definition at line 660 of file String.cc.
References computeHash(), extract(), m_Data, m_Hash, m_HeapData, m_Length, m_Size, m_Static, and StaticSize.
Referenced by FatDirectory::cacheDirectoryContents().
|
private |
Recompute internal hash.
Definition at line 849 of file String.cc.
References extract(), m_Hash, and m_Length.
Referenced by assign(), chomp(), hash(), lchomp(), lstrip(), move(), rstrip(), StringView::setHashingEnable(), split(), and StringView::substring().
|
private |
String String::copy | ( | ) | const |
bool String::endswith | ( | const char | c | ) | const |
Does this string end with the given string?
Definition at line 710 of file String.cc.
References extract(), and m_Length.
Referenced by UnixSocketSyscalls::bind(), and FatDirectory::cacheDirectoryContents().
|
private |
Extract the correct string buffer for this string.
Definition at line 791 of file String.cc.
References m_ConstData, m_Data, m_HeapData, m_Length, m_Static, and StaticSize.
Referenced by chomp(), computeHash(), endswith(), find(), lchomp(), lstrip(), move(), nextCharacter(), prevCharacter(), rstrip(), split(), startswith(), tokenise(), and view().
ssize_t String::find | ( | const char | c | ) | const |
void String::free | ( | ) |
uint32_t String::hash | ( | ) | const |
Variant of hash() that might compute the hash if needed, but won't update the stored hash.
Definition at line 218 of file String.cc.
References computeHash(), and m_Hash.
Referenced by move(), and StringView::setHashingEnable().
uint32_t String::hash | ( | ) |
Variant of hash() that computes the hash if needed.
Definition at line 228 of file String.cc.
References computeHash(), and m_Hash.
|
private |
void String::lchomp | ( | ) |
Removes the first character from the string.
Definition at line 635 of file String.cc.
References computeHash(), extract(), m_Data, m_Hash, m_HeapData, m_Length, m_Size, m_Static, and StaticSize.
void String::lstrip | ( | ) |
Removes the whitespace from the start of the string.
Definition at line 466 of file String.cc.
References computeHash(), extract(), iswhitespace(), m_Data, m_Hash, m_HeapData, m_Length, m_Size, m_Static, and StaticSize.
Referenced by strip().
|
private |
Move another string into this one.
Definition at line 61 of file String.cc.
References computeHash(), extract(), hash(), m_ConstData, m_Data, m_Hash, m_HeapData, m_Length, m_Size, m_Static, and StaticSize.
Referenced by String().
size_t String::nextCharacter | ( | size_t | c | ) | const |
|
inline |
Allow implicit typecasts to StringView for passing String to functions taking a StringView.
Definition at line 85 of file String.h.
References FORMAT, and operator==().
size_t String::prevCharacter | ( | size_t | c | ) | const |
Given a character index, return the index of the previous character, interpreting the string as UTF-8 encoded.
Definition at line 244 of file String.cc.
References assert, ERROR, extract(), m_ConstData, m_Data, m_Hash, m_HeapData, m_Length, m_Size, m_Static, and StaticSize.
|
private |
Internal doer for reserve()
Definition at line 368 of file String.cc.
References m_Data, m_HeapData, m_Size, m_Static, and StaticSize.
void String::rstrip | ( | ) |
Removes the whitespace from the end of the string.
Definition at line 501 of file String.cc.
References computeHash(), extract(), iswhitespace(), m_Data, m_Hash, m_HeapData, m_Length, m_Size, m_Static, and StaticSize.
Referenced by FatFilesystem::convertFilenameTo(), Symlink::initialise(), and strip().
String String::split | ( | size_t | offset | ) |
Splits the string at the given offset - the front portion will be kept in this string, the back portion (including the character at 'offset' will be returned in a new string.
Definition at line 418 of file String.cc.
References computeHash(), extract(), free(), m_Data, m_Hash, m_HeapData, m_Length, m_Size, m_Static, and StaticSize.
bool String::startswith | ( | const char | c | ) | const |
void String::strip | ( | ) |
void String::tokenise | ( | char | token, |
Vector< StringView > & | output | ||
) | const |
No-copy version of tokenise() that provides views instead of Strings
Definition at line 579 of file String.cc.
References Vector< T >::clear(), extract(), m_Length, Vector< T >::pushBack(), and view().
|
static |
Converts a UTF-32 character to its UTF-8 representation.
[in] | utf32 | Input UTF-32 character. |
[out] | utf8 | Pointer to a buffer at least 6 bytes long. |
Definition at line 543 of file String.cc.
Referenced by TextIO::translate().
StringView String::view | ( | ) | const |
Get a StringView of this String.
Definition at line 880 of file String.cc.
References extract(), m_Hash, and m_Length.
Referenced by Filesystem::find(), VFS::find(), VFS::lookupFilesystem(), StringView::setHashingEnable(), tokenise(), and UnixSocket::writeBytewise().
|
private |
|
private |
|
private |
Hash of the string.
Definition at line 219 of file String.h.
Referenced by assign(), chomp(), computeHash(), free(), hash(), lchomp(), lstrip(), move(), prevCharacter(), rstrip(), StringView::setHashingEnable(), split(), StringView::substring(), and view().
|
private |
|
private |
The string's length
Definition at line 208 of file String.h.
Referenced by assign(), chomp(), StringView::compare(), computeHash(), endswith(), extract(), find(), free(), lchomp(), lstrip(), move(), prevCharacter(), rstrip(), StringView::setHashingEnable(), split(), startswith(), StringView::substring(), tokenise(), and view().
|
private |
The size of the reserved space for the string
Definition at line 210 of file String.h.
Referenced by assign(), chomp(), free(), ProcFs::initialise(), lchomp(), lstrip(), move(), prevCharacter(), reserve(), PciDevicesFile::resync(), rstrip(), and split().
|
private |
|
staticprivate |