From ce287a872ef435a207d4c22ddcccc60963165376 Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Wed, 22 Apr 2015 23:16:04 +0200 Subject: TableRef: proper unescapeTableRefColumnSpecifier() Change-Id: Id3b0a776f85b36c399a818ec1575a63ba250e318 --- sc/source/core/tool/compiler.cxx | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'sc') diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 19a073983825..bec4b2ec1318 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -3363,6 +3363,36 @@ bool ScCompiler::IsTableRefItem( const OUString& rName ) const return bItem; } +namespace { +OUString unescapeTableRefColumnSpecifier( const OUString& rStr ) +{ + // '#', '[', ']' and '\'' are escaped with '\'' + + if (rStr.indexOf( '\'' ) < 0) + return rStr; + + const sal_Int32 n = rStr.getLength(); + OUStringBuffer aBuf( n ); + const sal_Unicode* p = rStr.getStr(); + const sal_Unicode* const pStop = p + n; + bool bEscaped = false; + for ( ; p < pStop; ++p) + { + const sal_Unicode c = *p; + if (bEscaped) + { + aBuf.append( c ); + bEscaped = false; + } + else if (c == '\'') + bEscaped = true; // unescaped escaping '\'' + else + aBuf.append( c ); + } + return aBuf.makeStringAndClear(); +} +} + bool ScCompiler::IsTableRefColumn( const OUString& rName ) const { // Only called when there actually is a current TableRef, hence @@ -3374,8 +3404,7 @@ bool ScCompiler::IsTableRefColumn( const OUString& rName ) const if (!pDBData) return false; - // '#', '[', ']' and '\'' are escaped with '\'' - OUString aName( rName.replaceAll( OUString("'"), OUString())); + OUString aName( unescapeTableRefColumnSpecifier( rName)); ScRange aRange; pDBData->GetArea( aRange); -- cgit