Difference between revisions of "CXStringEdit"

From cxwiki

(Created page with "<div class="mw-parser-output"> The CXStringEdit class is a string class optimised for simple editing. As compared to the standard CXString, it offers vastly superior gener...")
 
Line 1: Line 1:
<div class="mw-parser-output">
+
<div class="mw-parser-output"><div class="mw-parser-output">
The CXStringEdit class is a string class optimised for simple editing. As compared to the standard [[CXString]], it offers vastly superior general edit performance for short strings, vastly superior append performance even for long strings, and a variety of helper methods for string editing.
+
The CXStringEdit class is a string class optimised for simple editing. As compared to the standard [[CXString|CXString]], it offers vastly superior general edit performance for short strings, vastly superior append performance even for long strings, and a variety of helper methods for string editing.
  
 
A CXStringEdit object nominally stores UTF-8 encoded text with a zero termination byte. Short&nbsp;strings are stored in an internal buffer, while long strings are stored in an allocated buffer. CXStringEdit objects do not distinguish "null" and "empty" strings.
 
A CXStringEdit object nominally stores UTF-8 encoded text with a zero termination byte. Short&nbsp;strings are stored in an internal buffer, while long strings are stored in an allocated buffer. CXStringEdit objects do not distinguish "null" and "empty" strings.
Line 13: Line 13:
  
 
&nbsp;
 
&nbsp;
</div>
+
 
 +
= Construction =
 +
 
 +
Various constructors are available to allow a CXString to be build from a C String, other string classes, etc.
 +
<syntaxhighlight lang="c++">//
 +
CXStringEdit(void);
 +
 
 +
//
 +
CXStringEdit(const CXStringEdit&);
 +
CXStringEdit(CXStringEdit&&);
 +
CXStringEdit(const char* __nullable op);
 +
CXStringEdit(const char* __nonnull op, const char* __nonnull end);
 +
CXStringEdit(const char* __nullable op, size_t len);
 +
CXStringEdit(const CXString& op);
 +
CXStringEdit(const CXStringArgument& op);
 +
CXStringEdit(NSString* __nullable str);</syntaxhighlight>
 +
 
 +
&nbsp;
 +
 
 +
= Comparison =
 +
 
 +
