diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2013-12-03 00:11:26 +0100 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2013-12-04 00:15:39 +0100 |
commit | 8deb1305726966b3b583865dec1ba7ba1327d8cb (patch) | |
tree | 291627fbe0123dc35c015b1f398585f204afe8ea /src/common/restext.cpp | |
parent | dae8d8738908a65a4ee4ef14d88681e196825126 (diff) | |
download | colobot-8deb1305726966b3b583865dec1ba7ba1327d8cb.tar.gz colobot-8deb1305726966b3b583865dec1ba7ba1327d8cb.tar.bz2 colobot-8deb1305726966b3b583865dec1ba7ba1327d8cb.zip |
Changed char[] to std::string in restext
Experimental changes
Diffstat (limited to 'src/common/restext.cpp')
-rw-r--r-- | src/common/restext.cpp | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/src/common/restext.cpp b/src/common/restext.cpp index d61fa63..c5d0ceb 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -776,9 +776,7 @@ static KeyDesc keyTable[22] = bool SearchKey(const char *cmd, InputSlot &key) { - int i; - - for ( i=0 ; i<22 ; i++ ) + for (int i = 0; i < 22 ;i++) { if ( strstr(cmd, keyTable[i].name) == cmd ) { @@ -791,14 +789,11 @@ bool SearchKey(const char *cmd, InputSlot &key) // Replaces the commands "\key name;" in a text. -static void PutKeyName(char* dst, const char* src) +static void PutKeyName(std::string& dst, const char* src) { - InputSlot key; - char name[50]; - int s, d, n; - unsigned int res; + dst.clear(); - s = d = 0; + int s = 0; while ( src[s] != 0 ) { if ( src[s+0] == '\\' && @@ -807,18 +802,16 @@ static void PutKeyName(char* dst, const char* src) src[s+3] == 'y' && src[s+4] == ' ' ) { + InputSlot key; if ( SearchKey(src+s+5, key) ) { - res = CRobotMain::GetInstancePointer()->GetInputBinding(key).primary; + unsigned int res = CRobotMain::GetInstancePointer()->GetInputBinding(key).primary; if (res != KEY_INVALID) { - if ( GetResource(RES_KEY, res, name) ) + std::string keyName; + if ( GetResource(RES_KEY, res, keyName) ) { - n = 0; - while ( name[n] != 0 ) - { - dst[d++] = name[n++]; - } + dst.append(keyName); while ( src[s++] != ';' ); continue; } @@ -826,9 +819,8 @@ static void PutKeyName(char* dst, const char* src) } } - dst[d++] = src[s++]; + dst.append(1, src[s++]); } - dst[d++] = 0; } // Returns the translated text of a resource that needs key substitution @@ -905,13 +897,13 @@ static const char* GetResourceBase(ResType type, int num) // Returns the text of a resource. -bool GetResource(ResType type, int num, char* text) +bool GetResource(ResType type, int num, std::string& text) { const char *tmpl = GetResourceBase(type, num); if (!tmpl) { - text[0] = 0; + text.clear(); return false; } |