CStringInterface Class Reference

#include <string.h>

Inheritance diagram for CStringInterface:

Detailed Description

Class to store ASCII strings. CString stores 8 bit characters. Any characters are legal, including 0C (strings are not null-terminated). CStrings are reference-counted objects. This means that as long as you copy and do not modify strings they are just referenced. The first modification breaks the link and it becomes a unique new object.

@MAXON_ANNOTATION{refclass=false}

Public Member Functions

MAXON_METHOD Result< IntGetCStringBlock (const Block< Char > &buffer) const
 
MAXON_METHOD Result< void > GetCStringAppendArray (const NonConstArray< Char > &array) const
 
MAXON_METHOD Result< void > SetCString (const Char *buffer, Int count=-1)
 
MAXON_FUNCTION Result< void > SetCString (const Block< const Char > &buffer)
 
MAXON_METHOD Result< BaseArray< Char > > GetCString () const
 
String ToString (const FormatStatement *formatStatement=nullptr) const
 
MAXON_METHOD Block< const CharGetInternalData () const
 
- Public Member Functions inherited from StringTemplate< CStringInterface, CString, Char >
MAXON_METHOD Int GetLength () const
 
MAXON_METHOD Result< void > Init (Int count=0, Char fillChar=0)
 
MAXON_METHOD Result< void > Shrink ()
 
MAXON_METHOD Result< void > Append (const CStringInterface *str)
 
MAXON_FUNCTION Result< void > Append (const CString &str)
 
MAXON_METHOD Result< void > Append (const Char *str, Int len)
 
MAXON_FUNCTION Result< void > Append (const Block< const Char > &block)
 
MAXON_FUNCTION Result< void > AppendChar (Char v)
 
MAXON_METHOD Int FindIndex (const CStringInterface *str, StringPosition start=0) const
 
MAXON_METHOD Int FindIndex (Char ch, StringPosition start=0) const
 
MAXON_METHOD Int FindLastIndex (const CStringInterface *str, StringPosition start=StringEnd()) const
 
MAXON_METHOD Int FindLastIndex (Char ch, StringPosition start=StringEnd()) const
 
MAXON_METHOD Int FindUpperIndex (const CStringInterface *str, StringPosition start=0) const
 
MAXON_METHOD Int FindLastUpperIndex (const CStringInterface *str, StringPosition start=StringEnd()) const
 
MAXON_METHOD Result< void > Erase (StringPosition position, StringCount count)
 
MAXON_METHOD Result< void > Insert (StringPosition position, const CStringInterface *str, StringPosition strStart=0, StringCount strCount=StringEnd())
 
MAXON_METHOD Result< void > Insert (StringPosition position, Char ch)
 
MAXON_METHOD CStringInterfaceGetPart (StringPosition start, StringCount count) const
 
MAXON_METHOD CStringInterfaceToUpper () const
 
MAXON_METHOD CStringInterfaceToLower () const
 
MAXON_METHOD COMPARERESULT ComparePart (const CStringInterface *str, STRINGCOMPARISON mode, StringPosition position, StringCount count) const
 
MAXON_FUNCTION COMPARERESULT Compare (const CStringInterface *str, STRINGCOMPARISON mode=STRINGCOMPARISON::UNICODE_NUMBERS) const
 
MAXON_FUNCTION Bool IsEqual (const CStringInterface *str) const
 
MAXON_METHOD HashInt GetHashCode () const
 
MAXON_METHOD void SetChar (Int pos, Char ch)
 
MAXON_METHOD Char GetChar (Int pos) const
 
