OpenTTD Source: StringBuilder Class Reference

OpenTTD Source 14.0-beta1

Public Types | Public Member Functions | Private Attributes
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...
StringBuilder & | operator++ ()
StringBuilder | operator++ (int)
StringBuilder & | operator* ()
StringBuilder & | operator= (const char value)
| Operator to add a character to the end of the buffer. More...
StringBuilder & | operator+= (const char value)
| Operator to add a character to the end of the buffer. More...
StringBuilder & | operator+= (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 249 of file strings_internal.h.

## Constructor & Destructor Documentation

## ◆ StringBuilder()

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

Create the builder of an external buffer.

Parameters

  start | The start location to write to.
  last | The last location to write to.

Definition at line 265 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 330 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

  value | The character to add.

Returns
  Reference to this inserter.

Definition at line 289 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

  str | The string to add.

Returns
  Reference to this inserter.

Definition at line 300 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

  value | The character to add.

Returns
  Reference to this inserter.

Definition at line 279 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 339 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

  amount | The amount of characters to remove.

Returns
  true iff there was enough space and the character got added.

Definition at line 321 of file strings_internal.h.

## ◆ Utf8Encode()

void StringBuilder::Utf8Encode | ( | char32_t | c | ) |
| inline

Encode the given Utf8 character into the output buffer.

Parameters

  c | The character to encode.

Definition at line 310 of file strings_internal.h.

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

- src/strings_internal.h