13#include "../core/string_consumer.hpp"
14#include "../language.h"
15#include "../string_type.h"
16#include "../3rdparty/fmt/format.h"
18#include <unordered_map>
44 std::vector<std::shared_ptr<LangString>>
strings;
52 void Add(std::shared_ptr<LangString> ls);
67 void HandleString(std::string_view str);
73 virtual std::optional<std::string>
ReadLine() = 0;
94 virtual void WriteStringID(
const std::string &name,
size_t stringid) = 0;
121 virtual void Write(std::string_view buffer) = 0;
143 std::vector<CmdPair> non_consuming_commands;
144 std::array<const CmdStruct*, 32> consuming_commands{
nullptr };
150void StrgenWarningI(
const std::string &msg);
151void StrgenErrorI(
const std::string &msg);
152[[noreturn]]
void StrgenFatalI(
const std::string &msg);
153#define StrgenWarning(format_string, ...) StrgenWarningI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
154#define StrgenError(format_string, ...) StrgenErrorI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
155#define StrgenFatal(format_string, ...) StrgenFatalI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
156std::optional<std::string_view> ParseWord(
StringConsumer &consumer);
160 std::string
file =
"(unknown file)";
164 bool show_warnings =
false;
165 bool annotate_todos =
false;
Parse data from a string / buffer.
Container for the different cases of a string.
uint8_t caseidx
The index of the case.
std::string string
The translation of the case.
Information about a single string.
size_t line
Line of string in source-file.
std::string english
English text.
std::vector< Case > translated_cases
Cases of the translation.
std::string translated
Translated text.
void FreeTranslation()
Free all data related to the translation.
std::string name
Name of the string.
size_t index
The index in the language file.
Base class for all language writers.
virtual void WriteHeader(const LanguagePackHeader *header)=0
Write the header metadata.
virtual void Finalise()=0
Finalise writing the file.
virtual void WriteLength(size_t length)
Write the length as a simple gamma.
virtual void Write(std::string_view buffer)=0
Write a number of bytes.
virtual ~LanguageWriter()=default
Especially destroy the subclasses.
virtual void WriteLang(const StringData &data)
Actually write the language.
Global state shared between strgen.cpp, game_text.cpp and strgen_base.cpp.
std::string file
The filename of the input, so we can refer to it in errors/warnings.
bool translation
Is the current file actually a translation or not.
LanguagePackHeader lang
Header information about a language.
size_t cur_line
The current line we're parsing in the input file.
Information about the currently known strings.
size_t tabs
The number of 'tabs' of strings.
void Add(std::shared_ptr< LangString > ls)
Add a newly created LangString.
size_t max_strings
The maximum number of strings.
size_t next_string_id
The next string ID to allocate.
void FreeTranslation()
Free all data related to the translation.
LangString * Find(std::string_view s)
Find a LangString based on the string name.
std::unordered_map< std::string, std::shared_ptr< LangString >, StringHash, std::equal_to<> > name_to_string
Lookup table for the strings.
std::vector< std::shared_ptr< LangString > > strings
List of all known strings.
uint32_t Version() const
Make a hash of the file to get a unique "version number".
size_t CountInUse(size_t tab) const
Count the number of tab elements that are in use.
Helper to provide transparent hashing for string types in e.g.
Helper for reading strings.
const std::string file
The file we are reading.
StringData & data
The data to fill during reading.
virtual void ParseFile()
Start parsing the file.
bool translation
Are we reading a translation, implies !master. However, the base translation will have this false.
virtual void HandlePragma(std::string_view str, LanguagePackHeader &lang)
Handle the pragma of the file.
virtual std::optional< std::string > ReadLine()=0
Read a single line from the source of strings.
bool master
Are we reading the master file?