summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-04-29 19:04:27 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-13 23:13:17 +0200
commita032714dc4ca2b620af1ba9a444840d46ec9326f (patch)
tree9a97d456de8f1fdeb7c65dd5d38ad0304182da81 /src/script
parent95386dc2b8404519c91b9e0ad728c39fb1d9e118 (diff)
downloadopenttd-a032714dc4ca2b620af1ba9a444840d46ec9326f.tar.xz
Codechange: move script settings to std::string
Diffstat (limited to 'src/script')
-rw-r--r--src/script/script_config.cpp12
-rw-r--r--src/script/script_config.hpp4
2 files changed, 10 insertions, 6 deletions
diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp
index eeab51bed..340b3b3f1 100644
--- a/src/script/script_config.cpp
+++ b/src/script/script_config.cpp
@@ -179,9 +179,9 @@ int ScriptConfig::GetVersion() const
return this->version;
}
-void ScriptConfig::StringToSettings(const char *value)
+void ScriptConfig::StringToSettings(const std::string &value)
{
- char *value_copy = stredup(value);
+ char *value_copy = stredup(value.c_str());
char *s = value_copy;
while (s != nullptr) {
@@ -205,8 +205,10 @@ void ScriptConfig::StringToSettings(const char *value)
free(value_copy);
}
-void ScriptConfig::SettingsToString(char *string, const char *last) const
+std::string ScriptConfig::SettingsToString() const
{
+ char string[1024];
+ char *last = lastof(string);
char *s = string;
*s = '\0';
for (const auto &item : this->settings) {
@@ -216,7 +218,7 @@ void ScriptConfig::SettingsToString(char *string, const char *last) const
/* Check if the string would fit in the destination */
size_t needed_size = strlen(item.first) + 1 + strlen(no);
/* If it doesn't fit, skip the next settings */
- if (string + needed_size > last) break;
+ if (s + needed_size > last) break;
s = strecat(s, item.first, last);
s = strecat(s, "=", last);
@@ -226,6 +228,8 @@ void ScriptConfig::SettingsToString(char *string, const char *last) const
/* Remove the last ',', but only if at least one setting was saved. */
if (s != string) s[-1] = '\0';
+
+ return string;
}
const char *ScriptConfig::GetTextfile(TextfileType type, CompanyID slot) const
diff --git a/src/script/script_config.hpp b/src/script/script_config.hpp
index be231fcdc..7ddc0ab6a 100644
--- a/src/script/script_config.hpp
+++ b/src/script/script_config.hpp
@@ -169,13 +169,13 @@ public:
* Convert a string which is stored in the config file or savegames to
* custom settings of this Script.
*/
- void StringToSettings(const char *value);
+ void StringToSettings(const std::string &value);
/**
* Convert the custom settings to a string that can be stored in the config
* file or savegames.
*/
- void SettingsToString(char *string, const char *last) const;
+ std::string SettingsToString() const;
/**
* Search a textfile file next to this script.