OpenTTD Source: StringBuilder Class Reference

OpenTTD Source 15.3

Public Types | Public Member Functions | Private Attributes
StringBuilder Class Referencefinal

Compose data into a growing std::string. More...

`#include <string_builder.hpp>`

Inheritance diagram for StringBuilder:

## Public Types
using | back_insert_iterator = std::back_insert_iterator< std::string >
Public Types inherited from BaseStringBuilder
using | size_type = std::string_view::size_type

## Public Member Functions
| StringBuilder (std::string &dest)
| Construct StringBuilder into destination string.
bool | AnyBytesWritten () const noexcept
| Check whether any bytes have been written.
size_type | GetBytesWritten () const noexcept
| Get number of already written bytes.
const std::string & | GetWrittenData () const noexcept
| Get already written data.
std::string & | GetString () noexcept
| Get mutable already written data.
void | PutBuffer (std::span< const char > str) override
| Append buffer.
StringBuilder & | operator+= (std::string_view str)
| Append string.
back_insert_iterator | back_inserter ()
| Create a back-insert-iterator.
Public Member Functions inherited from BaseStringBuilder
void | Put (std::string_view str)
| Append string.
void | PutUint8 (uint8_t value)
| Append binary uint8.
void | PutSint8 (int8_t value)
| Append binary int8.
void | PutUint16LE (uint16_t value)
| Append binary uint16 using little endian.
void | PutSint16LE (int16_t value)
| Append binary int16 using little endian.
void | PutUint32LE (uint32_t value)
| Append binary uint32 using little endian.
void | PutSint32LE (int32_t value)
| Append binary int32 using little endian.
void | PutUint64LE (uint64_t value)
| Append binary uint64 using little endian.
void | PutSint64LE (int64_t value)
| Append binary int64 using little endian.
void | PutChar (char c)
| Append 8-bit char.
void | PutUtf8 (char32_t c)
| Append UTF.8 char.
template<class T >
void | PutIntegerBase (T value, int base)
| Append integer 'value' in given number 'base'.

## Private Attributes
std::string * | dest

## Detailed Description

Compose data into a growing std::string.

Definition at line 65 of file string_builder.hpp.

## Member Typedef Documentation

## ◆ back_insert_iterator

using StringBuilder::back_insert_iterator = std::back_insert_iterator<std::string>

Definition at line 102 of file string_builder.hpp.

## Constructor & Destructor Documentation

## ◆ StringBuilder()

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

Construct StringBuilder into destination string.

Note
  The lifetime of the string must exceed the lifetime of the StringBuilder.

Definition at line 72 of file string_builder.hpp.

## Member Function Documentation

## ◆ AnyBytesWritten()

bool StringBuilder::AnyBytesWritten | ( |  | ) | const
| inlinenoexcept

Check whether any bytes have been written.

Definition at line 77 of file string_builder.hpp.

## ◆ back_inserter()

back_insert_iterator StringBuilder::back_inserter | ( |  | ) |
| inline

Create a back-insert-iterator.

Definition at line 106 of file string_builder.hpp.

Referenced by FormatBytes(), and FormatString().

## ◆ GetBytesWritten()

size_type StringBuilder::GetBytesWritten | ( |  | ) | const
| inlinenoexcept

Get number of already written bytes.

Definition at line 81 of file string_builder.hpp.

Referenced by MakeEnglishOriginalTownName().

## ◆ GetString()

std::string & StringBuilder::GetString | ( |  | ) |
| inlinenoexcept

Get mutable already written data.

Definition at line 89 of file string_builder.hpp.

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

## ◆ GetWrittenData()

const std::string & StringBuilder::GetWrittenData | ( |  | ) | const
| inlinenoexcept

Get already written data.

Definition at line 85 of file string_builder.hpp.

## ◆ operator+=()

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

Append string.

Definition at line 96 of file string_builder.hpp.

References BaseStringBuilder::Put().

## ◆ PutBuffer()

void StringBuilder::PutBuffer | ( | std::span< const char > | str | ) |
| overridevirtual

Append buffer.

Implements BaseStringBuilder.

Definition at line 122 of file string_builder.cpp.

## Field Documentation

## ◆ dest

std::string* StringBuilder::dest
| private

Definition at line 66 of file string_builder.hpp.

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

- src/core/string_builder.hpp
- src/core/string_builder.cpp