Free Electron
|
Automatically reference-counted string container. More...
#include <String.h>
Classes | |
struct | Sort |
Sort an Array of Strings. More... | |
Public Member Functions | |
String (void) | |
Construct an empty string. More... | |
String (const String &operand) | |
Copy constructor. More... | |
String (const FESTRING_I8 *operand) | |
Construct using a signed byte buffer. More... | |
String (const FESTRING_U8 *operand) | |
Construct using a unsigned byte buffer. More... | |
String (int operand) | |
allow init as 0 in templates More... | |
String & | operator= (const String &operand) |
Compare to another String. More... | |
String & | operator= (const FESTRING_I8 *operand) |
Compare to a signed byte buffer (using 8-bit). More... | |
String & | operator= (const FESTRING_U8 *operand) |
Compare to an unsigned byte buffer (using 8-bit). More... | |
BWORD | equals (const String &operand) const |
checks if the string is equivalent More... | |
I32 | compare (const String &operand) const |
Standard string compare: returns -1, 0, or 1 if the string is alphabetically less than, equal, or greater than the operand. More... | |
BWORD | operator< (const String &operand) const |
String | pathname (void) const |
Return the substring preceding the last '/'. More... | |
String | basename (void) const |
Return the substring following the last '/'. More... | |
String | prechop (const String &prefix) const |
Return the substring after the prefix. More... | |
String | prechop (I32 count) const |
Return the substring without trailing characters. More... | |
String | chop (const String &suffix) const |
Return the substring before the suffix. More... | |
String | chop (I32 count) const |
Return the substring without trailing characters. More... | |
BWORD | contains (String find) const |
Returns TRUE if string contains the substring. More... | |
String | substitute (String find, String replace) const |
Return a string with replaced substrings. More... | |
String | substituteEnv (std::map< String, String > &a_rMap, BWORD a_alsoUseEnv=FALSE, BWORD a_throwMissing=FALSE) const |
Return a string with enviroment substitution. More... | |
String | substituteEnv (void) |
String | stripComments (String a_start="/*", String a_end="*/", BWORD a_keepStart=FALSE, BWORD a_keepEnd=FALSE) |
Return a string with sections removed. More... | |
BWORD | dotMatch (const String &operand) const |
Compares to another string assuming the given string is a dot-delimited ordered list containing optional substrings. More... | |
void | forceUppercase (void) |
Force all applicable characters to upper case. More... | |
void | forceLowercase (void) |
Force all applicable characters to lower case. More... | |
U32 | length (void) const |
Return the number of represented characters, but not necessarily the size of any buffer. More... | |
BWORD | empty (void) const |
Returns true if the contents have zero length. More... | |
String & | sPrintf (const char *fmt,...) |
Populate the string in the manner of sprintf(). More... | |
String & | catf (const char *fmt,...) |
Populate the string as with sPrintf(), but by concatenating the results to the existing string. More... | |
String & | cat (const char *operand) |
Append the current String with the given text. More... | |
String & | cat (const String &operand) |
Append the current String with the given String. More... | |
String & | cat (std::list< String > &strList, String sep="") |
Concatenate the strings in a list. More... | |
void | resize (U32 size, char c=' ') |
Add or remove characters to set the string length. More... | |
String | maybeQuote (String beginQuote, String endQuote) const |
Return the string, adding quotes if it contains a likely delimiter. More... | |
String | maybeQuote (String quote="\) const |
String | maybeUnQuote (String beginQuote, String endQuote) const |
Return the string, removing outer quotes if they exist. More... | |
String | maybeUnQuote (String quote="\) const |
String | parse (String quote="\, String delimiters=" \\", BWORD eachDelimiter=FALSE) |
I32 | lines (void) const |
String | line (I32 a_lineNumber) const |
String & | vsPrintf (const char *fmt, va_list ap, int &size) |
Populate using variable arg format. More... | |
const FESTRING_I8 * | c_str (void) const |
Return the contents of the 8-bit buffer cast as signed bytes. More... | |
const FESTRING_U8 * | rawU8 (void) const |
Return the contents of the 8-bit buffer cast as unsigned bytes. More... | |
void | output (std::ostream &ostrm) const |
void | input (std::istream &istrm) |
String & | operator+= (const String &operand) |
int | integer (void) const |
Real | real (void) const |
bool | match (const String a_pattern) const |
bool | search (const String a_pattern) const |
String | replace (const String a_pattern, const String a_replacement) const |
String | convertGlobToRegex (void) const |
U64 | computeFowlerNollVo1 (void) const |
Compute Fowler-Noll-Vo hash function (64-bit FNV-1) More... | |
Static Public Member Functions | |
static String | join (const String &a_sep, std::list< String > &a_list) |
static String | join (const String &a_sep, const String &a_1, const String &a_2) |
static String | join (const String &a_sep, const String &a_1, const String &a_2, const String &a_3) |
Private Member Functions | |
FESTRING_U8 * | buffer (void) |
void | create (const FESTRING_I8 *operand) |
void | init (void) |
void | forceCase (BWORD upper) |
Rep * | newRep (void) |
void | deleteRep (void) |
Private Attributes | |
FESTRING_U8 | m_pLocal [FESTRING_LOCALSIZE] |
I32 | m_length |
Rep * | m_pRep |
Automatically reference-counted string container.
Designed to behave as a native type, like float or int. All allocation worries are completely hidden.
To assign a string just use simple assignments.
You can compare strings in a boolean or lexical fashion.
To print a string in printf fashion, use c_str().
Although the String encoding may start like a (char*) byte-wise, you should always use the c_str() method in conjunction with C-style string operations, especially variable argument functions like *printf.
A String object is 32 bytes. Strings shorter than FESTRING_LOCALSIZE (currently 16), including terminator, are stored in a local buffer and compared quickly as two 64-bit words or as a single 128-bit word, depending on the compiler. Longer strings are allocated and can be shared in assignment.
We would prefer to derive fe::String from std::string, just adding fe methods to the std::string buffer handling. But, as of Feb 2021, on gcc 8.3.0, same size small string operator==() is 3 times faster with fe::String than std::string. Also, std::string is forbidden from being ref counted, so passing std::string as an argument is a deep copy every time. You don't don't need a full mutex to protect the ref count, but a swap increment appears to take about 4ns (in 2021). The alternative of a deep copy on every string copy can be a little less, or a much much more, depending on the string length. But, for the sake of conformance, this task will likely happen eventually.
As a tight core class, String doesn't carry virtual functions.
|
inline |
Copy constructor.
|
inline |
Construct using a signed byte buffer.
|
inline |
Construct using a unsigned byte buffer.
|
inline |
allow init as 0 in templates
String fe::String::basename | ( | void | ) | const |
Return the substring following the last '/'.
If there is no '/', the entire text is returned.
Referenced by fe::Library::setLoader().
|
inline |
Return the contents of the 8-bit buffer cast as signed bytes.
Referenced by cat(), fe::Catalog::catalogKeys(), catf(), contains(), fe::System::createDirectory(), dotMatch(), fe::DL_Loader::findDLFunction(), fe::System::findFile(), fe::ext::MOAViewer::getDefaultBgColor(), fe::ext::SockAddr::getIp4Address(), fe::ext::SplatterSystem::image(), fe::ext::GraphDot::interpretSelect(), fe::ext::ImageOIIO::interpretSelect(), fe::ext::ImageIL::interpretSelect(), fe::BruteScan::letterFrequency(), fe::System::listDirectory(), fe::ext::ImageOIIO::loadSelect(), fe::ext::ImageIL::loadSelect(), fe::ext::ImageSDL::loadSelect(), fe::System::localTime(), maybeQuote(), maybeUnQuote(), fe::DL_Loader::openDL(), fe::operator!=(), output(), fe::System::setCurrentWorkingDirectory(), stripComments(), and substitute().
String & fe::String::cat | ( | const char * | operand | ) |
Append the current String with the given text.
References c_str(), and sPrintf().
Referenced by cat(), fe::Matrix< 3, 4, T >::copyTranslation(), fe::operator!=(), fe::Matrix< 3, 4, Real >::print(), fe::ext::SparseMatrix< F64 >::print(), and fe::Vector< 4, t_moa_real >::print().
String & fe::String::catf | ( | const char * | fmt, |
... | |||
) |
Populate the string as with sPrintf(), but by concatenating the results to the existing string.
References c_str(), sPrintf(), and vsPrintf().
Referenced by fe::Matrix< 3, 4, T >::copyTranslation(), fe::Matrix< 3, 4, Real >::print(), and fe::ext::SparseMatrix< F64 >::print().
Return the substring before the suffix.
If the string doesn't end with the suffix, the original text is returned.
Referenced by fe::Library::setLoader().
String fe::String::chop | ( | I32 | count | ) | const |
|
inline |
Standard string compare: returns -1, 0, or 1 if the string is alphabetically less than, equal, or greater than the operand.
U64 fe::String::computeFowlerNollVo1 | ( | void | ) | const |
BWORD fe::String::contains | ( | String | find | ) | const |
Returns TRUE if string contains the substring.
References c_str().
Referenced by fe::ext::SurfaceAccessibleHoudini::accessor().
BWORD fe::String::dotMatch | ( | const String & | operand | ) | const |
Compares to another string assuming the given string is a dot-delimited ordered list containing optional substrings.
Returns true if strings are exactly the same, or if they match only up to the length of the operand and the operand's terminating zero matches a period.
|
inline |
Returns true if the contents have zero length.
Referenced by fe::ext::ConnectedCatalog::configure(), fe::ext::GuidePostNetHost::connect(), fe::System::createParentDirectories(), fe::ext::SurfaceAccessibleBase::discardPattern(), fe::ext::MOAViewer::getDefaultBgColor(), fe::ext::SockAddr::getIp4Address(), fe::System::getVerbose(), and fe::ext::ConnectedCatalog::postSet().
|
inline |
checks if the string is equivalent
Referenced by fe::operator!=(), and fe::operator==().
|
inline |
Force all applicable characters to lower case.
|
inline |
Force all applicable characters to upper case.
|
inline |
Return the number of represented characters, but not necessarily the size of any buffer.
Referenced by fe::BruteScan::charCount(), chop(), computeFowlerNollVo1(), dotMatch(), fe::ext::ImageIL::interpretSelect(), fe::ext::ImageOIIO::interpretSelect(), fe::System::localTime(), maybeUnQuote(), and prechop().
Return the string, adding quotes if it contains a likely delimiter.
References c_str().
|
inline |
Compare to a signed byte buffer (using 8-bit).
|
inline |
Compare to an unsigned byte buffer (using 8-bit).
void fe::String::output | ( | std::ostream & | ostrm | ) | const |
only works for 8bit and does too much copying
References c_str(), and operator=().
String fe::String::pathname | ( | void | ) | const |
Return the substring preceding the last '/'.
If there is no '/', no text is returned.
Referenced by fe::System::getExePath().
Return the substring after the prefix.
If the string doesn't begin with the prefix, the original text is returned.
Referenced by fe::Library::setLoader().
String fe::String::prechop | ( | I32 | count | ) | const |
|
inline |
Return the contents of the 8-bit buffer cast as unsigned bytes.
Referenced by computeFowlerNollVo1().
void fe::String::resize | ( | U32 | size, |
char | c = ' ' |
||
) |
Add or remove characters to set the string length.
If expanded, the given character is used to pad the string.
String & fe::String::sPrintf | ( | const char * | fmt, |
... | |||
) |
Populate the string in the manner of sprintf().
References vsPrintf().
Referenced by cat(), catf(), fe::ext::SplatterSystem::image(), fe::ext::GuidePostNetHost::listSpaces(), fe::System::localTime(), fe::operator!=(), fe::Vector< 4, t_moa_real >::print(), fe::Quaternion< Real >::print(), fe::ext::CameraEditable::rasterSpace(), and fe::Profiler::report().
String fe::String::stripComments | ( | String | a_start = "/*" , |
String | a_end = "*/" , |
||
BWORD | a_keepStart = FALSE , |
||
BWORD | a_keepEnd = FALSE |
||
) |
Return a string with sections removed.
Each substring beginning with the given start up to the given end is removed.
If either of the keep options is on, the associated delimiting string is retained.
References c_str().
Return a string with replaced substrings.
References c_str().
String fe::String::substituteEnv | ( | std::map< String, String > & | a_rMap, |
BWORD | a_alsoUseEnv = FALSE , |
||
BWORD | a_throwMissing = FALSE |
||
) | const |
Return a string with enviroment substitution.
Replace substrings like $VARIABLE and ${VARIABLE} with environment variables and or a map.
Without arguments, only environment variables are used for substitution.
A map can be provided for non-environment variables. In that case, the environment variable can optionally also be checked when a variable is not in the map.
If set to throw missing, a exception is thrown is a variable is found that can't be resolved.
String & fe::String::vsPrintf | ( | const char * | fmt, |
va_list | ap, | ||
int & | size | ||
) |