diff options
author | rubidium42 <rubidium@openttd.org> | 2021-05-14 18:32:58 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-15 10:20:50 +0200 |
commit | 2e0297b0fa85e0a8130e24122ab93c74b6a83002 (patch) | |
tree | 8eb24f037b29bbd24b27f1b116269e33fd243ee6 | |
parent | e6703eac6853851f310923760b194ee4c875251b (diff) | |
download | openttd-2e0297b0fa85e0a8130e24122ab93c74b6a83002.tar.xz |
Add: GetString that returns std::string instead of filling a passed buffer
-rw-r--r-- | src/strings.cpp | 12 | ||||
-rw-r--r-- | src/strings_func.h | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/strings.cpp b/src/strings.cpp index 8c9ac0aaf..6a0d1a880 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -285,6 +285,18 @@ char *GetString(char *buffr, StringID string, const char *last) return GetStringWithArgs(buffr, string, &_global_string_params, last); } +/** + * Resolve the given StringID into a std::string with all the associated + * DParam lookups and formatting. + * @param string The unique identifier of the translatable string. + * @return The std::string of the translated string. + */ +std::string GetString(StringID string) +{ + char buffer[DRAW_STRING_BUFFER]; + GetString(buffer, string, lastof(buffer)); + return buffer; +} /** * This function is used to "bind" a C string to a OpenTTD dparam slot. diff --git a/src/strings_func.h b/src/strings_func.h index be59b091a..11f41d738 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -172,6 +172,7 @@ public: extern StringParameters _global_string_params; char *GetString(char *buffr, StringID string, const char *last); +std::string GetString(StringID string); char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, const char *last, uint case_index = 0, bool game_script = false); const char *GetStringPtr(StringID string); |