Class String

Class Documentation

class String

Custom string class that we can use safely across a DLL boundary.

Public Functions

String()

Constructs an empty string.

~String()

Destructor.

Frees string memory.

explicit String(char const *const Text, size_t Length)

Constructs a string from a pointer with a given length.

Parameters
  • Text – const char* : Pointer to a string buffer to copy data from

  • Length – size_t : Size of buffer

explicit String(size_t Length)

Constructs a string with a given length.

Buffer is set to 0 for debug builds. Buffer isn’t guaranteed to be set to a particular value for release builds.

Parameters

Length – size_t : Size of buffer

String(const char *Text)

Constructs a string from a cstring.

In buffer is treated as a cstring and will assume the end of the buffer is the first /0.

Parameters

Text – const char* : Pointer to a string buffer to copy data from

String(String const &Other)

Copy constructor.

Parameters

OtherString const&

String(String &&Other)

Move constructor.

String &operator=(const String &Rhs)

Copy assignment.

Parameters

Rhs – const String&

Returns

String&

String &operator=(String &&Rhs)

Move assignment.

Parameters

Rhs – const String&

Returns

String&

String &operator=(char const *const Text)

Assigns a cstring to the string.

Parameters

Text – const char* : Pointer to a string buffer to copy data from

String &swap(String &Other)

Swaps string data with given string.

Parameters

OtherString& : String to swap data with

inline operator char const*() const

Auto converts to cstring by returning internal buffer.

inline char const *c_str() const

Returns internal buffer.

Returns

char const*

List<String> Split(char Delimiter) const

Splits current string by a given delimiter into individual elements.

Parameters

Delimiter – char

Returns

csp::common::List<csp::common::String>

bool operator==(const String &Other) const
bool operator==(const char *Other) const
bool operator!=(const String &Other) const
bool operator!=(const char *Other) const
bool operator<(const String &Other) const
void Append(const String &Other)

Appends given string.

This will resize the buffer of the current string.

Parameters

Other – const String& : String to append

void Append(const char *Other)

Appends given cstring.

This will resize the buffer of the current string.

Parameters

Other – const char* : Cstring to append

String &operator+=(const String &Other)

Appends given string.

This will resize the buffer of the current string.

Parameters

Other – const String& : String to append

Returns

String&

String &operator+=(const char *Other)

Appends given cstring.

This will resize the buffer of the current string.

Parameters

Other – const char* : Cstring to append

Returns

String&

size_t Length() const

Returns the length of the string.

Returns

size_t

size_t AllocatedMemorySize() const

Returns the length of the string including the terminator.

Returns

size_t

bool IsEmpty() const

Checks if the string has any data.

Returns

bool : Returns true if buffer size > 0

String Trim() const

Returns a copy of this string with all leading and trailing whitespace removed.

Returns

String : A copy of this string with leading and trailing whitespace removed.

String ToLower() const

Returns a copy of this string with all characters converted to lower-case.

Returns

String : A copy of this string with characters converted to lower-case.

Public Static Functions

static String Join(const List<String> &Parts, Optional<char> Separator = nullptr)

Concatenates all elements in the list with a separator after each element and returns as a string.

Parameters
  • Parts – const csp::common::List<String>& : List to concatenate

  • Separator – csp::common::Optional<char> : An optional separator to add after each concatenated element

Returns

String

static String Join(const std::initializer_list<String> &Parts, Optional<char> Separator = nullptr)

Concatenates all elements in the initializer_list and returns as a string.

Parameters
  • Parts – const std::initializer_list<String>& : initializer_list to concatenate

  • Separator – csp::common::Optional<char> : An optional separator to add after each concatenated element

Returns

String

Friends

inline friend String operator+(String Lhs, const String &Rhs)

Returns a new string created by appending rhs string to lhs string.

Parameters
Returns

String

inline friend String operator+(String Lhs, const char *Rhs)

Returns a new string created by appending rhs cstring to lhs string.

Parameters
  • LhsString : String to append to

  • Rhs – const char* : Cstring to append

Returns

String