Skip to content

Commit

Permalink
Make format and error member functions in I18n class constant
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedsiam0 committed Jan 23, 2024
1 parent 7dc64e2 commit 0526f61
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lttoolbox/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class I18n
public:
I18n(const char *locales_path, std::string package_name);
icu::UnicodeString format(const char* key, const std::vector<icu::UnicodeString> arg_names,
const std::vector<icu::Formattable> arg_values);
icu::UnicodeString format(const char* key);
const std::vector<icu::Formattable> arg_values) const;
icu::UnicodeString format(const char* key) const;
void error(const char* key, const std::vector<icu::UnicodeString> arg_names,
const std::vector<icu::Formattable> arg_values, bool quit);
void error(const char* key, bool quit);
const std::vector<icu::Formattable> arg_values, bool quit) const;
void error(const char* key, bool quit) const;
};

// Store .dat files and map it to package name of it.
Expand All @@ -39,7 +39,7 @@ inline std::unordered_map<std::string, std::unique_ptr<char[]>> I18n::locales_da
// being overriden by LtLocale::tryToSetLocale() function.
inline icu::Locale I18n::locale = icu::Locale().getName();

inline I18n::I18n(const char *locales_path, std::string package_name) : resource("", "", status)
inline I18n::I18n(const char *locales_path, std::string package_name) : resource(status)
{
// Initialize status.
status = U_ZERO_ERROR;
Expand Down Expand Up @@ -90,8 +90,9 @@ inline I18n::I18n(const char *locales_path, std::string package_name) : resource
}

inline icu::UnicodeString I18n::format(const char* key, const std::vector<icu::UnicodeString> arg_names,
const std::vector<icu::Formattable> arg_values)
const std::vector<icu::Formattable> arg_values) const
{
UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString pattern;
icu::UnicodeString output;

Expand Down Expand Up @@ -141,20 +142,20 @@ inline icu::UnicodeString I18n::format(const char* key, const std::vector<icu::U
return output;
}

inline icu::UnicodeString I18n::format(const char* key)
inline icu::UnicodeString I18n::format(const char* key) const
{
return format(key, {}, {});
}

inline void I18n::error(const char* key, const std::vector<icu::UnicodeString> arg_names,
const std::vector<icu::Formattable> arg_values, bool quit)
const std::vector<icu::Formattable> arg_values, bool quit) const
{
std::cerr << format(key, arg_names, arg_values) << std::endl;
if (quit) {
exit(EXIT_FAILURE);
}
}
inline void I18n::error(const char* key, bool quit)
inline void I18n::error(const char* key, bool quit) const
{
error(key, {}, {}, quit);
}
Expand Down

0 comments on commit 0526f61

Please sign in to comment.