diff --git a/module/Base/Utility.cpp b/module/Base/Utility.cpp index bcd87ddd..9ce7a8ce 100644 --- a/module/Base/Utility.cpp +++ b/module/Base/Utility.cpp @@ -298,6 +298,14 @@ String & NullString() return s; } +// ------------------------------------------------------------------------------------------------ +String & StringRef(const SQChar * str) +{ + static String s; + s.assign(str); + return s; +} + // ------------------------------------------------------------------------------------------------ CSStr ConvNum< Int8 >::ToStr(Int8 v) { diff --git a/module/Base/Utility.hpp b/module/Base/Utility.hpp index e7123435..779429f4 100644 --- a/module/Base/Utility.hpp +++ b/module/Base/Utility.hpp @@ -137,6 +137,11 @@ Function & NullFunction(); */ String & NullString(); +/* ------------------------------------------------------------------------------------------------ + * Retrieve a reference to a static string with a specific value. +*/ +String & StringRef(const SQChar * str); + /* ------------------------------------------------------------------------------------------------ * Compute the next power of two for the specified number. */ diff --git a/module/Core.cpp b/module/Core.cpp index 63d7a0d5..6dc8d89f 100644 --- a/module/Core.cpp +++ b/module/Core.cpp @@ -581,21 +581,21 @@ void Core::EnableNullEntities() } // ------------------------------------------------------------------------------------------------ -CSStr Core::GetOption(CSStr name) const +const String & Core::GetOption(const String & name) const { auto elem = m_Options.find(name); - return (elem == m_Options.end()) ? _SC("") : elem->second.c_str(); + return (elem == m_Options.end()) ? NullString() : elem->second; } // ------------------------------------------------------------------------------------------------ -CSStr Core::GetOption(CSStr name, CSStr value) const +const String & Core::GetOption(const String & name, const String & value) const { auto elem = m_Options.find(name); - return (elem == m_Options.end()) ? value : elem->second.c_str(); + return (elem == m_Options.end()) ? value : elem->second; } // ------------------------------------------------------------------------------------------------ -void Core::SetOption(CSStr name, CSStr value) +void Core::SetOption(const String & name, const String & value) { m_Options[name] = value; } diff --git a/module/Core.hpp b/module/Core.hpp index f9371198..0fc736c9 100644 --- a/module/Core.hpp +++ b/module/Core.hpp @@ -811,17 +811,17 @@ public: /* -------------------------------------------------------------------------------------------- * Retrieve the value of the specified option. */ - CSStr GetOption(CSStr name) const; + const String & GetOption(const String & name) const; /* -------------------------------------------------------------------------------------------- * Retrieve the value of the specified option or the fall back value if it doesn't exist. */ - CSStr GetOption(CSStr name, CSStr value) const; + const String & GetOption(const String & name, const String & value) const; /* -------------------------------------------------------------------------------------------- * Modify the value of the specified option. */ - void SetOption(CSStr name, CSStr value); + void SetOption(const String & name, const String & value); /* -------------------------------------------------------------------------------------------- * Retrieve the script source associated with a certain path in the scripts list. diff --git a/module/Core/Funcs.inc b/module/Core/Funcs.inc index be12ac10..9f179901 100644 --- a/module/Core/Funcs.inc +++ b/module/Core/Funcs.inc @@ -145,21 +145,21 @@ static void SqSetAreasEnabled(bool toggle) } // ------------------------------------------------------------------------------------------------ -static CSStr SqGetOption(CSStr name) +static const String & SqGetOption(StackStrF & name) { - return Core::Get().GetOption(name); + return Core::Get().GetOption(String(name.mPtr, name.mLen)); } // ------------------------------------------------------------------------------------------------ -static CSStr SqGetOptionOr(CSStr name, CSStr value) +static const String & SqGetOptionOr(StackStrF & name, StackStrF & value) { - return Core::Get().GetOption(name, value); + return Core::Get().GetOption(String(name.mPtr, name.mLen), StringRef(value.mPtr)); } // ------------------------------------------------------------------------------------------------ -static void SqSetOption(CSStr name, CSStr value) +static void SqSetOption(StackStrF & name, StackStrF & value) { - return Core::Get().SetOption(name, value); + Core::Get().SetOption(String(name.mPtr, name.mLen), String(value.mPtr, value.mLen)); } // ------------------------------------------------------------------------------------------------