Kaydet (Commit) 802f2a42 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Don't allow O[U]StringBuffer in string concatenation

...as

  OStringBuffer b("foo"); b = "bar" + b;

doesn't work as one might expect (see the mail thread starting at
<https://lists.freedesktop.org/archives/libreoffice/2016-October/075464.html>
"concat of OUStringBuffer".  That feature was LIBO_INTERNAL_ONLY, anyway.  And
of the affected places, MethodDescriptor::getSignature
(codemaker/source/javamaker/javatype.cxx) was the only one that would actually
have benefitted.

Change-Id: Ib84266f43e40c42c2e428f0c0616db8cfa90adff
üst e510e989
...@@ -205,7 +205,7 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation( ...@@ -205,7 +205,7 @@ OUString ExponentialRegressionCurveCalculator::ImplGetRepresentation(
OUString aValueString = getFormattedString( xNumFormatter, nNumberFormatKey, m_fLogIntercept, pValueLength ); OUString aValueString = getFormattedString( xNumFormatter, nNumberFormatKey, m_fLogIntercept, pValueLength );
if ( aValueString != "0" ) // aValueString may be rounded to 0 if nValueLength is small if ( aValueString != "0" ) // aValueString may be rounded to 0 if nValueLength is small
{ {
aTmpBuf.append( aValueString + ( (m_fLogSlope < 0.0) ? OUStringBuffer(" ") : OUStringBuffer(" + ") ) ); aTmpBuf.append( aValueString + ( (m_fLogSlope < 0.0) ? OUStringLiteral(" ") : OUStringLiteral(" + ") ) );
} }
} }
} }
......
...@@ -329,7 +329,7 @@ public: ...@@ -329,7 +329,7 @@ public:
OString getDescriptor() const; OString getDescriptor() const;
OString getSignature() const { return m_needsSignature ? m_signatureStart + m_signatureEnd : OString();} OString getSignature() const { return m_needsSignature ? m_signatureStart.toString() + m_signatureEnd : OString();}
private: private:
rtl::Reference< TypeManager > m_manager; rtl::Reference< TypeManager > m_manager;
......
...@@ -293,7 +293,7 @@ OUString Model::getNodeDisplayName( const XNode_t& xNode, ...@@ -293,7 +293,7 @@ OUString Model::getNodeDisplayName( const XNode_t& xNode,
OUString sContent = xNode->getNodeValue(); OUString sContent = xNode->getNodeValue();
if( bDetail || ! lcl_isWhitespace( sContent ) ) if( bDetail || ! lcl_isWhitespace( sContent ) )
{ {
aBuffer = aBuffer + "\"" + Convert::collapseWhitespace( sContent ) + "\""; aBuffer.append("\"" + Convert::collapseWhitespace( sContent ) + "\"");
} }
} }
break; break;
...@@ -866,7 +866,7 @@ static OUString lcl_serializeForDisplay( const Reference<XXPathObject>& xResult ...@@ -866,7 +866,7 @@ static OUString lcl_serializeForDisplay( const Reference<XXPathObject>& xResult
break; break;
case XPathObjectType_XPATH_STRING: case XPathObjectType_XPATH_STRING:
aBuffer = aBuffer + "\"" + xResult->getString() + "\""; aBuffer.append("\"" + xResult->getString() + "\"");
break; break;
case XPathObjectType_XPATH_NODESET: case XPathObjectType_XPATH_NODESET:
......
...@@ -220,16 +220,16 @@ bool SvIdlDataBase::ReadIdFile( const OString& rOFileName ) ...@@ -220,16 +220,16 @@ bool SvIdlDataBase::ReadIdFile( const OString& rOFileName )
else if( rTok.Is( SvHash_include() ) ) else if( rTok.Is( SvHash_include() ) )
{ {
rTok = aTokStm.GetToken_Next(); rTok = aTokStm.GetToken_Next();
OStringBuffer aName; OStringBuffer aNameBuf;
if( rTok.IsString() ) if( rTok.IsString() )
aName.append(rTok.GetString()); aNameBuf.append(rTok.GetString());
else if( rTok.IsChar() && rTok.GetChar() == '<' ) else if( rTok.IsChar() && rTok.GetChar() == '<' )
{ {
rTok = aTokStm.GetToken_Next(); rTok = aTokStm.GetToken_Next();
while( !rTok.IsEof() while( !rTok.IsEof()
&& !(rTok.IsChar() && rTok.GetChar() == '>') ) && !(rTok.IsChar() && rTok.GetChar() == '>') )
{ {
aName.append(rTok.GetTokenAsString()); aNameBuf.append(rTok.GetTokenAsString());
rTok = aTokStm.GetToken_Next(); rTok = aTokStm.GetToken_Next();
} }
if( rTok.IsEof() ) if( rTok.IsEof() )
...@@ -237,7 +237,8 @@ bool SvIdlDataBase::ReadIdFile( const OString& rOFileName ) ...@@ -237,7 +237,8 @@ bool SvIdlDataBase::ReadIdFile( const OString& rOFileName )
throw SvParseException("unexpected eof in #include", rTok); throw SvParseException("unexpected eof in #include", rTok);
} }
} }
if (!ReadIdFile(aName.toString())) OString aName(aNameBuf.makeStringAndClear());
if (!ReadIdFile(aName))
{ {
throw SvParseException("cannot read file: " + aName, rTok); throw SvParseException("cannot read file: " + aName, rTok);
} }
......
...@@ -995,21 +995,6 @@ private: ...@@ -995,21 +995,6 @@ private:
sal_Int32 nCapacity; sal_Int32 nCapacity;
}; };
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
/**
@internal
*/
template<>
struct ToStringHelper< OStringBuffer >
{
static int length( const OStringBuffer& s ) { return s.getLength(); }
static char* addData( char* buffer, const OStringBuffer& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
static const bool allowOStringConcat = true;
static const bool allowOUStringConcat = false;
};
#endif
} }
#ifdef RTL_STRING_UNITTEST #ifdef RTL_STRING_UNITTEST
......
...@@ -1561,20 +1561,6 @@ private: ...@@ -1561,20 +1561,6 @@ private:
sal_Int32 nCapacity; sal_Int32 nCapacity;
}; };
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
/**
@internal
*/
template<>
struct ToStringHelper< OUStringBuffer >
{
static int length( const OUStringBuffer& s ) { return s.getLength(); }
static sal_Unicode* addData( sal_Unicode* buffer, const OUStringBuffer& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
static const bool allowOStringConcat = false;
static const bool allowOUStringConcat = true;
};
#endif
} }
#ifdef RTL_STRING_UNITTEST #ifdef RTL_STRING_UNITTEST
......
...@@ -78,10 +78,6 @@ void test::ostring::StringConcat::checkConcat() ...@@ -78,10 +78,6 @@ void test::ostring::StringConcat::checkConcat()
CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, const char* > )), typeid( OString( "foo" ) + d3 )); CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, const char* > )), typeid( OString( "foo" ) + d3 ));
CPPUNIT_ASSERT_EQUAL( OString( "fooabc" ), OString( OString( "foo" ) + d4 )); CPPUNIT_ASSERT_EQUAL( OString( "fooabc" ), OString( OString( "foo" ) + d4 ));
CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, char* > )), typeid( OString( "foo" ) + d4 )); CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OString, char* > )), typeid( OString( "foo" ) + d4 ));
#ifdef __GNUC__
CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OStringBuffer( "foo" ) + OString( "bar" )));
CPPUNIT_ASSERT_EQUAL(( typeid( OStringConcat< OStringBuffer, OString > )), typeid( OStringBuffer( "foo" ) + OString( "bar" )));
#endif
} }
void test::ostring::StringConcat::checkEnsureCapacity() void test::ostring::StringConcat::checkEnsureCapacity()
...@@ -141,6 +137,7 @@ void test::ostring::StringConcat::checkAppend() ...@@ -141,6 +137,7 @@ void test::ostring::StringConcat::checkAppend()
void test::ostring::StringConcat::checkInvalid() void test::ostring::StringConcat::checkInvalid()
{ {
CPPUNIT_ASSERT( !INVALID_CONCAT( OString() + OString())); CPPUNIT_ASSERT( !INVALID_CONCAT( OString() + OString()));
CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OStringBuffer( "b" )));
CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUString( "b" ))); CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUString( "b" )));
CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUStringBuffer( "b" ))); CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUStringBuffer( "b" )));
CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUStringLiteral( "b" ))); CPPUNIT_ASSERT( INVALID_CONCAT( OString( "a" ) + OUStringLiteral( "b" )));
......
...@@ -69,8 +69,6 @@ void test::oustring::StringConcat::checkConcat() ...@@ -69,8 +69,6 @@ void test::oustring::StringConcat::checkConcat()
const char d1[] = "xyz"; const char d1[] = "xyz";
CPPUNIT_ASSERT_EQUAL( OUString( "fooxyz" ), OUString( OUString( "foo" ) + d1 )); CPPUNIT_ASSERT_EQUAL( OUString( "fooxyz" ), OUString( OUString( "foo" ) + d1 ));
CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const char[ 4 ] > )), typeid( OUString( "foo" ) + d1 )); CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, const char[ 4 ] > )), typeid( OUString( "foo" ) + d1 ));
CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUStringBuffer( "foo" ) + OUString( "bar" )));
CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUStringBuffer, OUString > )), typeid( OUStringBuffer( "foo" ) + OUString( "bar" )));
} }
void test::oustring::StringConcat::checkConcatAsciiL() void test::oustring::StringConcat::checkConcatAsciiL()
...@@ -146,6 +144,7 @@ void test::oustring::StringConcat::checkAppend() ...@@ -146,6 +144,7 @@ void test::oustring::StringConcat::checkAppend()
void test::oustring::StringConcat::checkInvalid() void test::oustring::StringConcat::checkInvalid()
{ {
CPPUNIT_ASSERT( !INVALID_CONCAT( OUString() + OUString())); CPPUNIT_ASSERT( !INVALID_CONCAT( OUString() + OUString()));
CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OUStringBuffer( "b" )));
CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OString( "b" ))); CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OString( "b" )));
CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OStringBuffer( "b" ))); CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + OStringBuffer( "b" )));
CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + static_cast<const char*>("b") )); CPPUNIT_ASSERT( INVALID_CONCAT( OUString( "a" ) + static_cast<const char*>("b") ));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment