diff options
author | Strangerke | 2015-12-19 17:32:23 +0100 |
---|---|---|
committer | Willem Jan Palenstijn | 2015-12-23 21:35:30 +0100 |
commit | a2097d2a2eb9d7abfcb4f73b1c45c3778f39f3ca (patch) | |
tree | c34b77430856010ce21e97dc2b2c5a58eb516b93 /engines | |
parent | d827faf1561123a87fec12c18ac584bac5f6afa4 (diff) | |
download | scummvm-rg350-a2097d2a2eb9d7abfcb4f73b1c45c3778f39f3ca.tar.gz scummvm-rg350-a2097d2a2eb9d7abfcb4f73b1c45c3778f39f3ca.tar.bz2 scummvm-rg350-a2097d2a2eb9d7abfcb4f73b1c45c3778f39f3ca.zip |
LAB: Get rid of strcat by using Common::String
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lab/dispman.cpp | 37 | ||||
-rw-r--r-- | engines/lab/dispman.h | 4 | ||||
-rw-r--r-- | engines/lab/intro.cpp | 5 |
3 files changed, 23 insertions, 23 deletions
diff --git a/engines/lab/dispman.cpp b/engines/lab/dispman.cpp index 0e7074d89c..49ea40a4e9 100644 --- a/engines/lab/dispman.cpp +++ b/engines/lab/dispman.cpp @@ -122,38 +122,37 @@ void DisplayMan::freePict() { /** * Extracts the first word from a string. */ -void DisplayMan::getWord(char *wordBuffer, const char *mainBuffer, uint16 *wordWidth) { +Common::String DisplayMan::getWord(const char *mainBuffer, uint16 *wordWidth) { uint16 width = 0; + Common::String result; while ((mainBuffer[width] != ' ') && mainBuffer[width] && (mainBuffer[width] != '\n')) { - wordBuffer[width] = mainBuffer[width]; + result += mainBuffer[width]; width++; } - wordBuffer[width] = 0; - *wordWidth = width; + return result; } /** * Gets a line of text for flowText; makes sure that its length is less than * or equal to the maximum width. */ -void DisplayMan::getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer, uint16 lineWidth) { +Common::String DisplayMan::getLine(TextFont *tf, const char **mainBuffer, uint16 lineWidth) { uint16 curWidth = 0, wordWidth; char wordBuffer[100]; + Common::String result; bool doit = true; lineWidth += textLength(tf, " ", 1); - lineBuffer[0] = 0; - while ((*mainBuffer)[0] && doit) { - getWord(wordBuffer, *mainBuffer, &wordWidth); - strcat(wordBuffer, " "); + Common::String wordBuffer = getWord(*mainBuffer, &wordWidth); + wordBuffer += " "; - if ((curWidth + textLength(tf, wordBuffer, wordWidth + 1)) <= lineWidth) { - strcat(lineBuffer, wordBuffer); + if ((curWidth + textLength(tf, wordBuffer.c_str(), wordWidth + 1)) <= lineWidth) { + result += wordBuffer; (*mainBuffer) += wordWidth; if ((*mainBuffer)[0] == '\n') @@ -162,10 +161,12 @@ void DisplayMan::getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer if ((*mainBuffer)[0]) (*mainBuffer)++; - curWidth = textLength(tf, lineBuffer, strlen(lineBuffer)); + curWidth = textLength(tf, result.c_str(), result.size()); } else doit = false; } + + return result; } /** @@ -201,14 +202,14 @@ int DisplayMan::flowText( uint16 numLines = (textRect.height() + 1) / fontHeight; uint16 width = textRect.width() + 1; uint16 y = textRect.top; - char lineBuffer[256]; + Common::String lineBuffer; if (centerv && output) { const char *temp = str; uint16 actlines = 0; while (temp[0]) { - getLine(msgFont, lineBuffer, &temp, width); + lineBuffer = getLine(msgFont, &temp, width); actlines++; } @@ -218,16 +219,16 @@ int DisplayMan::flowText( int len = 0; while (numLines && str[0]) { - getLine(msgFont, lineBuffer, &str, width); + lineBuffer = getLine(msgFont, &str, width); uint16 x = textRect.left; - len += strlen(lineBuffer); + len += lineBuffer.size(); if (centerh) - x += (width - textLength(msgFont, lineBuffer, strlen(lineBuffer))) / 2; + x += (width - textLength(msgFont, lineBuffer.c_str(), lineBuffer.size())) / 2; if (output) - drawText(msgFont, x, y, penColor, lineBuffer, strlen(lineBuffer)); + drawText(msgFont, x, y, penColor, lineBuffer.c_str(), lineBuffer.size()); numLines--; y += fontHeight; diff --git a/engines/lab/dispman.h b/engines/lab/dispman.h index e89bcabd41..518a4f745b 100644 --- a/engines/lab/dispman.h +++ b/engines/lab/dispman.h @@ -62,7 +62,7 @@ private: uint16 fadeNumIn(uint16 num, uint16 res, uint16 counter); uint16 fadeNumOut(uint16 num, uint16 res, uint16 counter); - void getWord(char *wordBuffer, const char *mainBuffer, uint16 *wordWidth); + Common::String getWord(const char *mainBuffer, uint16 *wordWidth); byte _curPen; Common::File *_curBitmap; @@ -134,7 +134,7 @@ public: uint16 textLength(TextFont *font, const char *text, uint16 numChars); uint16 textHeight(TextFont *tf); void drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, const char *text, uint16 numChars); - void getLine(TextFont *tf, char *lineBuffer, const char **mainBuffer, uint16 lineWidth); + Common::String getLine(TextFont *tf, const char **mainBuffer, uint16 lineWidth); bool _longWinInFront; bool _lastMessageLong; diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp index 2d2c55d09d..be52e2979d 100644 --- a/engines/lab/intro.cpp +++ b/engines/lab/intro.cpp @@ -71,8 +71,7 @@ void Intro::introEatMessages() { * Reads in a picture. */ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) { - char path[50] = "Lab:rooms/Intro/"; - strcat(path, filename); + Common::String path = Common::String("Lab:rooms/Intro/") + filename; uint timeDelay = (isScreen) ? 35 : 7; _vm->_music->updateMusic(); @@ -85,7 +84,7 @@ void Intro::doPictText(const char *filename, TextFont *msgFont, bool isScreen) { bool doneFl = false; bool begin = true; - Common::File *textFile = _vm->_resource->openDataFile(path); + Common::File *textFile = _vm->_resource->openDataFile(path.c_str()); byte *textBuffer = new byte[textFile->size()]; textFile->read(textBuffer, textFile->size()); delete textFile; |