OpenTTD Source: StringReader Struct Reference

OpenTTD Source 15.3

Public Member Functions | Data Fields
StringReader Struct Referenceabstract

Helper for reading strings. More...

`#include <strgen.h>`

Inheritance diagram for StringReader:

## Public Member Functions
| StringReader (StringData &data, const std::string &file, bool master, bool translation)
| Prepare reading.
void | HandleString (std::string_view str)
virtual std::optional< std::string > | ReadLine ()=0
| Read a single line from the source of strings.
virtual void | HandlePragma (std::string_view str, LanguagePackHeader &lang)
| Handle the pragma of the file.
virtual void | ParseFile ()
| Start parsing the file.

## Data Fields
StringData & | data
| The data to fill during reading.
const std::string | file
| The file we are reading.
bool | master
| Are we reading the master file?
bool | translation
| Are we reading a translation, implies !master. However, the base translation will have this false.

## Detailed Description

Helper for reading strings.

Definition at line 59 of file strgen.h.

## Constructor & Destructor Documentation

## ◆ StringReader()

StringReader::StringReader | ( | StringData & | data,
|  | const std::string & | file,
|  | bool | master,
|  | bool | translation
| ) |  |

Prepare reading.

Parameters

  data | The data to fill during reading.
  file | The file we are reading.
  master | Are we reading the master file?
  translation | Are we reading a translation?

Definition at line 378 of file strgen_base.cpp.

## Member Function Documentation

## ◆ HandlePragma()

void StringReader::HandlePragma | ( | std::string_view | str,
|  | LanguagePackHeader & | lang
| ) |  |
| virtual

Handle the pragma of the file.

Parameters

  str | The pragma string to parse.

Reimplemented in FileStringReader.

Definition at line 562 of file strgen_base.cpp.

References _plural_forms, lengthof, LanguagePackHeader::plural_form, StringConsumer::ReadIntegerBase(), StringConsumer::ReadUntilChar(), and StringConsumer::SKIP_ALL_SEPARATORS.

Referenced by FileStringReader::HandlePragma().

## ◆ HandleString()

void StringReader::HandleString | ( | std::string_view | str | ) |

Definition at line 475 of file strgen_base.cpp.

## ◆ ParseFile()

void StringReader::ParseFile | ( |  | ) |
| virtual

Start parsing the file.

Reimplemented in FileStringReader.

Definition at line 576 of file strgen_base.cpp.

References StrgenState::cur_line, data, file, StrgenState::file, StrgenState::lang, StringData::max_strings, StringData::next_string_id, ReadLine(), translation, StrgenState::translation, and StringConsumer::WHITESPACE_OR_NEWLINE.

Referenced by GameStrings::Compile(), and FileStringReader::ParseFile().

## ◆ ReadLine()

virtual std::optional< std::string > StringReader::ReadLine | ( |  | ) |
| pure virtual

Read a single line from the source of strings.

Returns
  The line, or std::nullopt if at the end of the file.

Implemented in StringListReader, and FileStringReader.

Referenced by ParseFile().

## Field Documentation

## ◆ data

StringData& StringReader::data

The data to fill during reading.

Definition at line 60 of file strgen.h.

Referenced by FileStringReader::HandlePragma(), and ParseFile().

## ◆ file

const std::string StringReader::file

The file we are reading.

Definition at line 61 of file strgen.h.

Referenced by FileStringReader::FileStringReader(), and ParseFile().

## ◆ master

bool StringReader::master

Are we reading the master file?

Definition at line 62 of file strgen.h.

Referenced by FileStringReader::HandlePragma().

## ◆ translation

bool StringReader::translation

Are we reading a translation, implies !master. However, the base translation will have this false.

Definition at line 63 of file strgen.h.

Referenced by ParseFile().

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

- src/strgen/strgen.h
- src/strgen/strgen_base.cpp