Bytewise comparison operators are available.&nbsp;If case-insensitive operations are required, the&nbsp;[http://cxwiki.typhoonsystems.com.au/index.php?title=CXStringUtils&action=edit&redlink=1 CXStringUtils]&nbsp;functions should be used.
 +
<syntaxhighlight lang="c++">bool operator==(const CXStringArgument& str) const;
 +
bool operator!=(const CXStringArgument& str) const;
 +
bool operator<(const CXStringArgument &other) const;
 +
bool operator<=(const CXStringArgument &other) const;
 +
bool operator>(const CXStringArgument &other) const;
 +
bool operator>=(const CXStringArgument &other) const;</syntaxhighlight>
 +
 
 +
&nbsp;
 +
 
 +
= <br/> Accessors =
 +
 
 +
A variety of simple accessors are provided to give read and write access to the payload.
 +
<syntaxhighlight lang="c++">//
 +
char* __nonnull GetBufferUnsafe(void);
 +
 
 +
//
 +
char* __nonnull GetBufferUnsafeUnterminated(void);
 +
 
 +
//
 +
const char* __nonnull GetBufferUnsafeUnterminated(void) const;
 +
 
 +
//
 +
const char* __nonnull c_str(void) const;
 +
 
 +
//
 +
operator NSString* __nonnull (void) const;
 +
 
 +
//
 +
const char& operator[] (int index) const;
 +
 
 +
//
 +
char& operator[] (int index);
 +
 
 +
//
 +
size_t Length(void) const;
 +
 
 +
//
 +
bool IsEmpty(void) const;</syntaxhighlight>
 +
 
 +
&nbsp;
 +
 
 +
&nbsp;
 +
 
 +
= Helpers =
 +
 
 +
Helper methods are available for composing a string, editing the string, and working with glyphs (unicode codepoints) as opposed to bytes.
 +
<syntaxhighlight lang="c++">//
 +
void Clear(void);
 +
 
 +
//
 +
void AddChar(char ch);
 +
 
 +
//
 +
void AddChars(const char* __nullable ch, size_t len);
 +
 
 +
//
 +
void Add(CXStringArgument str);
 +
 
 +
 
 +
 
 +
//
 +
void Addf(const char* __nonnull format, ...) CX_PRINTF_ARGS(2, 3);
 +
 
 +
//
 +
void Addv(const char* __nonnull format, va_list arg);
 +
 
 +
//
 +
void AddInt(sint32 value, int minDigits = 0);
 +
 
 +
//
 +
void AddInt64(sint64 value, int minDigits = 0);
 +
 
 +
//
 +
void AddUInt64(uint64 value, int minDigits = 0);
 +
 
 +
 
 +
 
 +
//
 +
CXStringEdit operator+(const CXStringArgument& other) const;
 +
 
 +
  
 +
 
 +
//
 +
void Del(size_t startIndex, size_t length);
 +
 
 +
//
 +
void Replace(size_t startIndex, size_t oldLength, const CXStringArgument& newText);
 +
 
 +
//
 +
CXStringEdit Copy(signed_size_t startIndex, signed_size_t endIndex) const;
 +
 
 +
  
 +
 
 +
//
 +
void ToLower(void);
 +
 
 +
//
 +
void ToUpper(void);
 +
 
 +
//
 +
signed_size_t Find(char ch, size_t startPosition = 0);
 +
 
 +
  
 +
 
 +
  
 +
 
 +
// The following functions work with UTF8 glyphs, not bytes.
 +
 
 +
//
 +
bool AddGlyph(uint glyph);
 +
 
 +
//
 +
uint GetFirstGlyph(void) const;
 +
 
 +
//
 +
uint GetLastGlyph(void) const;
 +
 
 +
//
 +
void DeleteFirstGlyph(void);
 +
 
 +
//
 +
void DeleteLastGlyph(void);
 +
 
 +
//
 +
CXStringEdit CopyGlyphs(signed_size_t startGlyphIndex, signed_size_t endGlyphIndex) const;
 +
 
 +
//
 +
uint32 GetIndexedGlyph(signed_size_t glyphIndex) const;
 +
 
 +
//
 +
size_t CountGlyphs(void) const;</syntaxhighlight>
 +
 
 +
&nbsp;
 +
 
 +
&nbsp;
 +
</div> </div>

Revision as of 20:46, 24 February 2018

The CXStringEdit class is a string class optimised for simple editing. As compared to the standard CXString, it offers vastly superior general edit performance for short strings, vastly superior append performance even for long strings, and a variety of helper methods for string editing.

A CXStringEdit object nominally stores UTF-8 encoded text with a zero termination byte. Short strings are stored in an internal buffer, while long strings are stored in an allocated buffer. CXStringEdit objects do not distinguish "null" and "empty" strings.

 

In practice, CXString objects can contain any binary data at all with little overhead:

  • The UTF-8 encoding of the payload is not checked or enforced, except by functions which explicitly deal with UTF-8 glyphs. 
  • While they do have a guaranteed zero terminator byte, nothing prevents additional zero bytes within the payload. 
  • The zero terminator byte is not considered part of the payload, so will not be accidentally appended to a "non-zero-terminated" binary payload. 

 

Construction

Various constructors are available to allow a CXString to be build from a C String, other string classes, etc.

//
CXStringEdit(void);

//
CXStringEdit(const CXStringEdit&);
CXStringEdit(CXStringEdit&&);
CXStringEdit(const char* __nullable op);
CXStringEdit(const char* __nonnull op, const char* __nonnull end);
CXStringEdit(const char* __nullable op, size_t len);
CXStringEdit(const CXString& op);
CXStringEdit(const CXStringArgument& op);
CXStringEdit(NSString* __nullable str);

 

Comparison

Bytewise comparison operators are available. If case-insensitive operations are required, the CXStringUtils functions should be used.

bool operator==(const CXStringArgument& str) const;
bool operator!=(const CXStringArgument& str) const;
bool operator<(const CXStringArgument &other) const;
bool operator<=(const CXStringArgument &other) const;
bool operator>(const CXStringArgument &other) const;
bool operator>=(const CXStringArgument &other) const;

 


Accessors

A variety of simple accessors are provided to give read and write access to the payload.

//
char* __nonnull GetBufferUnsafe(void);

//
char* __nonnull GetBufferUnsafeUnterminated(void);

//
const char* __nonnull GetBufferUnsafeUnterminated(void) const;

//
const char* __nonnull c_str(void) const;

//
operator NSString* __nonnull (void) const;

//
const char& operator[] (int index) const;

//
char& operator[] (int index);

//
size_t Length(void) const;

//
bool IsEmpty(void) const;

 

 

Helpers

Helper methods are available for composing a string, editing the string, and working with glyphs (unicode codepoints) as opposed to bytes.

//
void Clear(void);

//
void AddChar(char ch);

//
void AddChars(const char* __nullable ch, size_t len);

//
void Add(CXStringArgument str);



//
void Addf(const char* __nonnull format, ...) CX_PRINTF_ARGS(2, 3);

//
void Addv(const char* __nonnull format, va_list arg);

//
void AddInt(sint32 value, int minDigits = 0);

//
void AddInt64(sint64 value, int minDigits = 0);

//
void AddUInt64(uint64 value, int minDigits = 0);



//
CXStringEdit operator+(const CXStringArgument& other) const;

  

//
void Del(size_t startIndex, size_t length);

//
void Replace(size_t startIndex, size_t oldLength, const CXStringArgument& newText);

//
CXStringEdit Copy(signed_size_t startIndex, signed_size_t endIndex) const;

  

//
void ToLower(void);

//
void ToUpper(void);

//
signed_size_t Find(char ch, size_t startPosition = 0);

  

  

// The following functions work with UTF8 glyphs, not bytes.

//
bool AddGlyph(uint glyph);

//
uint GetFirstGlyph(void) const;

//
uint GetLastGlyph(void) const;

//
void DeleteFirstGlyph(void);

//
void DeleteLastGlyph(void);

//
CXStringEdit CopyGlyphs(signed_size_t startGlyphIndex, signed_size_t endGlyphIndex) const;

//
uint32 GetIndexedGlyph(signed_size_t glyphIndex) const;

//
size_t CountGlyphs(void) const;