CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
System::Text::StringBuilder Class Reference

Buffer to accumulate string part by part. This type can be allocated either in stack as value type or in heap using System::MakeObject() function. Once the object is allocated, never mix up these two usecases: having SmartPtr pointers onto stack-allocated objects is strictly prohibited. More...

#include <string_builder.h>

Inherits System::Object.

Public Member Functions

 StringBuilder ()
 Constructor. More...
 
 StringBuilder (int capacity)
 Constructor. More...
 
 StringBuilder (const String &str)
 Constructor. More...
 
 StringBuilder (const String &value, int capacity)
 Constructor. More...
 
 StringBuilder (const String &value, int startIndex, int length, int capacity)
 Constructor. More...
 
 ~StringBuilder ()
 Destructor. More...
 
int get_Length () const
 Gets length of string currently in builder. More...
 
void set_Length (int len)
 Trunkates or extends string builder to specified length. More...
 
int get_Capacity () const
 Gets current capacity of string builder. More...
 
void set_Capacity (int capacity)
 Sets current capacity of string builder. More...
 
char_t operator[] (int index) const
 Gets character at specified position. More...
 
char_t idx_get (int index) const
 Gets character at specified position. More...
 
void idx_set (int index, char_t c)
 Sets character at specified position. More...
 
StringBuilderAppend (char_t c)
 Adds character to builder. More...
 
StringBuilderAppend (char_t c, int count)
 Adds characters to builder. More...
 
StringBuilderAppend (const ArrayPtr< char_t > &arr)
 Adds characters array to builder. More...
 
StringBuilderAppend (const ArrayPtr< char_t > &arr, int startIndex, int charCount)
 Adds characters array slice to builder. More...
 
StringBuilderAppend (const String &str)
 Adds string to builder. More...
 
StringBuilderAppend (const String &str, int startIndex, int charCount)
 Adds string slice to builder. More...
 
template<class T >
StringBuilderAppend (const SharedPtr< T > &obj)
 Adds object's string representation to builder. More...
 
StringBuilderAppend (const SharedPtr< StringBuilder > &builder)
 Adds builder's content to builder. More...
 
StringBuilderAppend (float f)
 Adds floating point value to builder. More...
 
StringBuilderAppend (double df)
 Adds floating point value to builder. More...
 
StringBuilderAppend (int i)
 Adds integer value to builder. More...
 
template<typename T >
std::enable_if< std::is_arithmetic< T >::value, StringBuilder * >::type Append (T value)
 Adds arithmetic value to builder. More...
 
template<class E >
std::enable_if< std::is_enum< E >::value, StringBuilder * >::type Append (E e)
 Adds enum value string representation to builder. More...
 
template<class... TArgs>
StringBuilderAppendFormat (const String &format, const TArgs &... args)
 Appends formated string to builder. More...
 
template<class... TArgs>
StringBuilderAppendFormat (const SharedPtr< IFormatProvider > &fp, const String &format, const TArgs &... args)
 Appends formated string to builder. More...
 
StringBuilderAppendLine ()
 Appends new line character to builder. More...
 
StringBuilderAppendLine (const String &str)
 Appends string followed by new line character to builder. More...
 
StringBuilderClear ()
 Removes all characters from the builder. More...
 
StringBuilderInsert (int startIndex, const String &str)
 Inserts string into builder's fixed position. More...
 
StringBuilderInsert (int32_t index, const String &value, int32_t count)
 Inserts repeated string into builder's fixed position. More...
 
StringBuilderInsert (int startIndex, char_t ch)
 Inserts character into builder's fixed position. More...
 
StringBuilderInsert (int index, const System::ArrayPtr< char_t > &chars, int startIndex, int charCount)
 Inserts characters into builder's fixed position. More...
 
template<typename T >
std::enable_if< std::is_arithmetic< T >::value, StringBuilder * >::type Insert (int startIndex, T value)
 Inserts value into builder's fixed position. More...
 
StringBuilderReplace (const String &oldString, const String &newString)
 Replaces substring through the builder. More...
 
