OpenTTD Source: EncodedString Class Reference

OpenTTD Source 15.3

Public Member Functions | Private Member Functions | Private Attributes | Friends
EncodedString Class Reference

Container for an encoded string, created by GetEncodedString. More...

`#include <strings_type.h>`

## Public Member Functions
auto | operator<=> (const EncodedString &) const =default
std::string | GetDecodedString () const
| Decode the encoded string.
EncodedString | ReplaceParam (size_t param, StringParameter &&value) const
| Replace a parameter of this EncodedString.
void | clear ()
bool | empty () const

## Private Member Functions
| EncodedString (std::string &&string)

## Private Attributes
std::string | string
| The encoded string.

## Friends
template<typename Tcont , typename Titer >
class | EndianBufferWriter
class | EndianBufferReader
class | ScriptText
EncodedString | GetEncodedStringWithArgs (StringID str, std::span< const StringParameter > params)
| Encode a string with its parameters into an encoded string.

## Detailed Description

Container for an encoded string, created by GetEncodedString.

Definition at line 98 of file strings_type.h.

## Constructor & Destructor Documentation

## ◆ EncodedString()

EncodedString::EncodedString | ( | std::string && | string | ) |
| inlineexplicitprivate

Definition at line 114 of file strings_type.h.

## Member Function Documentation

## ◆ clear()

void EncodedString::clear | ( |  | ) |
| inline

Definition at line 107 of file strings_type.h.

## ◆ empty()

bool EncodedString::empty | ( |  | ) | const
| inline

Definition at line 108 of file strings_type.h.

## ◆ GetDecodedString()

std::string EncodedString::GetDecodedString | ( |  | ) | const

Decode the encoded string.

Returns
  Decoded raw string.

Definition at line 207 of file strings.cpp.

References GetString().

Referenced by IndustryViewWindow::DrawInfo(), ErrmsgWindow::DrawWidget(), SaveLoadWindow::DrawWidget(), GoalQuestionWindow::DrawWidget(), ScriptLeagueWindow::DrawWidget(), QueryWindow::DrawWidget(), NewsWindow::DrawWidget(), StoryBookWindow::DrawWidget(), TownViewWindow::DrawWidget(), FileList::FindItem(), TownViewWindow::GetDesiredInfoHeight(), StoryBookWindow::GetHeadHeight(), StoryBookWindow::GetPageElementFloatWidth(), StoryBookWindow::GetPageElementHeight(), GenerateLandscapeWindow::GetWidgetString(), ScriptLeagueWindow::GetWidgetString(), QueryWindow::GetWidgetString(), StoryBookWindow::GetWidgetString(), SaveLoadWindow::OnClick(), FiosItem::operator<(), ErrmsgWindow::UpdateWidgetSize(), GoalQuestionWindow::UpdateWidgetSize(), ScriptLeagueWindow::UpdateWidgetSize(), TooltipsWindow::UpdateWidgetSize(), QueryWindow::UpdateWidgetSize(), NewsWindow::UpdateWidgetSize(), and StoryBookWindow::UpdateWidgetSize().

## ◆ ReplaceParam()

EncodedString EncodedString::ReplaceParam | ( | size_t | param,
|  | StringParameter && | data
| ) |  | const

Replace a parameter of this EncodedString.

Note
  If the string cannot be decoded for some reason, an empty EncodedString will be returned instead.

Parameters

  param | Index of parameter to replace.
  data | New data for parameter.

Returns
  a new EncodedString with the parameter replaced.

Definition at line 150 of file strings.cpp.

References StringConsumer::AnyBytesLeft(), GetEncodedStringWithArgs, StringConsumer::npos, StringConsumer::Read(), StringConsumer::ReadIntegerBase(), StringConsumer::ReadUntilUtf8(), StringConsumer::ReadUtf8(), StringConsumer::ReadUtf8If(), SCC_ENCODED_INTERNAL, SCC_ENCODED_NUMERIC, SCC_ENCODED_STRING, StringConsumer::SKIP_ONE_SEPARATOR, and StringConsumer::TryReadIntegerBase().

Referenced by ChangeVehicleNews().

## Friends And Related Symbol Documentation

## ◆ EndianBufferReader

friend class EndianBufferReader
| friend

Definition at line 120 of file strings_type.h.

## ◆ EndianBufferWriter

template<typename Tcont , typename Titer >

friend class EndianBufferWriter
| friend

Definition at line 119 of file strings_type.h.

## ◆ GetEncodedStringWithArgs

EncodedString GetEncodedStringWithArgs | ( | StringID | str,
|  | std::span< const StringParameter > | params
| ) |  |
| friend

Encode a string with its parameters into an encoded string.

The encoded string can be stored and decoded later without requiring parameters to be stored separately.

Parameters

  str | The StringID to format.
  params | The parameters of the string.

Returns
  The encoded string.

Definition at line 102 of file strings.cpp.

Referenced by ReplaceParam().

## ◆ ScriptText

friend class ScriptText
| friend

Definition at line 121 of file strings_type.h.

## Field Documentation

## ◆ string

std::string EncodedString::string
| private

The encoded string.

Definition at line 111 of file strings_type.h.

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

- src/strings_type.h
- src/strings.cpp