wowlib
0.0.0
Read & write World of Warcraft client files — a C++26 core
Toggle main menu visibility
Loading...
Searching...
No Matches
locstring.hpp
Go to the documentation of this file.
1
#pragma once
2
8
9
#include <array>
10
#include <cstddef>
11
#include <cstdint>
12
#include <optional>
13
#include <string>
14
#include <string_view>
15
16
#include <welder/vocabulary.hpp>
17
18
#include <
wowlib/core/client_version.hpp
>
19
#include <
wowlib/core/error.hpp
>
20
21
namespace
wowlib::db
{
28
constexpr
std::optional<std::size_t>
localeColumnSlot
(
Locale
locale) {
29
switch
(locale) {
30
case
Locale::enUS
:
31
case
Locale::enGB
:
return
0;
32
case
Locale::koKR
:
return
1;
33
case
Locale::frFR
:
return
2;
34
case
Locale::deDE
:
return
3;
35
case
Locale::zhCN
:
return
4;
36
case
Locale::zhTW
:
return
5;
37
case
Locale::esES
:
return
6;
38
case
Locale::esMX
:
return
7;
39
case
Locale::ruRU
:
return
8;
40
case
Locale::ptBR
:
return
10;
41
case
Locale::itIT
:
return
11;
42
}
43
return
std::nullopt;
44
}
45
51
template
<std::
size_t
Langs>
52
struct
[[
53
=welder::weld,
54
=welder::doc(R
"(
55
A localized string column of a pre-Cataclysm client database: one string
56
per language slot in the client's fixed column order, plus the locale
57
flags field. Use at()/set() to address slots by Locale.)")
58
]]
LocString
{
59
[[=welder::mark::no_reassign,
60
=welder::doc(
61
"The language slot values in client column order (0 enUS, 1 koKR, "
62
"2 frFR, 3 deDE, 4 zhCN, 5 zhTW, 6 esES, 7 esMX, then ruRU/ptBR/"
63
"itIT for 16-slot eras); empty for languages the file does not "
64
"carry."
)]]
65
std::array<std::string, Langs>
values
{};
66
67
[[=welder::doc(
68
"The trailing locale flags field; a bitmask the client never "
69
"reads, preserved verbatim."
)]]
70
std::uint32_t
flags
= 0;
71
73
76
[[nodiscard]]
77
[[=welder::doc(
78
"The string stored for a locale; empty when the locale has no "
79
"slot in this client era."
),
80
=welder::returns(
"the slot value, empty when absent"
)]]
81
std::string_view
at
(
Locale
locale [[=welder::doc(
"the locale to look up"
)]])
const
{
82
const
auto
slot =
localeColumnSlot
(locale);
83
if
(!slot || *slot >= Langs)
return
{};
84
return
values[*slot];
85
}
86
92
[[=welder::doc(
"Store a string in a locale's slot."
),
93
=welder::returns(
"nothing; raises when the locale has no slot in this "
94
"client era"
)]]
95
Result<void>
set
(
Locale
locale [[=welder::doc(
"the locale to write"
)]],
96
std::string_view value [[=welder::doc(
97
"the string to store"
)]]) {
98
const
auto
slot =
localeColumnSlot
(locale);
99
if
(!slot || *slot >= Langs)
100
return
makeError
(
ErrorCode::NotSupported
,
101
std::string{
"locale "
} + std::string{
localeCode
(locale)} +
102
" has no langstringref slot in this client era"
);
103
values[*slot] = value;
104
return
{};
105
}
106
107
constexpr
bool
operator==(
const
LocString
&)
const
=
default
;
108
};
109
111
using
LocString8
=
LocString<8>
;
112
114
using
LocString16
=
LocString<16>
;
115
}
client_version.hpp
Client version identity, the flavor axis that separates a client's CONTENT version from the engine ge...
error.hpp
The error-handling vocabulary: ErrorCode, Error and the Result<T> alias every fallible wowlib operati...
wowlib::db
Definition
annotations.hpp:31
wowlib::db::localeColumnSlot
constexpr std::optional< std::size_t > localeColumnSlot(Locale locale)
The langstringref column slot locale occupies, in the client's fixed column order (0 enUS/enGB,...
Definition
locstring.hpp:28
wowlib::db::LocString16
LocString< 16 > LocString16
The TBC..WotLK column shape: 16 language slots (2.1.0.6692+).
Definition
locstring.hpp:101
wowlib::db::LocString8
LocString< 8 > LocString8
The vanilla-era column shape: 8 language slots (pre-2.1.0.6692).
Definition
locstring.hpp:98
wowlib::Result
std::expected< T, Error > Result
Every fallible wowlib operation returns Result<T>; bindings translate the error branch into a target-...
Definition
error.hpp:100
wowlib::localeCode
std::string_view localeCode(Locale locale)
The four-letter code of locale ("enUS", ...) as used in MPQ locale directory and archive names.
Definition
client_version.cpp:55
wowlib::Locale
Locale
Definition
client_version.hpp:285
wowlib::Locale::itIT
@ itIT
Definition
client_version.hpp:297
wowlib::Locale::deDE
@ deDE
Definition
client_version.hpp:288
wowlib::Locale::ruRU
@ ruRU
Definition
client_version.hpp:290
wowlib::Locale::frFR
@ frFR
Definition
client_version.hpp:289
wowlib::Locale::koKR
@ koKR
Definition
client_version.hpp:293
wowlib::Locale::zhCN
@ zhCN
Definition
client_version.hpp:294
wowlib::Locale::zhTW
@ zhTW
Definition
client_version.hpp:295
wowlib::Locale::enGB
@ enGB
Definition
client_version.hpp:287
wowlib::Locale::esMX
@ esMX
Definition
client_version.hpp:292
wowlib::Locale::esES
@ esES
Definition
client_version.hpp:291
wowlib::Locale::ptBR
@ ptBR
Definition
client_version.hpp:296
wowlib::Locale::enUS
@ enUS
Definition
client_version.hpp:286
wowlib::makeError
std::unexpected< Error > makeError(ErrorCode code, std::string message, std::uint32_t nativeError=0)
Shorthand for constructing the error branch of a Result.
Definition
error.hpp:107
wowlib::ErrorCode::NotSupported
@ NotSupported
Operation not supported by this backend/provider.
Definition
error.hpp:32
wowlib::db::LocString
A decoded pre-Cataclysm localized string column: Langs language slots (8 before TBC 2....
Definition
locstring.hpp:52
wowlib::db::LocString< 8 >::values
std::array< std::string, Langs > values
Definition
locstring.hpp:54
wowlib::db::LocString< 8 >::flags
std::uint32_t flags
Definition
locstring.hpp:57
wowlib::db::LocString::at
std::string_view at(Locale locale) const
The string stored for locale.
Definition
locstring.hpp:68
wowlib::db::LocString::operator==
constexpr bool operator==(const LocString &) const =default
wowlib::db::LocString::set
Result< void > set(Locale locale, std::string_view value)
Store value in the slot of locale.
Definition
locstring.hpp:83
src
wowlib
db
locstring.hpp
Generated by
1.17.0