StringBuilderReplace (const String &oldString, const String &newString, int position, int count)
 Replaces substring through the builder's range. More...
 
StringBuilderReplace (char_t oldChar, char_t newChar)
 Replaces character through the builder. More...
 
StringBuilderReplace (char_t oldChar, char_t newChar, int startIndex, int count)
 Replaces character through the builder's range. More...
 
StringBuilderRemove (int startIndex, int length)
 Removes fragment from builder. More...
 
String ToString () const override
 Gets string currently contained in builder. More...
 
String ToString (int startIndex, int length) const
 Gets substring currently contained in builder. More...
 
void CopyTo (int sourceIndex, System::ArrayPtr< char_t > const &destination, int destinationIndex, int count)
 Copies builder's data into existing array positions. More...
 
- Public Member Functions inherited from System::Object
 Object ()
 Creates object. Initializes all internal data structures. More...
 
virtual ~Object ()
 Destroys object. Frees all internal data structures. More...
 
 Object (Object const &x)
 Copy constructor. Doesn't copy anything, really, just initializes new object and enables copy constructing subclasses. More...
 
Objectoperator= (Object const &x)
 Assignment operator. Doesn't copy anything, really, just initializes new object and enables copy constructing subclasses. More...
 
ObjectSharedRefAdded ()
 Increments shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
int SharedRefRemovedSafe ()
 Decrements and returns shared reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
int RemovedSharedRefs (int count)
 Decreases shared reference count by specified value. More...
 
Detail::SmartPtrCounter * WeakRefAdded ()
 Increments weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
void WeakRefRemoved ()
 Decrements weak reference count. Shouldn't be called directly; instead, use smart pointers or ThisProtector. More...
 
Detail::SmartPtrCounter * GetCounter ()
 Gets reference counter data structure associated with the object. More...
 
int SharedCount () const
 Gets current value of shared reference counter. More...
 
void Lock ()
 Implements C# lock() statement locking. Call directly or use LockContext sentry object. More...
 
void Unlock ()
 Implements C# lock() statement unlocking. Call directly or use LockContext sentry object. More...
 
virtual bool Equals (ptr obj)
 Compares objects using C# Object.Equals semantics. More...
 
virtual int32_t GetHashCode () const
 Analog of C# Object.GetHashCode() method. Enables hashing of custom objects. More...
 
virtual String ToString () const
 Analog of C# Object.ToString() method. Enables converting custom objects to string. More...
 
virtual ptr MemberwiseClone () const
 Analog of C# Object.MemberwiseClone() method. Enables cloning custom types. More...
 
virtual const TypeInfoGetType () const
 Gets actual type of object. Analog of C# System.Object.GetType() call. More...
 
virtual bool Is (const TypeInfo &targetType) const
 Check if object represents an instance of type described by targetType. Analog of C# 'is' operator. More...
 
virtual void SetTemplateWeakPtr (uint32_t argument)
 Set n'th template argument a weak pointer (rather than shared). Allows switching pointers in containers to weak mode. More...
 
virtual bool FastCast (const Details::FastRttiBase &helper, void **out_ptr) const
 For internal purposes only. More...
 
template<>
bool ReferenceEquals (String const &str, std::nullptr_t)
 Specialization of Object::ReferenceEquals for case of string and nullptr. More...
 
template<>
bool ReferenceEquals (String const &str1, String const &str2)
 Specialization of Object::ReferenceEquals for case of strings. More...
 

Additional Inherited Members

- Public Types inherited from System::Object
typedef SmartPtr< Objectptr
 Alias for smart pointer type. More...
 
- Static Public Member Functions inherited from System::Object
static bool ReferenceEquals (ptr const &objA, ptr const &objB)
 Compares objects by reference. More...
 
template<typename T >
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, T const &objB)
 Compares objects by reference. More...
 
template<typename T >
static std::enable_if<!IsSmartPtr< T >::value, bool >::type ReferenceEquals (T const &objA, std::nullptr_t)
 Reference-compares value type object with nullptr. More...
 
