summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-08-12 13:01:24 +0200
committerLuboš Luňák <l.lunak@collabora.com>2022-08-12 15:34:39 +0200
commitc62a987ebce52f7e30afb1f6bce4c7bd3ac45644 (patch)
treec74175e327980bd35ba63d431690adc85085bab3
parent3d7048552abcbcfaedffad0ba348d6939b6591d7 (diff)
revert direct append to aToken in SvRTFParser::ScanText() (tdf#150151)
This reverts most of commit 09558e2f45e27d572fd261562c884c2d2cc896a7, the problem is that GetNextToken_() resets aToken, overwriting the value created by this function. Change-Id: I1daca07a6e01cfecfeff9fbf7c311b0d392d84d4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138190 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r--svtools/source/svrtf/parrtf.cxx35
1 files changed, 21 insertions, 14 deletions
diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx
index 8f55ae448d44..42fcc211b264 100644
--- a/svtools/source/svrtf/parrtf.cxx
+++ b/svtools/source/svrtf/parrtf.cxx
@@ -302,9 +302,9 @@ sal_Unicode SvRTFParser::GetHexValue()
void SvRTFParser::ScanText()
{
const sal_Unicode cBreak = 0;
- const sal_uInt32 nStartLength = aToken.getLength();
+ OUStringBuffer aStrBuffer;
bool bContinue = true;
- while( bContinue && IsParserWorking() && aToken.getLength() - nStartLength < MAX_STRING_LEN)
+ while( bContinue && IsParserWorking() && aStrBuffer.getLength() < MAX_STRING_LEN)
{
bool bNextCh = true;
switch( nNextCh )
@@ -343,10 +343,10 @@ void SvRTFParser::ScanText()
{
if (!aByteString.isEmpty())
{
- aToken.append( OStringToOUString(aByteString, GetSrcEncoding()) );
+ aStrBuffer.append( OStringToOUString(aByteString, GetSrcEncoding()) );
aByteString.setLength(0);
}
- aToken.append(static_cast<sal_Unicode>(next));
+ aStrBuffer.append(static_cast<sal_Unicode>(next));
continue;
}
@@ -387,7 +387,7 @@ void SvRTFParser::ScanText()
if (!aByteString.isEmpty())
{
- aToken.append( OStringToOUString(aByteString, GetSrcEncoding()) );
+ aStrBuffer.append( OStringToOUString(aByteString, GetSrcEncoding()) );
aByteString.setLength(0);
}
}
@@ -396,16 +396,16 @@ void SvRTFParser::ScanText()
case '}':
case '{':
case '+': // I found in a RTF file
- aToken.append(sal_Unicode(nNextCh));
+ aStrBuffer.append(sal_Unicode(nNextCh));
break;
case '~': // nonbreaking space
- aToken.append(u'\x00A0');
+ aStrBuffer.append(u'\x00A0');
break;
case '-': // optional hyphen
- aToken.append(u'\x00AD');
+ aStrBuffer.append(u'\x00AD');
break;
case '_': // nonbreaking hyphen
- aToken.append(u'\x2011');
+ aStrBuffer.append(u'\x2011');
break;
case 'u':
@@ -418,12 +418,12 @@ void SvRTFParser::ScanText()
{
bRTF_InTextRead = true;
- OUString sSave( aToken );
+ OUString sSave( aToken ); // GetNextToken_() overwrites this
nNextCh = '\\';
int nToken = GetNextToken_();
DBG_ASSERT( RTF_U == nToken, "still not a UNI-Code character" );
// don't convert symbol chars
- aToken.append(static_cast< sal_Unicode >(nTokenValue));
+ aStrBuffer.append(static_cast< sal_Unicode >(nTokenValue));
// overread the next n "RTF" characters. This
// can be also \{, \}, \'88
@@ -494,20 +494,24 @@ void SvRTFParser::ScanText()
break;
default:
- if( nNextCh == cBreak || aToken.getLength() - nStartLength >= MAX_STRING_LEN)
+ if( nNextCh == cBreak || aStrBuffer.getLength() >= MAX_STRING_LEN)
bContinue = false;
else
{
do {
// all other characters end up in the text
- aToken.appendUtf32(nNextCh);
+ aStrBuffer.appendUtf32(nNextCh);
if (sal_Unicode(EOF) == (nNextCh = GetNextChar()))
+ {
+ if (!aStrBuffer.isEmpty())
+ aToken.append( aStrBuffer );
return;
+ }
} while
(
(RTF_ISALPHA(nNextCh) || RTF_ISDIGIT(nNextCh)) &&
- (aToken.getLength() - nStartLength < MAX_STRING_LEN)
+ (aStrBuffer.getLength() < MAX_STRING_LEN)
);
bNextCh = false;
}
@@ -516,6 +520,9 @@ void SvRTFParser::ScanText()
if( bContinue && bNextCh )
nNextCh = GetNextChar();
}
+
+ if (!aStrBuffer.isEmpty())
+ aToken.append( aStrBuffer );
}