diff --git a/docs/changelog.txt b/docs/changelog.txt index b90248c91..980301c27 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -73,7 +73,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - ``Lua::PushInterfaceKeys()``: transforms viewscreen ``feed()`` keys into something that can be interpreted by lua-based widgets - ``Lua::Push()``: now handles maps with otherwise supported keys and values - Constructions module: added ``insert()`` to insert constructions into the game's sorted list. -- MiscUtils: moved the following string transformation functions from ``uicommon.h``: ``int_to_string``, ``ltrim``, ``rtrim``, and ``trim`` +- MiscUtils: moved the following string transformation functions from ``uicommon.h``: ``int_to_string``, ``ltrim``, ``rtrim``, and ``trim``; added ``string_to_int`` ## Lua - ``widgets.Scrollbar``: new scrollbar widget that can be paired with an associated scrollable widget. Integrated with ``widgets.Label`` and ``widgets.List``. diff --git a/library/include/MiscUtils.h b/library/include/MiscUtils.h index b361bdbdb..d089640ef 100644 --- a/library/include/MiscUtils.h +++ b/library/include/MiscUtils.h @@ -387,13 +387,21 @@ DFHACK_EXPORT std::string toUpper(const std::string &str); DFHACK_EXPORT std::string toLower(const std::string &str); DFHACK_EXPORT std::string to_search_normalized(const std::string &str); -static inline std::string int_to_string(const int n) -{ +static inline std::string int_to_string(const int n) { std::ostringstream ss; ss << n; return ss.str(); } +static inline int string_to_int(const std::string s, int default_ = 0) { + try { + return std::stoi(s); + } + catch (std::exception&) { + return default_; + } +} + // trim from start static inline std::string <rim(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char x){ return !std::isspace(x); })); diff --git a/plugins/autochop.cpp b/plugins/autochop.cpp index 82c40934c..acb8959b9 100644 --- a/plugins/autochop.cpp +++ b/plugins/autochop.cpp @@ -185,18 +185,6 @@ private: static WatchedBurrows watchedBurrows; -static int string_to_int(string s, int default_ = 0) -{ - try - { - return std::stoi(s); - } - catch (std::exception&) - { - return default_; - } -} - static void save_config() { config_autochop.val() = watchedBurrows.getSerialisedIds();