template<typename T1 , typename T2 >
static std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 Compares reference type objects in C# style. More...
 
template<typename T1 , typename T2 >
static std::enable_if<!IsSmartPtr< T1 >::value &&!IsSmartPtr< T2 >::value, bool >::type Equals (T1 const &objA, T2 const &objB)
 Compares value type objects in C# style. More...
 
static const TypeInfoType ()
 Implements C# typeof(System.Object) construct. More...
 
template<>
bool Equals (float const &objA, float const &objB)
 Emulates C#-style floating point comparison where two NaNs are considered equal even though according to IEC 60559:1989 NaN is not equal to any value, including NaN. More...
 
template<>
bool Equals (double const &objA, double const &objB)
 Emulates C#-style floating point comparison where two NaNs are considered equal even though according to IEC 60559:1989 NaN is not equal to any value, including NaN. More...
 

Detailed Description

Buffer to accumulate string part by part. This type can be allocated either in stack as value type or in heap using System::MakeObject() function. Once the object is allocated, never mix up these two usecases: having SmartPtr pointers onto stack-allocated objects is strictly prohibited.

Constructor & Destructor Documentation

◆ StringBuilder() [1/5]

System::Text::StringBuilder::StringBuilder ( )

Constructor.

◆ StringBuilder() [2/5]

System::Text::StringBuilder::StringBuilder ( int  capacity)

Constructor.

Parameters
capacityInitial string capacity.

◆ StringBuilder() [3/5]

System::Text::StringBuilder::StringBuilder ( const String str)

Constructor.

Parameters
strInitial value.

◆ StringBuilder() [4/5]

System::Text::StringBuilder::StringBuilder ( const String value,
int  capacity 
)

Constructor.

Parameters
valueInitial value.
capacityInitial string capacity.

◆ StringBuilder() [5/5]

System::Text::StringBuilder::StringBuilder ( const String value,
int  startIndex,
int  length,
int  capacity 
)

Constructor.

Parameters
valueInitial value.
startIndexIndex of initial value slice beginning.
lengthInitial value slice length.
capacityInitial string capacity.

◆ ~StringBuilder()

System::Text::StringBuilder::~StringBuilder ( )

Destructor.

Member Function Documentation

◆ Append() [1/13]

StringBuilder * System::Text::StringBuilder::Append ( char_t  c)

Adds character to builder.

Parameters
cCharacter value.
Returns
This pointer.

◆ Append() [2/13]

StringBuilder * System::Text::StringBuilder::Append ( char_t  c,
int  count 
)

Adds characters to builder.

Parameters
cCharacter value.
countHow many times to repeat insertee character.
Returns
This pointer.

◆ Append() [3/13]

StringBuilder * System::Text::StringBuilder::Append ( const ArrayPtr< char_t > &  arr)

Adds characters array to builder.

Parameters
arrCharacters to add.
Returns
This pointer.

◆ Append() [4/13]

StringBuilder * System::Text::StringBuilder::Append ( const ArrayPtr< char_t > &  arr,
int  startIndex,
int  charCount 
)

Adds characters array slice to builder.

Parameters
arrCharacters to add.
startIndexSlice beginning index.
charCountSlice length.
Returns
This pointer.

◆ Append() [5/13]

StringBuilder * System::Text::StringBuilder::Append ( const SharedPtr< StringBuilder > &  builder)

Adds builder's content to builder.

Parameters
builderBuilder to add content from.
Returns
This pointer.

◆ Append() [6/13]

template<class T >
StringBuilder * System::Text::StringBuilder::Append ( const SharedPtr< T > &  obj)
inline

Adds object's string representation to builder.

Template Parameters
TObject type.
Parameters
objObject to serialize and add.
Returns
This pointer.

◆ Append() [7/13]

StringBuilder * System::Text::StringBuilder::Append ( const String str)

Adds string to builder.

Parameters
strString to add.
Returns
This pointer.

◆ Append() [8/13]

StringBuilder * System::Text::StringBuilder::Append ( const String str,
int  startIndex,
int  charCount 
)

