diff options
author | rubidium <rubidium@openttd.org> | 2010-11-13 14:36:43 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-11-13 14:36:43 +0000 |
commit | d46a2ef122a4dc3a44bfba97a1e7c5f112344c0c (patch) | |
tree | 807a3907760ffdeff5d91240397ad9a6ac32edd2 /src/language.h | |
parent | 8aba642ed5bbad969b56bf5b72834ad04599d296 (diff) | |
download | openttd-d46a2ef122a4dc3a44bfba97a1e7c5f112344c0c.tar.xz |
(svn r21165) -Codechange: move the case/gender meta data into the language metadata struct as well
Diffstat (limited to 'src/language.h')
-rw-r--r-- | src/language.h | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/src/language.h b/src/language.h index 6a208ab92..a8de8c0f7 100644 --- a/src/language.h +++ b/src/language.h @@ -14,6 +14,10 @@ #include "core/smallvec_type.hpp" +static const uint8 CASE_GENDER_LEN = 16; ///< The (maximum) length of a case/gender string. +static const uint8 MAX_NUM_GENDERS = 8; ///< Maximum number of supported genders. +static const uint8 MAX_NUM_CASES = 16; ///< Maximum number of supported cases. + /** Header of a language file. */ struct LanguagePackHeader { static const uint32 IDENT = 0x474E414C; ///< Identifier for OpenTTD language files, big endian for "LANG" @@ -43,13 +47,44 @@ struct LanguagePackHeader { */ uint16 winlangid; ///< windows language id uint8 newgrflangid; ///< newgrf language id - byte pad[3]; ///< pad header to be a multiple of 4 + uint8 num_genders; ///< the number of genders of this language + uint8 num_cases; ///< the number of cases of this language + byte pad[1]; ///< pad header to be a multiple of 4 + + char genders[MAX_NUM_GENDERS][CASE_GENDER_LEN]; ///< the genders used by this translation + char cases[MAX_NUM_CASES][CASE_GENDER_LEN]; ///< the cases used by this translation /** * Check whether the header is a valid header for OpenTTD. * @return true iff the header is deemed valid. */ bool IsValid() const; + + /** + * Get the index for the given gender. + * @param gender_str The string representation of the gender. + * @return The index of the gender, or MAX_NUM_GENDERS when the gender is unknown. + */ + uint8 GetGenderIndex(const char *gender_str) const + { + for (uint8 i = 0; i < MAX_NUM_GENDERS; i++) { + if (strcmp(gender_str, this->genders[i]) == 0) return i; + } + return MAX_NUM_GENDERS; + } + + /** + * Get the index for the given case. + * @param case_str The string representation of the case. + * @return The index of the case, or MAX_NUM_CASES when the case is unknown. + */ + uint8 GetCaseIndex(const char *case_str) const + { + for (uint8 i = 0; i < MAX_NUM_CASES; i++) { + if (strcmp(case_str, this->cases[i]) == 0) return i; + } + return MAX_NUM_CASES; + } }; assert_compile(sizeof(LanguagePackHeader) % 4 == 0); |