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);
68 void HandleString(std::string_view str);
74 virtual std::optional<std::string>
ReadLine() = 0;
96 virtual void WriteStringID(
const std::string &name,
size_t stringid) = 0;
123 virtual void Write(std::string_view buffer) = 0;
143 auto operator<=>(
const CmdPair &other)
const =
default;
147 std::vector<CmdPair> non_consuming_commands;
154void StrgenWarningI(
const std::string &msg);
155void StrgenErrorI(
const std::string &msg);
156[[noreturn]]
void StrgenFatalI(
const std::string &msg);
157#define StrgenWarning(format_string, ...) StrgenWarningI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
158#define StrgenError(format_string, ...) StrgenErrorI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
159#define StrgenFatal(format_string, ...) StrgenFatalI(fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__))
160std::optional<std::string_view> ParseWord(
StringConsumer &consumer);
164 std::string
file =
"(unknown file)";
168 bool show_warnings =
false;
169 bool annotate_todos =
false;
Parse data from a string / buffer.
Information about languages and their files.
Case(uint8_t caseidx, std::string_view string)
Create a new case.
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.
LangString(std::string_view name, std::string_view english, size_t index, size_t line)
Create a new string.
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
Ensure the destructor of the sub classes are called as well.
virtual void WriteLang(const StringData &data)
Actually write the language.
std::array< const CmdStruct *, 32 > consuming_commands
Ordered by param #.
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.
StringData(size_t tabs)
Create a new string data container.
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.
const std::string file
The file we are reading.
StringReader(StringData &data, const std::string &file, bool master, bool translation)
Prepare 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?
virtual ~StringReader()=default
Ensure the destructor of the sub classes are called as well.