OpenTTD Source 20241224-master-gf74b0cf984
StringBuilder Class Reference

Equivalent to the std::back_insert_iterator in function, with some convenience helpers for string concatenation. More...

#include <strings_internal.h>

Public Types

using value_type = void
 
using difference_type = void
 
using iterator_category = std::output_iterator_tag
 
using pointer = void
 
using reference = void
 

Public Member Functions

 StringBuilder (std::string &string)
 Create the builder of an external buffer.
 
StringBuilderoperator++ ()
 
StringBuilder operator++ (int)
 
StringBuilderoperator* ()
 
StringBuilderoperator= (const char value)
 Operator to add a character to the end of the buffer.
 
StringBuilderoperator+= (const char value)
 Operator to add a character to the end of the buffer.
 
StringBuilderoperator+= (std::string_view str)
 Operator to append the given string to the output buffer.
 
void Utf8Encode (char32_t c)
 Encode the given Utf8 character into the output buffer.
 
void RemoveElementsFromBack (size_t amount)
 Remove the given amount of characters from the back of the string.
 
size_t CurrentIndex ()
 Get the current index in the string.
 
char & operator[] (size_t index)
 Get the reference to the character at the given index.
 

Private Attributes

std::string * string
 

Detailed Description

Equivalent to the std::back_insert_iterator in function, with some convenience helpers for string concatenation.

Definition at line 248 of file strings_internal.h.

Member Typedef Documentation

◆ difference_type

using StringBuilder::difference_type = void

Definition at line 254 of file strings_internal.h.

◆ iterator_category

using StringBuilder::iterator_category = std::output_iterator_tag

Definition at line 255 of file strings_internal.h.

◆ pointer

using StringBuilder::pointer = void

Definition at line 256 of file strings_internal.h.

◆ reference

using StringBuilder::reference = void

Definition at line 257 of file strings_internal.h.

◆ value_type

using StringBuilder::value_type = void

Definition at line 253 of file strings_internal.h.

Constructor & Destructor Documentation

◆ StringBuilder()

StringBuilder::StringBuilder ( std::string &  string)
inline

Create the builder of an external buffer.

Parameters
stringThe string to write to.

Definition at line 263 of file strings_internal.h.

Member Function Documentation

◆ CurrentIndex()

size_t StringBuilder::CurrentIndex ( )
inline

Get the current index in the string.

Returns
The index.

Definition at line 327 of file strings_internal.h.

Referenced by MakeCzechTownName(), MakeEnglishAdditionalTownName(), MakeEnglishOriginalTownName(), MakeFinnishTownName(), and ReplaceWords().

◆ operator*()

StringBuilder & StringBuilder::operator* ( )
inline

Definition at line 268 of file strings_internal.h.

◆ operator++() [1/2]

StringBuilder & StringBuilder::operator++ ( )
inline

Definition at line 266 of file strings_internal.h.

◆ operator++() [2/2]

StringBuilder StringBuilder::operator++ ( int  )
inline

Definition at line 267 of file strings_internal.h.

◆ operator+=() [1/2]

StringBuilder & StringBuilder::operator+= ( const char  value)
inline

Operator to add a character to the end of the buffer.

Parameters
valueThe character to add.
Returns
Reference to this inserter.

Definition at line 287 of file strings_internal.h.

Referenced by operator=().

◆ operator+=() [2/2]

StringBuilder & StringBuilder::operator+= ( std::string_view  str)
inline

Operator to append the given string to the output buffer.

Parameters
strThe string to add.
Returns
Reference to this inserter.

Definition at line 298 of file strings_internal.h.

◆ operator=()

StringBuilder & StringBuilder::operator= ( const char  value)
inline

Operator to add a character to the end of the buffer.

Like the back insert iterators this also increases the position of the end of the buffer.

Parameters
valueThe character to add.
Returns
Reference to this inserter.

Definition at line 277 of file strings_internal.h.

References operator+=().

◆ operator[]()

char & StringBuilder::operator[] ( size_t  index)
inline

Get the reference to the character at the given index.

Returns
The reference to the character.

Definition at line 336 of file strings_internal.h.

◆ RemoveElementsFromBack()

void StringBuilder::RemoveElementsFromBack ( size_t  amount)
inline

Remove the given amount of characters from the back of the string.

Parameters
amountThe amount of characters to remove.

Definition at line 318 of file strings_internal.h.

Referenced by MakeCzechTownName().

◆ Utf8Encode()

void StringBuilder::Utf8Encode ( char32_t  c)
inline

Encode the given Utf8 character into the output buffer.

Parameters
cThe character to encode.

Definition at line 308 of file strings_internal.h.

References Utf8Encode().

Referenced by FormatString(), and Utf8Encode().

Field Documentation

◆ string

std::string* StringBuilder::string
private

Definition at line 249 of file strings_internal.h.


The documentation for this class was generated from the following file: