From 6004cd319d3c865821bc2be29647222c957ed517 Mon Sep 17 00:00:00 2001 From: Simei Yin Date: Wed, 30 May 2018 19:22:46 +0200 Subject: [PATCH] SLUDGE: Move createCString() with string tools --- engines/sludge/moreio.cpp | 11 +++++++++++ engines/sludge/moreio.h | 2 ++ engines/sludge/variable.cpp | 11 ----------- engines/sludge/variable.h | 1 - 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/engines/sludge/moreio.cpp b/engines/sludge/moreio.cpp index 1512574207d..ee9ab8e0f0e 100644 --- a/engines/sludge/moreio.cpp +++ b/engines/sludge/moreio.cpp @@ -167,4 +167,15 @@ Common::String decodeFilename(const Common::String &nameIn) { return newName; } +char *createCString(const Common::String &s) { + uint n = s.size() + 1; + char *res = new char[n]; + if (!checkNew(res)) { + fatal("createCString : Unable to copy String"); + return NULL; + } + memcpy(res, s.c_str(), n); + return res; +} + } // End of namespace Sludge diff --git a/engines/sludge/moreio.h b/engines/sludge/moreio.h index 09235ae8a66..237a918626d 100644 --- a/engines/sludge/moreio.h +++ b/engines/sludge/moreio.h @@ -31,6 +31,8 @@ void writeString(Common::String s, Common::WriteStream *stream); Common::String encodeFilename(const Common::String &nameIn); Common::String decodeFilename(const Common::String &nameIn); +char *createCString(const Common::String &s); + } // End of namespace Sludge #endif diff --git a/engines/sludge/variable.cpp b/engines/sludge/variable.cpp index 35e10365687..b9e7b123d80 100644 --- a/engines/sludge/variable.cpp +++ b/engines/sludge/variable.cpp @@ -239,17 +239,6 @@ void compareVariablesInSecond(const Variable &var1, Variable &var2) { setVariable(var2, SVT_INT, compareVars(var1, var2)); } -char *createCString(const Common::String &s) { - uint n = s.size() + 1; - char *res = new char[n]; - if (!checkNew(res)) { - fatal("createCString : Unable to copy String"); - return NULL; - } - memcpy(res, s.c_str(), n); - return res; -} - void makeTextVar(Variable &thisVar, const Common::String &txt) { unlinkVar(thisVar); thisVar.varType = SVT_STRING; diff --git a/engines/sludge/variable.h b/engines/sludge/variable.h index 8f0d3945144..a3ae673f66a 100644 --- a/engines/sludge/variable.h +++ b/engines/sludge/variable.h @@ -90,7 +90,6 @@ void newCostumeVariable(Variable &thisVar, struct Persona *i); void makeTextVar(Variable &thisVar, const Common::String &txt); void addVariablesInSecond(Variable &var1, Variable &var2); void compareVariablesInSecond(const Variable &var1, Variable &var2); -char *createCString(const Common::String &s); // Misc.