Adds string slice to builder.

Parameters
strString to add.
startIndexSlice beginning index.
charCountSlice length.
Returns
This pointer.

◆ Append() [9/13]

StringBuilder * System::Text::StringBuilder::Append ( double  df)

Adds floating point value to builder.

Parameters
dfValue to serialize and add.
Returns
This pointer.

◆ Append() [10/13]

template<class E >
std::enable_if< std::is_enum< E >::value, StringBuilder * >::type System::Text::StringBuilder::Append ( e)
inline

Adds enum value string representation to builder.

Template Parameters
EEnum type.
Parameters
eValue to serialize and add.
Returns
This pointer.

◆ Append() [11/13]

StringBuilder * System::Text::StringBuilder::Append ( float  f)

Adds floating point value to builder.

Parameters
fValue to serialize and add.
Returns
This pointer.

◆ Append() [12/13]

StringBuilder * System::Text::StringBuilder::Append ( int  i)

Adds integer value to builder.

Parameters
iValue to serialize and add.
Returns
This pointer.

◆ Append() [13/13]

template<typename T >
std::enable_if< std::is_arithmetic< T >::value, StringBuilder * >::type System::Text::StringBuilder::Append ( value)
inline

Adds arithmetic value to builder.

Template Parameters
TArithmetic type.
Parameters
valueValue to serialize and add.
Returns
This pointer.

◆ AppendFormat() [1/2]

template<class... TArgs>
StringBuilder * System::Text::StringBuilder::AppendFormat ( const SharedPtr< IFormatProvider > &  fp,
const String format,
const TArgs &...  args 
)
inline

Appends formated string to builder.

Template Parameters
TArgsArguments type.
Parameters
fpFormat provider; ignored.
formatFormat string.
argsArguments to insert into format string positions.
Returns
This pointer.

◆ AppendFormat() [2/2]

template<class... TArgs>
StringBuilder * System::Text::StringBuilder::AppendFormat ( const String format,
const TArgs &...  args 
)
inline

Appends formated string to builder.

Template Parameters
TArgsArguments type.
Parameters
formatFormat string.
argsArguments to insert into format string positions.
Returns
This pointer.

◆ AppendLine() [1/2]

StringBuilder * System::Text::StringBuilder::AppendLine ( )

Appends new line character to builder.

Returns
This pointer.

◆ AppendLine() [2/2]

StringBuilder * System::Text::StringBuilder::AppendLine ( const String str)

Appends string followed by new line character to builder.

Parameters
strString to add.
Returns
This pointer.

◆ Clear()

StringBuilder * System::Text::StringBuilder::Clear ( )

Removes all characters from the builder.

Returns
This pointer.

◆ CopyTo()

void System::Text::StringBuilder::CopyTo ( int  sourceIndex,
System::ArrayPtr< char_t > const &  destination,
int  destinationIndex,
int  count 
)

Copies builder's data into existing array positions.

Parameters
sourceIndexIndex in builder to start copying from.
destinationDestination array.
destinationIndexIndex in destination array to start insertion at.
countNumber of characters to copy.

◆ get_Capacity()

int System::Text::StringBuilder::get_Capacity ( ) const

Gets current capacity of string builder.

Returns
Number of allocated characters.

◆ get_Length()

int System::Text::StringBuilder::get_Length ( ) const

Gets length of string currently in builder.

Returns
Number of characters currently stored in builder.

◆ idx_get()

char_t System::Text::StringBuilder::idx_get ( int  index) const

Gets character at specified position.

Parameters
indexPosition in builder.
Returns
Character at specified position.

◆ idx_set()

void System::Text::StringBuilder::idx_set ( int  index,
char_t  c 
)

Sets character at specified position.

Parameters
indexPosition in builder.
cCharacter to set.

◆ Insert() [1/5]

StringBuilder * System::Text::StringBuilder::Insert ( int  index,
const System::ArrayPtr< char_t > &  chars,
int  startIndex,
int  charCount 
)

