Merge pull request #2386 from myk002/myk_more_misc

[MiscUtils] add string_to_int
develop
Myk 2022-11-09 15:36:05 -08:00 committed by GitHub
commit b8c3c96db6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 15 deletions

@ -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``.

@ -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 &ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char x){ return !std::isspace(x); }));

@ -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();