[Scummvm-cvs-logs] SF.net SVN: scummvm:[43975] scummvm/trunk/engines/queen/journal.cpp
tramboi at users.sourceforge.net
tramboi at users.sourceforge.net
Sun Sep 6 13:37:15 CEST 2009
Revision: 43975
http://scummvm.svn.sourceforge.net/scummvm/?rev=43975&view=rev
Author: tramboi
Date: 2009-09-06 11:37:15 +0000 (Sun, 06 Sep 2009)
Log Message:
-----------
Constness fix
Modified Paths:
--------------
scummvm/trunk/engines/queen/journal.cpp
Modified: scummvm/trunk/engines/queen/journal.cpp
===================================================================
--- scummvm/trunk/engines/queen/journal.cpp 2009-09-06 10:51:20 UTC (rev 43974)
+++ scummvm/trunk/engines/queen/journal.cpp 2009-09-06 11:37:15 UTC (rev 43975)
@@ -380,35 +380,56 @@
update();
}
+static void removeLeadingAndTrailingSpaces(char *dst, size_t dstSize, const char* src) {
+ assert(dstSize > 0);
+ size_t srcLen = strlen(src);
+ if (0 == srcLen) {
+ dst[0] = '\0';
+ return;
+ }
+
+ size_t firstNonSpaceIndex;
+ for (firstNonSpaceIndex = 0; firstNonSpaceIndex < srcLen; ++firstNonSpaceIndex) {
+ if (src[firstNonSpaceIndex] != ' ')
+ break;
+ }
+ if (firstNonSpaceIndex == srcLen) {
+ dst[0] = '\0';
+ return;
+ }
+
+ size_t lastNonSpaceIndex = srcLen - 1;
+ while (src[lastNonSpaceIndex] == ' ')
+ --lastNonSpaceIndex;
+
+ size_t newLen = lastNonSpaceIndex - firstNonSpaceIndex + 1;
+ assert(newLen < dstSize);
+ for (size_t i = 0; i < newLen; ++i) {
+ dst[i] = src[firstNonSpaceIndex + i];
+ }
+ dst[newLen] = '\0';
+}
+
void Journal::drawPanelText(int y, const char *text) {
debug(7, "Journal::drawPanelText(%d, '%s')", y, text);
+
char s[128];
- strncpy(s, text, 127);
- s[127] = 0;
- char *p;
+ removeLeadingAndTrailingSpaces(s, 128, text); // necessary for spanish version
- // remove leading and trailing spaces (necessary for spanish version)
- for (p = s + strlen(s) - 1; p >= s && *p == ' '; --p) {
- *p = 0;
- }
- text = s;
- for (p = s; *p == ' '; ++p) {
- text = p + 1;
- }
// draw the substrings
- p = (char *)strchr(text, ' ');
+ char *p = strchr(s, ' ');
if (!p) {
- int x = (128 - _vm->display()->textWidth(text)) / 2;
- _vm->display()->setText(x, y, text, false);
+ int x = (128 - _vm->display()->textWidth(s)) / 2;
+ _vm->display()->setText(x, y, s, false);
assert(_panelTextCount < MAX_PANEL_TEXTS);
_panelTextY[_panelTextCount++] = y;
} else {
*p++ = '\0';
if (_vm->resource()->getLanguage() == Common::HB_ISR) {
drawPanelText(y - 5, p);
- drawPanelText(y + 5, text);
+ drawPanelText(y + 5, s);
} else {
- drawPanelText(y - 5, text);
+ drawPanelText(y - 5, s);
drawPanelText(y + 5, p);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list