Inserts characters into builder's fixed position.

Parameters
indexPosition to insert characters into.
charsArray to insert slice from.
startIndexArray slice beginning index.
charCountArray slice length.
Returns
This pointer.

◆ Insert() [2/5]

StringBuilder * System::Text::StringBuilder::Insert ( int  startIndex,
char_t  ch 
)

Inserts character into builder's fixed position.

Parameters
startIndexPosition to insert characters into.
chCharacter to insert.
Returns
This pointer.

◆ Insert() [3/5]

StringBuilder * System::Text::StringBuilder::Insert ( int  startIndex,
const String str 
)

Inserts string into builder's fixed position.

Parameters
startIndexPosition to insert characters into.
strString to insert.
Returns
This pointer.

◆ Insert() [4/5]

template<typename T >
std::enable_if< std::is_arithmetic< T >::value, StringBuilder * >::type System::Text::StringBuilder::Insert ( int  startIndex,
value 
)
inline

Inserts value into builder's fixed position.

Template Parameters
Parametertype.
Parameters
startIndexPosition to insert characters into.
valueValue to format and insert.
Returns
This pointer.

◆ Insert() [5/5]

StringBuilder * System::Text::StringBuilder::Insert ( int32_t  index,
const String value,
int32_t  count 
)

Inserts repeated string into builder's fixed position.

Parameters
indexPosition to insert characters into.
valueString to insert.
countHow many times to repeat value string.
Returns
This pointer.

◆ operator[]()

char_t System::Text::StringBuilder::operator[] ( int  index) const

Gets character at specified position.

Parameters
indexPosition in builder.
Returns
Character at specified position.

◆ Remove()

StringBuilder * System::Text::StringBuilder::Remove ( int  startIndex,
int  length 
)

Removes fragment from builder.

Parameters
startIndexDeletion range beginning index.
lengthNumber of characters to remove.
Returns
This pointer.

◆ Replace() [1/4]

StringBuilder * System::Text::StringBuilder::Replace ( char_t  oldChar,
char_t  newChar 
)

Replaces character through the builder.

Parameters
oldCharCharacter to replace.
newCharReplacement character.
Returns
This pointer.

◆ Replace() [2/4]

StringBuilder * System::Text::StringBuilder::Replace ( char_t  oldChar,
char_t  newChar,
int  startIndex,
int  count 
)

Replaces character through the builder's range.

Parameters
oldCharCharacter to replace.
newCharReplacement character.
startIndexBuilder's replacement range beginning position.
countBuilder's replacement range length.
Returns
This pointer.

◆ Replace() [3/4]

StringBuilder * System::Text::StringBuilder::Replace ( const String oldString,
const String newString 
)

Replaces substring through the builder.

Parameters
oldStringString to replace.
newStringReplacement string.
Returns
This pointer.

◆ Replace() [4/4]

StringBuilder * System::Text::StringBuilder::Replace ( const String oldString,
const String newString,
int  position,
int  count 
)

Replaces substring through the builder's range.

Parameters
oldStringString to replace.
newStringReplacement string.
positionBuilder's replacement range beginning position.
countBuilder's replacement range length.
Returns
This pointer.

◆ set_Capacity()

void System::Text::StringBuilder::set_Capacity ( int  capacity)

Sets current capacity of string builder.

Parameters
capacityMaximum number of characters that can be contained in the memory allocated by the current instance.

◆ set_Length()

void System::Text::StringBuilder::set_Length ( int  len)

Trunkates or extends string builder to specified length.

Parameters
lenLength to set.

◆ ToString() [1/2]

String System::Text::StringBuilder::ToString ( ) const
overridevirtual

Gets string currently contained in builder.

Returns
String representation of builder's data.

Reimplemented from System::Object.

◆ ToString() [2/2]

String System::Text::StringBuilder::ToString ( int  startIndex,
int  length 
) const

Gets substring currently contained in builder.

Parameters
startIndexExtraction range beginning index.
lengthNumber of characters to extract.
Returns
String representation of builder's data subrange.