aboutsummaryrefslogtreecommitdiff
path: root/engines/lab/dispman.cpp
diff options
context:
space:
mode:
authorStrangerke2015-12-19 17:32:23 +0100
committerWillem Jan Palenstijn2015-12-23 21:35:30 +0100
commita2097d2a2eb9d7abfcb4f73b1c45c3778f39f3ca (patch)
treec34b77430856010ce21e97dc2b2c5a58eb516b93 /engines/lab/dispman.cpp
parentd827faf1561123a87fec12c18ac584bac5f6afa4 (diff)
downloadscummvm-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/lab/dispman.cpp')
-rw-r--r--engines/lab/dispman.cpp37
1 files changed, 19 insertions, 18 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;