FreeNOS
|
Abstraction of strings. More...
#include <String.h>
Public Member Functions | |
String () | |
Default constructor. More... | |
String (const String &str) | |
Copy constructor. More... | |
String (char *s, const bool copy=true) | |
Constructor. More... | |
String (const char *s, const bool copy=false) | |
Constant constructor. More... | |
String (const int number) | |
Signed integer constructor. More... | |
virtual | ~String () |
Destructor. More... | |
virtual Size | size () const |
Calculates the length of the String. More... | |
virtual Size | count () const |
Number of characters in the string. More... | |
Size | length () const |
Same as count(). More... | |
virtual bool | resize (const Size size) |
Change the size of the String buffer. More... | |
virtual bool | reserve (const Size count) |
Make sure at least given number of bytes available. More... | |
virtual const char * | get (const Size position) const |
Returns the item at the given position. More... | |
virtual const char & | at (const Size position) const |
Returns a reference to the item at the given position. More... | |
virtual const char | value (const Size position) const |
Return value at the given position. More... | |
virtual bool | contains (const char character) const |
Check if the given character occurs in the String. More... | |
bool | startsWith (const String &prefix) const |
Tests if this String starts with the specified prefix. More... | |
bool | startsWith (const char *prefix) const |
Tests if this String starts with the specified prefix. More... | |
bool | endsWith (const String &suffix) const |
Tests if this String ends with the specified suffix. More... | |
bool | endsWith (const char *suffix) const |
Tests if this String ends with the specified suffix. More... | |
virtual int | compareTo (const String &str) const |
Compares this String to the given String. More... | |
virtual int | compareTo (const String &str, const bool caseSensitive=true) const |
Compare with another String. More... | |
virtual int | compareTo (const char *str, const bool caseSensitive=true, const Size count=0) const |
Compare with a character string. More... | |
virtual bool | equals (const String &str) const |
Alias for compareTo(). More... | |
bool | match (const char *mask) const |
Matches the String against a mask. More... | |
String | substring (const Size index, const Size size=0) const |
Returns a part of the String as a copy. More... | |
List< String > | split (const char delimiter) const |
Split the String into parts separated by a delimiter. More... | |
List< String > | split (const String &delimiter) const |
Split the String into parts separated by a delimiter. More... | |
long | toLong (const Number::Base base=Number::Dec) const |
Convert the String to a signed long integer. More... | |
String & | pad (const Size length) |
Pad line with trailing whitespace. More... | |
String & | trim () |
Remove leading and trailing whitespace from the String. More... | |
String & | lower () |
Convert all Characters to lower case. More... | |
String & | upper () |
Convert all Characters to upper case. More... | |
Size | set (const long number, const Number::Base base=Number::Dec, char *string=ZERO) |
Set text-representation of a signed number. More... | |
Size | setUnsigned (const ulong number, const Number::Base base=Number::Dec, char *string=ZERO, const bool sign=false) |
Set text-representation of an unsigned number. More... | |
void | operator= (const char *str) |
Assignment operator. More... | |
void | operator= (const String &str) |
Assignment operator. More... | |
bool | operator== (const String &str) const |
Comparision operator. More... | |
bool | operator!= (const String &str) const |
Inequal operator. More... | |
const char * | operator* () const |
Dereference operator (read-only). More... | |
char * | operator* () |
Dereference operator. More... | |
String & | operator<< (const char *str) |
Append character string to the String. More... | |
String & | operator<< (const String &str) |
Append String to another String. More... | |
String & | operator<< (const int number) |
Append the given signed number as text to the String. More... | |
String & | operator<< (const unsigned int number) |
Append the given unsigned number as text to the String. More... | |
String & | operator<< (const void *pointer) |
Append the pointer as hexidecimal unsigned number to the String. More... | |
String & | operator<< (const Number::Base format) |
Change the default number format representation. More... | |
Public Member Functions inherited from Sequence< char > | |
virtual int | insert (const char &item) |
Adds the given item to the Sequence, if possible. More... | |
virtual bool | insert (Size position, const char &item) |
Inserts the given item at the given position. More... | |
virtual void | fill (char value) |
Fill the Sequence with the given value. More... | |
virtual int | remove (char value) |
Remove all items with the given value. More... | |
virtual bool | removeAt (Size position) |
Removes the item at the given position. More... | |
virtual void | clear () |
Removes all items from the Sequence. More... | |
virtual int | compareTo (const Sequence< char > &s) const |
Compare this Sequence to another Sequence. More... | |
virtual bool | equals (const Sequence< char > &s) const |
Test if this Sequence is equal to an other Sequence. More... | |
const char & | operator[] (int i) const |
Returns the item at the given position in the Sequence. More... | |
const char & | operator[] (Size i) const |
Returns the item at the given position in the Sequence. More... | |
char & | operator[] (int i) |
Returns the item at the given position in the Sequence. More... | |
char & | operator[] (Size i) |
Returns the item at the given position in the Sequence. More... | |
Public Member Functions inherited from Container | |
Container () | |
Constructor. More... | |
virtual | ~Container () |
Destructor. More... | |
virtual bool | isEmpty () const |
Check if the Container is empty. More... | |
virtual bool | shrink (Size size) |
Shrink the container size by the given amount of items. More... | |
virtual Size | squeeze () |
Try to minimize the memory required in the Container. More... | |
Public Member Functions inherited from Comparable< Sequence< char > > | |
virtual | ~Comparable () |
Class destructor. More... | |
Static Public Member Functions | |
static Size | length (char *str) |
Get the length of the given character string. More... | |
static Size | length (const char *str) |
Get the length of a constant character string. More... | |
Private Attributes | |
char * | m_string |
Current value of the String. More... | |
Size | m_size |
Size of the string buffer, including any NULL byte(s) at the end. More... | |
Size | m_count |
Length of the string text, excluding NULL byte(s) at the end. More... | |
bool | m_allocated |
True if the string buffer is a deep copy, false otherwise. More... | |
Number::Base | m_base |
Number format to use for convertions. More... | |
String::String | ( | ) |
Default constructor.
Constructs an empty string with the default size.
Definition at line 22 of file String.cpp.
References Number::Dec, m_allocated, m_base, m_count, m_size, m_string, STRING_DEFAULT_SIZE, and ZERO.
String::String | ( | const String & | str | ) |
Copy constructor.
str | String reference. |
Definition at line 32 of file String.cpp.
References MemoryBlock::copy(), m_allocated, m_base, m_count, m_size, and m_string.
String::String | ( | char * | s, |
const bool | copy = true |
||
) |
Constructor.
s | Initial value of the String. |
copy | If true allocate and copy the input buffer. |
Definition at line 42 of file String.cpp.
References MemoryBlock::copy(), copy(), Number::Dec, length(), m_allocated, m_base, m_count, m_size, m_string, and STRING_DEFAULT_SIZE.
String::String | ( | const char * | s, |
const bool | copy = false |
||
) |
Constant constructor.
s | Initial value of the String. |
copy | If true allocate and copy the input buffer. |
Definition at line 58 of file String.cpp.
References MemoryBlock::copy(), copy(), Number::Dec, length(), m_allocated, m_base, m_count, m_size, m_string, and STRING_DEFAULT_SIZE.
String::String | ( | const int | number | ) |
Signed integer constructor.
Creates a String with the textual representation of the given signed integer.
number | Integer number of the new String. |
Definition at line 74 of file String.cpp.
References Number::Dec, m_allocated, m_base, m_count, m_size, m_string, set(), STRING_DEFAULT_SIZE, and ZERO.
|
virtual |
|
virtual |
Returns a reference to the item at the given position.
position | Valid index inside this array. |
Implements Sequence< char >.
Definition at line 170 of file String.cpp.
References m_string.
|
virtual |
Compare with a character string.
str | Character string to compare against. |
caseSensitive | True if uppercase characters are considered not equal to lowercase, false otherwise. |
count | Number of character to compare or ZERO for whole strings. |
Definition at line 241 of file String.cpp.
References count(), Character::lower(), and m_string.
|
virtual |
Compares this String to the given String.
str | The String to compare us to. |
Definition at line 231 of file String.cpp.
Referenced by compareTo(), equals(), FileSystemClient::findMount(), Directory::get(), NetworkClient::initialize(), operator!=(), operator==(), FileSystemServer::redirectRequest(), and Directory::remove().
|
virtual |
Compare with another String.
str | String instance to compare against. |
caseSensitive | True if uppercase characters are considered not equal to lowercase, false otherwise. |
Definition at line 236 of file String.cpp.
References compareTo(), and m_string.
|
virtual |
Check if the given character occurs in the String.
character | The character to search for. |
Reimplemented from Sequence< char >.
Definition at line 180 of file String.cpp.
|
virtual |
Number of characters in the string.
Implements Container.
Definition at line 100 of file String.cpp.
References m_count.
Referenced by compareTo(), length(), and reserve().
bool String::endsWith | ( | const char * | suffix | ) | const |
bool String::endsWith | ( | const String & | suffix | ) | const |
Tests if this String ends with the specified suffix.
suffix | The suffix String. |
Definition at line 210 of file String.cpp.
References m_string.
Referenced by Decompress::decompressFile(), and DirectoryScanner::scan().
|
virtual |
Alias for compareTo().
str | String instance to compare against |
Definition at line 262 of file String.cpp.
References compareTo(), and m_string.
Referenced by ArgumentContainer::get(), LinnDirectory::getLinnDirectoryEntry(), BootSymbolStorage::loadSymbol(), and ProcessClient::processInfo().
|
virtual |
Returns the item at the given position.
position | The position of the item to get. |
Implements Sequence< char >.
Definition at line 165 of file String.cpp.
Size String::length | ( | ) | const |
Same as count().
Definition at line 105 of file String.cpp.
References count().
Referenced by chdir(), Decompress::decompressFile(), endsWith(), ProcessList::exec(), WriteCommand::execute(), FileSystemServer::findFileCache(), FileSystemClient::findMount(), FileSystemServer::getParentDirectory(), hash(), NetworkClient::initialize(), FileSystemServer::insertFileCache(), FileSystemPath::length(), length(), operator<<(), operator=(), pad(), ArgumentParser::parse(), ListFiles::printFiles(), FileSystemServer::processRequest(), PseudoFile::PseudoFile(), UDPFactory::read(), ICMPFactory::read(), FileSystemServer::redirectRequest(), MpiHost::startProcesses(), startsWith(), String(), and DeviceLog::write().
|
static |
Get the length of the given character string.
str | Input string |
Definition at line 110 of file String.cpp.
References length().
|
static |
Get the length of a constant character string.
str | Input string |
Definition at line 115 of file String.cpp.
String & String::lower | ( | ) |
Convert all Characters to lower case.
Definition at line 386 of file String.cpp.
References Character::lower(), m_count, m_string, and reserve().
bool String::match | ( | const char * | mask | ) | const |
Matches the String against a mask.
mask | Pattern to match against. |
Definition at line 267 of file String.cpp.
References Character::isWildcard(), m_string, and ZERO.
Referenced by LinnCreate::insertDirectory().
bool String::operator!= | ( | const String & | str | ) | const |
Inequal operator.
str | Input string |
Definition at line 639 of file String.cpp.
References compareTo().
char* String::operator* | ( | ) |
Dereference operator.
char * String::operator* | ( | ) | const |
String & String::operator<< | ( | const char * | str | ) |
Append character string to the String.
Definition at line 654 of file String.cpp.
References MemoryBlock::copy(), length(), m_count, m_string, reserve(), and ZERO.
Referenced by operator<<().
String & String::operator<< | ( | const int | number | ) |
String & String::operator<< | ( | const Number::Base | format | ) |
Change the default number format representation.
Definition at line 697 of file String.cpp.
References m_base.
Append String to another String.
Definition at line 667 of file String.cpp.
References m_string, and operator<<().
String & String::operator<< | ( | const unsigned int | number | ) |
Append the given unsigned number as text to the String.
Definition at line 681 of file String.cpp.
References m_base, m_count, m_string, reserve(), and setUnsigned().
String & String::operator<< | ( | const void * | pointer | ) |
Append the pointer as hexidecimal unsigned number to the String.
Definition at line 689 of file String.cpp.
References Number::Hex, m_count, m_string, reserve(), and setUnsigned().
void String::operator= | ( | const char * | str | ) |
Assignment operator.
str | Constant string. |
Definition at line 610 of file String.cpp.
References MemoryBlock::copy(), length(), m_count, m_string, reserve(), and ZERO.
void String::operator= | ( | const String & | str | ) |
Assignment operator.
str | Input string |
Definition at line 622 of file String.cpp.
References MemoryBlock::copy(), length(), m_count, m_string, reserve(), and ZERO.
bool String::operator== | ( | const String & | str | ) | const |
Comparision operator.
str | Input string |
Definition at line 634 of file String.cpp.
References compareTo().
Pad line with trailing whitespace.
This function ensures the last line inside the String is at least the given length in characters, by appending extra whitespace at the end of the line.
length | Length of the String including whitespace pads |
Definition at line 332 of file String.cpp.
References length(), m_count, m_string, reserve(), MemoryBlock::set(), and ZERO.
Referenced by ListFiles::printSingleFile().
|
virtual |
Make sure at least given number of bytes available.
count | The number of free bytes to guarantee. |
Reimplemented from Container.
Definition at line 157 of file String.cpp.
References count(), m_allocated, m_size, and resize().
Referenced by lower(), operator<<(), operator=(), pad(), setUnsigned(), trim(), and upper().
|
virtual |
Change the size of the String buffer.
size | New size of the String. |
Reimplemented from Container.
Definition at line 125 of file String.cpp.
References MemoryBlock::copy(), m_allocated, m_count, m_size, m_string, size(), and ZERO.
Referenced by reserve().
Size String::set | ( | const long | number, |
const Number::Base | base = Number::Dec , |
||
char * | string = ZERO |
||
) |
Set text-representation of a signed number.
number | Number value to use |
base | Numeric base of the given value |
string | Destination character string buffer or ZERO to fill internal String buffer. |
Definition at line 533 of file String.cpp.
References setUnsigned().
Referenced by itoa(), operator<<(), LogLevelFile::read(), and String().
Size String::setUnsigned | ( | const ulong | number, |
const Number::Base | base = Number::Dec , |
||
char * | string = ZERO , |
||
const bool | sign = false |
||
) |
Set text-representation of an unsigned number.
number | Input number. |
base | Numberal base type. |
string | Destination character string buffer or ZERO to fill internal String buffer. |
sign | Threat input number as signed. |
Definition at line 538 of file String.cpp.
References Number::Dec, Number::Hex, m_count, m_string, reserve(), and STRING_DEFAULT_SIZE.
Referenced by operator<<(), set(), and vsnprintf().
|
virtual |
Calculates the length of the String.
Implements Container.
Definition at line 95 of file String.cpp.
References m_size.
Referenced by resize(), and substring().
Split the String into parts separated by a delimiter.
delimiter | Character to use a delimiter. |
Definition at line 408 of file String.cpp.
References ZERO.
Referenced by Shell::exec(), ArgumentParser::parse(), MpiHost::parseHostsFile(), RecoveryServer::restartProcess(), MpiProxy::startLocalProcess(), MpiProxy::startRemoteProcess(), and IPV4::toAddress().
Split the String into parts separated by a delimiter.
delimiter | String which acts as a delimiter. |
Definition at line 416 of file String.cpp.
References List< T >::append(), copy(), m_count, m_string, and substring().
bool String::startsWith | ( | const char * | prefix | ) | const |
bool String::startsWith | ( | const String & | prefix | ) | const |
Tests if this String starts with the specified prefix.
prefix | String prefix. |
Definition at line 189 of file String.cpp.
References m_string.
Returns a part of the String as a copy.
This function copies the input starting from index (inclusive), and copies at most size characters.
index | The begin index to create the substring of. |
size | The maximum size of the substring. |
Definition at line 314 of file String.cpp.
References m_count, m_string, size(), and ZERO.
Referenced by Decompress::decompressFile(), ArgumentParser::parse(), and split().
long String::toLong | ( | const Number::Base | base = Number::Dec | ) | const |
Convert the String to a signed long integer.
base | NumberBase to use. Default is decimal. |
Definition at line 456 of file String.cpp.
References Number::Dec, Number::Hex, Character::isAlpha(), Character::isDigit(), Character::isUpper(), Character::isWhitespace(), LONG_MAX, LONG_MIN, and m_string.
Referenced by atoi(), NetSend::exec(), NetSend::initialize(), MpiTarget::initializeSlave(), main(), strtol(), IPV4::toAddress(), and LogLevelFile::write().
String & String::trim | ( | ) |
Remove leading and trailing whitespace from the String.
Definition at line 357 of file String.cpp.
References MemoryBlock::copy(), Character::isWhitespace(), m_count, m_string, and reserve().
String & String::upper | ( | ) |
Convert all Characters to upper case.
Definition at line 397 of file String.cpp.
References m_count, m_string, reserve(), and Character::upper().
|
virtual |
Return value at the given position.
If position is not within bounds of this array, this function will return a default constructed T.
position | Index inside this array. |
Definition at line 175 of file String.cpp.
References m_string.
|
private |
|
private |
Number format to use for convertions.
Definition at line 460 of file String.h.
Referenced by operator<<(), and String().
|
private |
Length of the string text, excluding NULL byte(s) at the end.
Definition at line 454 of file String.h.
Referenced by contains(), count(), endsWith(), get(), lower(), operator<<(), operator=(), pad(), resize(), setUnsigned(), split(), startsWith(), String(), substring(), trim(), and upper().
|
private |
|
private |
Current value of the String.
Definition at line 448 of file String.h.
Referenced by at(), compareTo(), contains(), endsWith(), equals(), get(), lower(), match(), operator*(), operator<<(), operator=(), pad(), resize(), setUnsigned(), split(), startsWith(), String(), substring(), toLong(), trim(), upper(), value(), and ~String().