MAXON_FUNCTION Result< Float64ToFloat64 (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION Result< Float32ToFloat32 (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION Result< FloatToFloat (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION Result< Int64ToInt64 (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION Result< Int32ToInt32 (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION Result< IntToInt (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION Result< UInt64ToUInt64 (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION Result< UInt32ToUInt32 (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION Result< UIntToUInt (STRINGCONVERSION flags=STRINGCONVERSION::NONE) const
 
MAXON_FUNCTION CStringInterfaceAppendInt (Int32 v)
 
MAXON_FUNCTION CStringInterfaceAppendInt (Int64 v)
 
MAXON_FUNCTION CStringInterfaceAppendUInt (UInt32 v)
 
MAXON_FUNCTION CStringInterfaceAppendUInt (UInt64 v)
 
MAXON_METHOD Result< void > GetUtf32 (Utf32CharBuffer &stringData) const
 
MAXON_METHOD Result< void > TrimLeft ()
 
MAXON_METHOD Result< void > TrimRight ()
 
MAXON_METHOD Result< void > Split (const CString &splitSymbol, Bool trim, const ValueReceiver< const CString & > &parts) const
 
MAXON_METHOD Result< IntReplace (Char find, Char replace)
 
MAXON_METHOD Result< IntReplace (const CString &find, const CString &replace)
 
MAXON_METHOD Result< IntReplace (Char find, const CString &replace)
 
MAXON_FUNCTION Bool Find (const CString &str, Int *pos, StringPosition start=0) const
 
MAXON_FUNCTION Bool Find (Char ch, Int *pos, StringPosition start=0) const
 
MAXON_FUNCTION Bool FindLast (const CString &str, Int *pos, StringPosition start=StringEnd()) const
 
MAXON_FUNCTION Bool FindLast (Char ch, Int *pos, StringPosition start=StringEnd()) const
 
MAXON_FUNCTION Bool FindUpper (const CString &str, Int *pos, StringPosition start=0) const
 
MAXON_FUNCTION Bool FindLastUpper (const CString &str, Int *pos, StringPosition start=StringEnd()) const
 
MAXON_FUNCTION CStringInterfaceGetLeftPart (StringPosition start) const
 
MAXON_FUNCTION CStringInterfaceGetRightPart (StringPosition start) const
 
MAXON_FUNCTION Bool StartsWith (Char ch) const
 
MAXON_FUNCTION Bool StartsWith (const CString &str) const
 
MAXON_FUNCTION Bool EndsWith (Char ch) const
 
MAXON_FUNCTION Bool EndsWith (const CString &str) const
 
MAXON_FUNCTION Result< void > Trim ()
 

Static Public Member Functions

static const MAXON_METHOD CStringGetAndCacheConstString (const Char *chr, Int len)
 
- Static Public Member Functions inherited from StringTemplate< CStringInterface, CString, Char >
static MAXON_FUNCTION CString FloatToString (Float32 value, Int charsBeforeComma=STRING_DYNAMIC_DIGITS, Int digitsAfterComma=-3, Bool exponent=false, Char fillChar=' ')
 
static MAXON_FUNCTION CString FloatToString (Float64 value, Int charsBeforeComma=STRING_DYNAMIC_DIGITS, Int digitsAfterComma=-3, Bool exponent=false, Char fillChar=' ')
 
static MAXON_FUNCTION CString IntToString (Int32 v)
 
static MAXON_FUNCTION CString IntToString (Int64 v)
 
static MAXON_FUNCTION CString UIntToString (UInt32 v)
 
static MAXON_FUNCTION CString UIntToString (UInt64 v)
 
static MAXON_FUNCTION CString MemorySizeToString (Int64 v, Bool mebibytes=true)
 
static MAXON_FUNCTION CString HexToString (UInt32 v, Bool prefix0x=true)
 
static MAXON_FUNCTION CString HexToString (UInt64 v, Bool prefix0x=true)
 
static MAXON_FUNCTION CString PointerToString (const void *v)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (CStringInterface, MAXON_REFERENCE_COPY_ON_WRITE, "net.maxon.interface.cstring")
 

Additional Inherited Members

- Public Types inherited from StringTemplate< CStringInterface, CString, Char >
using Super = StringTemplate
 
using CharType = Char
 

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( CStringInterface  ,
MAXON_REFERENCE_COPY_ON_WRITE  ,
"net.maxon.interface.cstring"   
)
private

◆ GetCStringBlock()

MAXON_METHOD Result<Int> GetCStringBlock ( const Block< Char > &  buffer) const

Copies the string into 'buffer'.

Parameters
[in,out]bufferBlock describing the buffer. A \0 byte will be appended to the string in any case.
Returns
The length of the corresponding 8-bit string for the given encoding. the \0 byte is not counted.

◆ GetCStringAppendArray()

MAXON_METHOD Result<void> GetCStringAppendArray ( const NonConstArray< Char > &  array) const

Appends the string to the given array.

Parameters
[in,out]arrayArray to be filled with the string. The string is NOT terminated with a \0 byte.
Returns
OK on success.

◆ SetCString() [1/2]

MAXON_METHOD Result<void> SetCString ( const Char buffer,
Int  count = -1 
)

Initializes the string with a given 8-bit Char string (the CString will contain an exact copy of the buffer, there's no encoding to a different character set).

Parameters
[out]bufferPointer to the 8-bit character string.
[in]countNumber of valid characters in the buffer, a value of -1 automatically detects the string length by searching for the first \0 character, otherwise count is relevant and not \0.
Returns
OK on success.

◆ SetCString() [2/2]

MAXON_FUNCTION Result<void> SetCString ( const Block< const Char > &  buffer)

Initializes the string with a given 8-bit Char string with the given encoding.

Parameters
[out]bufferBlock with an 8-bit character string.
Returns
OK on success.

◆ GetCString()

MAXON_METHOD Result<BaseArray<Char> > GetCString ( ) const

Returns a copy of the C string in a new memory block. If a string is empty this function returns a string with a terminating null character.

Returns
BaseArray<Char> with the encoded string. The string is \0 - terminated, so the last character in the array is \0.

◆ ToString()

String ToString ( const FormatStatement formatStatement = nullptr) const

Returns a readable string of the content.

Parameters
[in]formatStatementNullptr or additional formatting instruction. Currently no additional formatting instructions are supported.
Returns
The converted result.

◆ GetInternalData()

MAXON_METHOD Block<const Char> GetInternalData ( ) const

Returns the internal character array.

Returns
Block describing the internal character buffer. The data is read only!

◆ GetAndCacheConstString()

static const MAXON_METHOD CString& GetAndCacheConstString ( const Char chr,
Int  len 
)
static

Internal. Caches a static constant string and returns a maxon::CString.