OpenTTD Source 20250328-master-gc3457cd4c0
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()

◆ 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
paramIndex of parameter to replace.
dataNew data for parameter.
Returns
a new EncodedString with the parameter replaced.

Definition at line 153 of file strings.cpp.

References GetEncodedStringWithArgs, SCC_ENCODED_INTERNAL, SCC_ENCODED_NUMERIC, SCC_ENCODED_STRING, and Utf8Decode().

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
strThe StringID to format.
paramsThe 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: