diff options
author | RichieSams | 2013-09-16 00:07:45 -0500 |
---|---|---|
committer | RichieSams | 2013-09-16 00:09:03 -0500 |
commit | 14cfc65c0d3f3ac678c17614140ea32902abec69 (patch) | |
tree | 5f1e7f304e9748bcd27457fd70e79c24b83b7fe1 /engines/zvision | |
parent | 4c4f08a99e0b7ff914c6f9c2cb1b38caeba9009f (diff) | |
download | scummvm-rg350-14cfc65c0d3f3ac678c17614140ea32902abec69.tar.gz scummvm-rg350-14cfc65c0d3f3ac678c17614140ea32902abec69.tar.bz2 scummvm-rg350-14cfc65c0d3f3ac678c17614140ea32902abec69.zip |
ZVISION: Use wide-to-ASCII conversion to read a line instead of stream.readLine()
SeekableReadStream::readLine() wasn't finding the CRLF's properly
Diffstat (limited to 'engines/zvision')
-rw-r--r-- | engines/zvision/string_manager.cpp | 42 | ||||
-rw-r--r-- | engines/zvision/string_manager.h | 2 |
2 files changed, 27 insertions, 17 deletions
diff --git a/engines/zvision/string_manager.cpp b/engines/zvision/string_manager.cpp index 818b60c732..127b62f34e 100644 --- a/engines/zvision/string_manager.cpp +++ b/engines/zvision/string_manager.cpp @@ -98,10 +98,10 @@ void StringManager::parseStrFile(const Common::String &fileName) { } } - // STR files add a null character after the CR/LF. We need to skip over that before we can read another line - file.readByte(); + if (textStringCursor > 0) { + _inGameText[lineNumber].fragments.back().text = Common::String(textString, textStringCursor); + } - line = file.readLine(); lineNumber++; } } @@ -199,33 +199,43 @@ void StringManager::parseTag(const Common::String &tagString, const Common::Stri fragment->text = textString; } -Common::String StringManager::wideToASCII(const char *wideStr, uint arrayLength) { - // TODO: Contemplate using a largish static buffer instead of a dynamic heap buffer - uint newSize = arrayLength / 2; - char *asciiString = new char[newSize]; +Common::String StringManager::readWideLine(Common::SeekableReadStream &stream) { + // NOTE: Hardcoded size. All strings I've checked are less than 290 chars + char asciiString[300]; // Don't spam the user with warnings about UTF-16 support. // Just do one warning per String bool charOverflowWarning = false; - // Crush each octet pair to a single octet with a simple cast - for (uint i = 0; i < newSize; i++) { - uint16 value = READ_LE_UINT16(wideStr + (i * 2)); + + uint16 value = stream.readUint16LE(); + uint i = 0; + while (!stream.eos()) { + // Check for CRLF + if (value == 0x0A0D) { + // Read in the extra NULL char + stream.readByte(); // \0 + // End of the line. Break + break; + } + + // Crush each octet pair to a single octet with a simple cast if (value > 255) { charOverflowWarning = true; value = 255; } - asciiString[i] = (char)value; + char charValue = (char)value; + + asciiString[i] = charValue; + i++; + + value = stream.readUint16LE(); } if (charOverflowWarning) { warning("UTF-16 is not supported. Characters greater than 255 are clamped to 255"); } - Common::String returnString(asciiString, newSize); - // Cleanup. Common::String constructor does a memmove() internally so we can safely delete - delete[] asciiString; - - return returnString; + return Common::String(asciiString, i); } StringManager::TextStyle StringManager::getTextStyle(uint stringNumber) { diff --git a/engines/zvision/string_manager.h b/engines/zvision/string_manager.h index a9d2dc1a1d..a214c6c625 100644 --- a/engines/zvision/string_manager.h +++ b/engines/zvision/string_manager.h @@ -76,7 +76,7 @@ private: void parseStrFile(const Common::String &fileName); void parseTag(const Common::String &tagString, const Common::String &textString, uint lineNumber); - static Common::String wideToASCII(const char *wideStr, uint arrayLength); + static Common::String readWideLine(Common::SeekableReadStream &stream); }; } // End of namespace ZVision |