summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2011-09-04 23:04:18 +0100
committerCaolán McNamara <caolanm@redhat.com>2011-09-05 10:54:21 +0100
commitb96c999d7a7cb5399fc8fbeab32a8b3b8b5c76bc (patch)
tree07581a3bba58454071d287901e36535c3ab74cc4
parent2fb353433db5b9fd1afe8c688451d04db5b62d5f (diff)
disentangle 16bit pascal-strings and zero terminated pstrings, etc.
one method to read pascal strings, zero-terminated pascal strings and non-zero terminated non-pascal strings is a disaster when length of 0 toggle into pascal-string mode, shudder!
-rw-r--r--sw/source/filter/ww8/ww8graf2.cxx2
-rw-r--r--sw/source/filter/ww8/ww8par.cxx4
-rw-r--r--sw/source/filter/ww8/ww8par3.cxx4
-rw-r--r--sw/source/filter/ww8/ww8scan.cxx51
-rw-r--r--sw/source/filter/ww8/ww8scan.hxx16
-rw-r--r--sw/source/filter/ww8/ww8toolbar.cxx5
6 files changed, 35 insertions, 47 deletions
diff --git a/sw/source/filter/ww8/ww8graf2.cxx b/sw/source/filter/ww8/ww8graf2.cxx
index cb40a02d9b94..a382f4923d2a 100644
--- a/sw/source/filter/ww8/ww8graf2.cxx
+++ b/sw/source/filter/ww8/ww8graf2.cxx
@@ -269,7 +269,7 @@ bool SwWW8ImplReader::ReadGrafFile(String& rFileName, Graphic*& rpGraphic,
case 99: // TIFF-File ( nicht embeddet )
pSt->Seek(nPosFc);
// Name als P-String einlesen
- rFileName = WW8ReadPascalString(*pSt, eStructCharSet);
+ rFileName = read_uInt8_PascalString(*pSt, eStructCharSet);
if (rFileName.Len())
rFileName = URIHelper::SmartRel2Abs(
INetURLObject(sBaseURL), rFileName,
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 703e1db3bbb9..c708a2ce50ae 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -5337,13 +5337,13 @@ const String* SwWW8ImplReader::GetAnnotationAuthor(sal_uInt16 nIdx)
{
if( bVer67 )
{
- mpAtnNames->push_back(WW8ReadPascalString(rStrm,
+ mpAtnNames->push_back(read_uInt8_PascalString(rStrm,
RTL_TEXTENCODING_MS_1252));
nRead += mpAtnNames->rbegin()->Len() + 1; // Laenge + sal_uInt8 Count
}
else
{
- mpAtnNames->push_back(WW8Read_xstz(rStrm, 0, false));
+ mpAtnNames->push_back(read_LEuInt16_PascalString(rStrm));
// UNICode: doppelte Laenge + sal_uInt16 Count
nRead += mpAtnNames->rbegin()->Len() * 2 + 2;
}
diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index 4094d00a433f..41df2b0da259 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -702,7 +702,7 @@ bool WW8ListManager::ReadLVL(SwNumFmt& rNumFmt, SfxItemSet*& rpItemSet,
//
// 4. den Nummerierungsstring einlesen: ergibt Prefix und Postfix
//
- String sNumString(WW8Read_xstz(rSt, 0, false));
+ String sNumString(read_LEuInt16_PascalString(rSt));
//
// 5. gelesene Werte in Writer Syntax umwandeln
@@ -2225,7 +2225,7 @@ void WW8FormulaControl::FormulaRead(SwWw8ControlType nWhich,
maListEntries.reserve(nNoStrings);
for (sal_uInt32 nI = 0; nI < nNoStrings; ++nI)
{
- String sEntry = WW8Read_xstz(*pDataStream, 0, false);
+ String sEntry = read_LEuInt16_PascalString(*pDataStream);
maListEntries.push_back(sEntry);
}
}
diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx
index 5f4f714ddd0e..babb3319c364 100644
--- a/sw/source/filter/ww8/ww8scan.cxx
+++ b/sw/source/filter/ww8/ww8scan.cxx
@@ -1900,35 +1900,32 @@ Err:
return false;
}
-String WW8ReadPascalString(SvStream& rStrm, rtl_TextEncoding eEnc)
+String read_uInt8_PascalString(SvStream& rStrm, rtl_TextEncoding eEnc)
{
- sal_uInt8 b(0);
- rStrm >> b;
- return rtl::OStringToOUString(read_uInt8s_AsOString(rStrm, b), eEnc);
+ sal_uInt8 nLen(0);
+ rStrm >> nLen;
+ return rtl::OStringToOUString(read_uInt8s_AsOString(rStrm, nLen), eEnc);
}
-String WW8ReadBeltAndBracesString(SvStream& rStrm, rtl_TextEncoding eEnc)
+String read_LEuInt16_PascalString(SvStream& rStrm)
{
- String aRet = WW8ReadPascalString(rStrm, eEnc);
- rStrm.SeekRel( 1 ); // skip null-byte at end
- return aRet;
+ sal_uInt16 nLen(0);
+ rStrm >> nLen;
+ return read_LEuInt16s_AsOUString(rStrm, nLen);
}
-String WW8Read_xstz(SvStream& rStrm, sal_uInt16 nChars, bool bAtEndSeekRel1)
+String read_uInt8_BeltAndBracesString(SvStream& rStrm, rtl_TextEncoding eEnc)
{
- sal_uInt16 b(0);
-
- if( nChars )
- b = nChars;
- else
- rStrm >> b;
-
- rtl::OUString sRet = read_LEuInt16s_AsOUString(rStrm, nChars);
-
- if( bAtEndSeekRel1 )
- rStrm.SeekRel( 2 ); // ueberspringe das Null-Character am Ende.
+ String aRet = read_uInt8_PascalString(rStrm, eEnc);
+ rStrm.SeekRel(sizeof(sal_uInt8)); // skip null-byte at end
+ return aRet;
+}
- return sRet;
+String read_LEuInt16_BeltAndBracesString(SvStream& rStrm)
+{
+ String aRet = read_LEuInt16_PascalString(rStrm);
+ rStrm.SeekRel(sizeof(sal_Unicode)); // skip null-byte at end
+ return aRet;
}
xub_StrLen WW8ScannerBase::WW8ReadString( SvStream& rStrm, String& rStr,
@@ -1961,7 +1958,7 @@ xub_StrLen WW8ScannerBase::WW8ReadString( SvStream& rStrm, String& rStr,
nLen = USHRT_MAX - 1;
if( bIsUnicode )
- rStr.Append(WW8Read_xstz(rStrm, (sal_uInt16)nLen, false));
+ rStr.Append(String(read_LEuInt16s_AsOUString(rStrm, nLen)));
else
{
// Alloc method automatically sets Zero at the end
@@ -3864,7 +3861,7 @@ void WW8ReadSTTBF(bool bVer8, SvStream& rStrm, sal_uInt32 nStart, sal_Int32 nLen
for (sal_uInt16 i=0; i < nStrings; ++i)
{
if (bUnicode)
- rArray.push_back(WW8Read_xstz(rStrm, 0, false));
+ rArray.push_back(read_LEuInt16_PascalString(rStrm));
else
{
sal_uInt8 nBChar(0);
@@ -3897,7 +3894,7 @@ void WW8ReadSTTBF(bool bVer8, SvStream& rStrm, sal_uInt32 nStart, sal_Int32 nLen
for (sal_uInt16 i=0; i < nStrings; ++i)
{
if( bUnicode )
- pValueArray->push_back(WW8Read_xstz(rStrm, 0, false));
+ pValueArray->push_back(read_LEuInt16_PascalString(rStrm));
else
{
sal_uInt8 nBChar(0);
@@ -6142,7 +6139,7 @@ WW8_STD* WW8Style::Read1Style( short& rSkip, String* pString, short* pcbStd )
case 6:
case 7:
// lies Pascal-String
- *pString = WW8ReadBeltAndBracesString(rSt, RTL_TEXTENCODING_MS_1252);
+ *pString = read_uInt8_BeltAndBracesString(rSt, RTL_TEXTENCODING_MS_1252);
// leading len and trailing zero --> 2
rSkip -= 2+ pString->Len();
break;
@@ -6151,7 +6148,7 @@ WW8_STD* WW8Style::Read1Style( short& rSkip, String* pString, short* pcbStd )
// trailing zero
if (ww8String::TestBeltAndBraces(rSt))
{
- *pString = WW8Read_xstz(rSt, 0, true);
+ *pString = read_LEuInt16_BeltAndBracesString(rSt);
rSkip -= (pString->Len() + 2) * 2;
}
else
@@ -6166,7 +6163,7 @@ WW8_STD* WW8Style::Read1Style( short& rSkip, String* pString, short* pcbStd )
they are not corrupt. If they are then we try them as
8bit ones
*/
- *pString = WW8ReadBeltAndBracesString(rSt,RTL_TEXTENCODING_MS_1252);
+ *pString = read_uInt8_BeltAndBracesString(rSt,RTL_TEXTENCODING_MS_1252);
// leading len and trailing zero --> 2
rSkip -= 2+ pString->Len();
}
diff --git a/sw/source/filter/ww8/ww8scan.hxx b/sw/source/filter/ww8/ww8scan.hxx
index 5118eca44a24..7d732c81b4e7 100644
--- a/sw/source/filter/ww8/ww8scan.hxx
+++ b/sw/source/filter/ww8/ww8scan.hxx
@@ -152,12 +152,14 @@ public:
//Read a Pascal-style, i.e. single byte string length followed
//by string contents
-String WW8ReadPascalString(SvStream& rStrm, rtl_TextEncoding eEnc);
+String read_uInt8_PascalString(SvStream& rStrm, rtl_TextEncoding eEnc);
+String read_LEuInt16_PascalString(SvStream& rStrm);
//Belt and Braces strings, i.e. Pascal-style strings followed by
//null termination, Spolsky calls them "fucked strings" FWIW
//http://www.joelonsoftware.com/articles/fog0000000319.html
-String WW8ReadBeltAndBracesString(SvStream& rStrm, rtl_TextEncoding eEnc);
+String read_uInt8_BeltAndBracesString(SvStream& rStrm, rtl_TextEncoding eEnc);
+String read_LEuInt16_BeltAndBracesString(SvStream& rStrm);
//--Line abovewhich the code has meaningful comments
@@ -168,16 +170,6 @@ struct WW8PLCFxDesc;
class WW8PLCFx_PCD;
/**
- Reads a UTF-16 unicode string. If nLen is set then that number of 16bit units
- (not bytes) is read, if its not set, then read a 16bit count from the
- stream and use that for the length.
-
- If bAtEndSeekRel1 is set, exactly ONE extra unit (not byte) is skipped at the
- end of the string.
-*/
-String WW8Read_xstz(SvStream& rStrm, sal_uInt16 nChars, bool bAtEndSeekRel1);
-
-/**
reads array of strings (see MS documentation: STring TaBle stored in File)
returns NOT the original pascal strings but an array of converted char*
diff --git a/sw/source/filter/ww8/ww8toolbar.cxx b/sw/source/filter/ww8/ww8toolbar.cxx
index 1147e9e6b010..3f2c333a07d7 100644
--- a/sw/source/filter/ww8/ww8toolbar.cxx
+++ b/sw/source/filter/ww8/ww8toolbar.cxx
@@ -29,6 +29,7 @@
* instead of those above.
*/
#include "ww8toolbar.hxx"
+#include "ww8scan.hxx"
#include <rtl/ustrbuf.hxx>
#include <stdarg.h>
#include <com/sun/star/ui/XUIConfigurationPersistence.hpp>
@@ -786,9 +787,7 @@ Xst::Read( SvStream& rS )
{
OSL_TRACE("Xst::Read() stream pos 0x%x", rS.Tell() );
nOffSet = rS.Tell();
- sal_Int16 nChars = 0;
- rS >> nChars;
- sString = read_LEuInt16s_AsOUString(rS, nChars);
+ sString = read_LEuInt16_PascalString(rS);
return true;
}