Difference between revisions of "CXString"
From cxwiki
Line 1: | Line 1: | ||
− | <div class="mw-parser-output">The CXString class is considered the "default" string class in the cxsource framework. It offers a reasonable compromise of capabilities. Other string classes are available for more specific uses where the standard tradeoffs are not suitable.</div> <div class="mw-parser-output">A CXString object nominally stores UTF-8 encoded text with a zero termination byte. Strings are stored using copy-on-write references, and string pooling may optionally be enabled using a compile-time flag. CXString objects do not distinguish "null" and "empty" strings.</div> <div class="mw-parser-output"> </div> | + | <div class="mw-parser-output"><div class="mw-parser-output">The CXString class is considered the "default" string class in the cxsource framework. It offers a reasonable compromise of capabilities. Other string classes are available for more specific uses where the standard tradeoffs are not suitable.</div> <div class="mw-parser-output">A CXString object nominally stores UTF-8 encoded text with a zero termination byte. Strings are stored using copy-on-write references, and string pooling may optionally be enabled using a compile-time flag. CXString objects do not distinguish "null" and "empty" strings.</div> <div class="mw-parser-output"> </div> |
= Construction = | = Construction = | ||
<div class="mw-parser-output"><syntaxhighlight lang="c++">// Efficiently construct an empty string. | <div class="mw-parser-output"><syntaxhighlight lang="c++">// Efficiently construct an empty string. | ||
Line 46: | Line 46: | ||
| | ||
− | <div class="mw-parser-output"> </div> <div class="mw-parser-output">Helpers</ | + | <div class="mw-parser-output"> </div> <div class="mw-parser-output"> |
+ | = Helpers = | ||
+ | |||
+ | | ||
+ | <syntaxhighlight lang="c++">// | ||
+ | size_t Length(void) const; | ||
+ | |||
+ | // | ||
+ | bool IsEmpty(void) const; | ||
+ | |||
+ | // | ||
+ | const char* __nonnull c_str(void) const; | ||
+ | |||
+ | // | ||
+ | CXString Copy(size_t startIndex, size_t endIndex) const; | ||
+ | |||
+ | // | ||
+ | void Del(signed_size_t startIndex, signed_size_t endIndex); | ||
+ | |||
+ | // | ||
+ | CXString Left(signed_size_t len) const; | ||
+ | |||
+ | // | ||
+ | CXString Right(signed_size_t len) const; | ||
+ | |||
+ | // | ||
+ | CXString RightOf(signed_size_t pos) const; | ||
+ | |||
+ | // | ||
+ | signed_size_t Pos(char glyph, size_t startIndex = 0) const; | ||
+ | |||
+ | // | ||
+ | bool MatchesPrefix(const CXString &p_prefix) const; | ||
+ | |||
+ | // | ||
+ | const char& operator[](size_t pos) const; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | Constants | ||
+ | <syntaxhighlight lang="c++">// | ||
+ | static const CXString NULLCHAR; | ||
+ | |||
+ | // | ||
+ | static const CXString EMPTY; | ||
+ | |||
+ | // | ||
+ | static const char* __nonnull kEmptyCString;</syntaxhighlight> | ||
+ | |||
+ | | ||
+ | |||
+ | Streamers | ||
+ | <syntaxhighlight lang="c++">// | ||
+ | CX_STREAMER_TMPL CX_STREAMER_QUAL& operator<<(CX_STREAMER_QUAL &a_streamer, const CXString &a_string) | ||
+ | |||
+ | // | ||
+ | CX_STREAMER_TMPL CX_STREAMER_QUAL& operator>>(CX_STREAMER_QUAL &a_streamer, CXString &o_string) | ||
+ | |||
+ | </syntaxhighlight> | ||
+ | |||
+ | | ||
+ | </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> <div class="mw-parser-output"> </div> </div> |
Revision as of 07:34, 23 February 2018
The CXString class is considered the "default" string class in the cxsource framework. It offers a reasonable compromise of capabilities. Other string classes are available for more specific uses where the standard tradeoffs are not suitable.
A CXString object nominally stores UTF-8 encoded text with a zero termination byte. Strings are stored using copy-on-write references, and string pooling may optionally be enabled using a compile-time flag. CXString objects do not distinguish "null" and "empty" strings.
Construction
// Efficiently construct an empty string.
CXString(void);
// Construct from a cxsource string object.
CXString(const CXString &str);
CXString(CXString&& rhs);
CXString(const class CXStringEdit& str);
CXString(const CXStringArgument& cstr);
// Construct from a character range.
CXString(const CXStringArgument& begin, const CXStringArgument& end);
CXString(const char* __nullable ch, size_t len);
CXString(const char* __nonnull ch, const char* __nonnull end);
// Construct from Objective-C string or data objects.
CXString(NSString* __nullable str);
CXString(NSData* __nullable data);
// Construct from a printf-style format string.
static CXString Fromf(const char* __nonnull format, ...);
Equivalent assingment operators are also available.
Comparison
// Equality operators test for byte-for-byte equality.
bool operator==(const CXString& other) const;
bool operator==(const char* __nullable other) const;
bool operator!=(const CXString& other) const;
bool operator!=(const char* __nullable other) const;
// Byte-for-byte sort operators.
bool operator<(const CXString& other) const;
bool operator<=(const CXString& other) const;
bool operator>(const CXString& other) const;
bool operator>=(const CXString& other) const;
// Optimise hash operator.
struct std::hash<CXString>;
// Optimised std::map comparison function, non-alphabetic ordering.
struct CXStringPooledMapCompare;
Helpers
//
size_t Length(void) const;
//
bool IsEmpty(void) const;
//
const char* __nonnull c_str(void) const;
//
CXString Copy(size_t startIndex, size_t endIndex) const;
//
void Del(signed_size_t startIndex, signed_size_t endIndex);
//
CXString Left(signed_size_t len) const;
//
CXString Right(signed_size_t len) const;
//
CXString RightOf(signed_size_t pos) const;
//
signed_size_t Pos(char glyph, size_t startIndex = 0) const;
//
bool MatchesPrefix(const CXString &p_prefix) const;
//
const char& operator[](size_t pos) const;
Constants
//
static const CXString NULLCHAR;
//
static const CXString EMPTY;
//
static const char* __nonnull kEmptyCString;
Streamers
//
CX_STREAMER_TMPL CX_STREAMER_QUAL& operator<<(CX_STREAMER_QUAL &a_streamer, const CXString &a_string)
//
CX_STREAMER_TMPL CX_STREAMER_QUAL& operator>>(CX_STREAMER_QUAL &a_streamer, CXString &o_string)