OpenTTD Source  20241121-master-g67a0fccfad
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. More...
 
StringBuilderoperator++ ()
 
StringBuilder operator++ (int)
 
StringBuilderoperator* ()
 
StringBuilderoperator= (const char value)
 Operator to add a character to the end of the buffer. More...
 
StringBuilderoperator+= (const char value)
 Operator to add a character to the end of the buffer. More...
 
StringBuilderoperator+= (std::string_view str)
 Operator to append the given string to the output buffer. More...
 
void Utf8Encode (char32_t c)
 Encode the given Utf8 character into the output buffer. More...
 
void RemoveElementsFromBack (size_t amount)
 Remove the given amount of characters from the back of the string. More...
 
size_t CurrentIndex ()
 Get the current index in the string. More...
 
char & operator[] (size_t index)
 Get the reference to the character at the given index. More...
 

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.

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 MakeEnglishAdditionalTownName(), MakeEnglishOriginalTownName(), MakeFinnishTownName(), and ReplaceWords().

◆ 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.

◆ 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.


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