diff -ru sc/inc/document.hxx sc/inc/document.hxx --- openoffice.org.orig/sc/inc/document.hxx 2008-05-01 14:06:46.000000000 +0100 +++ openofficeorg/sc/inc/document.hxx 2008-05-01 14:07:19.000000000 +0100 @@ -559,7 +559,6 @@ void SnapVisArea( Rectangle& rRect ) const; // 1/100 mm SC_DLLPUBLIC BOOL ValidTabName( const String& rName ) const; - static SC_DLLPUBLIC void ConvertToValidTabName( String& rName, sal_Unicode cReplaceChar ); SC_DLLPUBLIC BOOL ValidNewTabName( const String& rName ) const; SC_DLLPUBLIC void CreateValidTabName(String& rName) const; BOOL InsertTab( SCTAB nPos, const String& rName, diff -ru sc/source/core/data/document.cxx sc/source/core/data/document.cxx --- openoffice.org.orig/sc/source/core/data/document.cxx 2008-05-01 14:06:24.000000000 +0100 +++ openoffice.org/sc/source/core/data/document.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -167,40 +167,7 @@ BOOL ScDocument::ValidTabName( const String& rName ) const { - // behaviour must be equal to ConvertToValidTabName(), see below - using namespace ::com::sun::star::i18n; - sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER | - KParseTokens::ASC_UNDERSCORE; - sal_Int32 nContFlags = nStartFlags; - String aContChars( RTL_CONSTASCII_USTRINGPARAM(" ") ); - ParseResult aRes = ScGlobal::pCharClass->parsePredefinedToken( - KParseType::IDENTNAME, rName, 0, nStartFlags, EMPTY_STRING, nContFlags, aContChars ); - return (aRes.TokenType & KParseType::IDENTNAME) && aRes.EndPos == rName.Len(); -} - - -void ScDocument::ConvertToValidTabName( String& rName, sal_Unicode cReplaceChar ) -{ - // behaviour must be equal to ValidTabName(), see above - using namespace ::com::sun::star::i18n; - sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER | - KParseTokens::ASC_UNDERSCORE; - sal_Int32 nContFlags = nStartFlags; - String aStartChars; - String aContChars( RTL_CONSTASCII_USTRINGPARAM(" ") ); - sal_Int32 nStartPos = 0; - while( nStartPos < rName.Len() ) - { - ParseResult aRes = ScGlobal::pCharClass->parsePredefinedToken( KParseType::IDENTNAME, - rName, nStartPos, nStartFlags, aStartChars, nContFlags, aContChars ); - if( aRes.EndPos < rName.Len() ) - { - rName.SetChar( static_cast< xub_StrLen >( aRes.EndPos ), cReplaceChar ); - nStartFlags = nContFlags; - aStartChars = aContChars; - } - nStartPos = aRes.EndPos + 1; - } + return rName.Len() > 0; } diff -ru sc/source/core/tool/address.cxx sc/source/core/tool/address.cxx --- openoffice.org.orig/sc/source/core/tool/address.cxx 2008-05-01 14:06:24.000000000 +0100 +++ openoffice.org/sc/source/core/tool/address.cxx 2008-05-01 14:07:50.000000000 +0100 @@ -651,23 +651,30 @@ BOOL bExtDoc = FALSE; BOOL bNeedExtTab = FALSE; + //Lets see if this is a reference to something in an external file + //A Documentname is always quoted and has a trailing # if ( *p == '\'' && ScGlobal::UnicodeStrChr( p, SC_COMPILER_FILE_TAB_SEP ) ) { - BOOL bQuote = TRUE; // Dokumentenname ist immer quoted + const sal_Unicode *pStart = p; + BOOL bQuote = TRUE; // A Documentname is always quoted aDocTab += *p++; while ( bQuote && *p ) { if ( *p == '\'' && *(p-1) != '\\' ) bQuote = FALSE; else if( !(*p == '\\' && *(p+1) == '\'') ) - aDocName += *p; // falls escaped Quote: nur Quote in den Namen + aDocName += *p; // An escaped Quote in the Documentname aDocTab += *p++; } aDocTab += *p; // den SC_COMPILER_FILE_TAB_SEP mitnehmen if( *p++ == SC_COMPILER_FILE_TAB_SEP ) bExtDoc = TRUE; else - return nRes; + { + //It wasn't a document after all, reset and continue as normal + p = pStart; + aDocTab = String(); + } } SCCOL nCol = 0; @@ -682,12 +689,33 @@ nRes |= SCA_TAB_ABSOLUTE; if (*p == '$') nRes |= SCA_TAB_ABSOLUTE, p++; - BOOL bQuote = FALSE; + + //Tokens that start at ' can have anything in them until a final ' + //but '' marks an escaped ' + //We've earlier guaranteed that a string containing '' will be + //surrounded by ' if( *p == '\'' ) - p++, bQuote = TRUE; - while (*p && (*p != '.')) { - if( bQuote && *p == '\'' ) + ++p; + while (*p) + { + if (*p == '\'') + { + if ( (*(p+1) != '\'') ) + break; + else + *p++; + } + aTab += *p++; + } + } + + while (*p) + { + if( *p == '.') + break; + + if( *p == '\'' ) { p++; break; } @@ -736,6 +764,7 @@ } nRes |= nBits; + q = p; if (*p) { diff -ru sc/source/core/tool/compiler.cxx sc/source/core/tool/compiler.cxx --- openoffice.org.orig/sc/source/core/tool/compiler.cxx 2008-05-01 14:06:24.000000000 +0100 +++ openoffice.org/sc/source/core/tool/compiler.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -993,6 +993,30 @@ xub_StrLen nSrcPos, const CharClass* pCharClass) const { + //Tokens that start at ' can have anything in them until a final ' + //but '' marks an escaped ' + //We've earlier guaranteed that a string containing '' will be + //surrounded by ' + if (rFormula.GetChar(nSrcPos) == '\'') + { + xub_StrLen nPos = nSrcPos+1; + while (nPos < rFormula.Len()) + { + if (rFormula.GetChar(nPos) == '\'') + { + if ( (nPos+1 == rFormula.Len()) || (rFormula.GetChar(nPos+1) != '\'') ) + { + ParseResult aRet; + aRet.TokenType = KParseType::SINGLE_QUOTE_NAME; + aRet.EndPos = nPos+1; + return aRet; + } + ++nPos; + } + ++nPos; + } + } + static const sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER | KParseTokens::ASC_UNDERSCORE | KParseTokens::ASC_DOLLAR; static const sal_Int32 nContFlags = nStartFlags | KParseTokens::ASC_DOT; @@ -1524,29 +1538,18 @@ void ScCompiler::CheckTabQuotes( String& rString, const ScAddress::Convention eConv ) { - register const xub_StrLen nLen = rString.Len(); - register xub_StrLen i; - - bool bNeedsQuote = false; - - for ( i = 0 ; i < nLen ; i++ ) - { - if( !IsWordChar( rString, i ) ) - { - bNeedsQuote = true; - break; - } - } - if ( !bNeedsQuote && CharClass::isAsciiNumeric( rString ) ) - { - bNeedsQuote = true; - } + using namespace ::com::sun::star::i18n; + sal_Int32 nStartFlags = KParseTokens::ANY_LETTER_OR_NUMBER | KParseTokens::ASC_UNDERSCORE; + sal_Int32 nContFlags = nStartFlags; + ParseResult aRes = ScGlobal::pCharClass->parsePredefinedToken( + KParseType::IDENTNAME, rString, 0, nStartFlags, EMPTY_STRING, nContFlags, EMPTY_STRING); + bool bNeedsQuote = !((aRes.TokenType & KParseType::IDENTNAME) && aRes.EndPos == rString.Len()); switch ( eConv ) { default : case ScAddress::CONV_UNSPECIFIED : - case ScAddress::CONV_OOO : break; + case ScAddress::CONV_OOO : case ScAddress::CONV_XL_A1 : case ScAddress::CONV_XL_R1C1 : if( bNeedsQuote ) diff -ru sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx --- openoffice.org.orig/sc/source/filter/excel/excimp8.cxx 2008-05-01 14:06:26.000000000 +0100 +++ openoffice.org/sc/source/filter/excel/excimp8.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -186,7 +186,6 @@ String aName( aIn.ReadUniString( nLen ) ); GetTabInfo().AppendXclTabName( aName, nBdshtTab ); - ScfTools::ConvertToScSheetName( aName ); *pExcRoot->pTabNameBuff << aName; SCTAB nScTab = static_cast< SCTAB >( nBdshtTab ); diff -ru sc/source/filter/excel/exctools.cxx sc/source/filter/excel/exctools.cxx --- openoffice.org.orig/sc/source/filter/excel/exctools.cxx 2008-05-01 14:06:26.000000000 +0100 +++ openoffice.org/sc/source/filter/excel/exctools.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -391,7 +391,6 @@ ScDocument& r = rRoot.GetDoc(); ExcScenarioCell* p = EXCSCFIRST(); String aSzenName( *pName ); - ScfTools::ConvertToScSheetName( aSzenName ); UINT16 nNewTab = nTab + 1; if( !r.InsertTab( nNewTab, aSzenName ) ) diff -ru sc/source/filter/excel/impop.cxx sc/source/filter/excel/impop.cxx --- openoffice.org.orig/sc/source/filter/excel/impop.cxx 2008-05-01 14:06:26.000000000 +0100 +++ openoffice.org/sc/source/filter/excel/impop.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -435,7 +435,6 @@ bool bSameWorkBook; String aEncodedUrl( aIn.ReadByteString( false ) ); XclImpUrlHelper::DecodeUrl( aUrl, aTabName, bSameWorkBook, *pExcRoot->pIR, aEncodedUrl ); - ScfTools::ConvertToScSheetName( aTabName ); pExcRoot->pExtSheetBuff->Add( aUrl, aTabName, bSameWorkBook ); } @@ -686,7 +685,6 @@ } String aName( aIn.ReadByteString( FALSE ) ); - ScfTools::ConvertToScSheetName( aName ); *pExcRoot->pTabNameBuff << aName; diff -ru sc/source/filter/excel/xicontent.cxx sc/source/filter/excel/xicontent.cxx --- openoffice.org.orig/sc/source/filter/excel/xicontent.cxx 2008-05-01 14:06:26.000000000 +0100 +++ openoffice.org/sc/source/filter/excel/xicontent.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -354,12 +354,7 @@ { bInQuote = !bInQuote; if (!bInQuote && aTabName.Len() > 0) - { - // Sheet name exists. Convert it to valid name the same way the - // sheet names are converted. - ScDocument::ConvertToValidTabName(aTabName, sal_Unicode('_')); aNewUrl.Append(aTabName); - } } else if (bInQuote) aTabName.Append(c); diff -ru sc/source/filter/excel/xilink.cxx sc/source/filter/excel/xilink.cxx --- openoffice.org.orig/sc/source/filter/excel/xilink.cxx 2008-05-01 14:06:26.000000000 +0100 +++ openoffice.org/sc/source/filter/excel/xilink.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -422,7 +422,6 @@ for( sal_uInt16 nSBTab = 0; nSBTab < nSBTabCnt; ++nSBTab ) { String aTabName( rStrm.ReadUniString() ); - ScfTools::ConvertToScSheetName( aTabName ); maSupbTabList.Append( new XclImpSupbookTab( aTabName ) ); } } diff -ru sc/source/filter/excel/xipivot.cxx sc/source/filter/excel/xipivot.cxx --- openoffice.org.orig/sc/source/filter/excel/xipivot.cxx 2008-05-01 14:06:26.000000000 +0100 +++ openoffice.org/sc/source/filter/excel/xipivot.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -695,7 +695,6 @@ String aDummyName = CREATE_STRING( "DPCache" ); if( maTabName.Len() > 0 ) aDummyName.Append( '_' ).Append( maTabName ); - ScfTools::ConvertToScSheetName( aDummyName ); rDoc.CreateValidTabName( aDummyName ); rDoc.RenameTab( nScTab, aDummyName ); // set sheet index to source range diff -ru sc/source/filter/ftools/ftools.cxx sc/source/filter/ftools/ftools.cxx --- openoffice.org.orig/sc/source/filter/ftools/ftools.cxx 2008-05-01 14:06:25.000000000 +0100 +++ openoffice.org/sc/source/filter/ftools/ftools.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -158,11 +158,6 @@ // *** conversion of names *** ------------------------------------------------ -void ScfTools::ConvertToScSheetName( String& rName ) -{ - ScDocument::ConvertToValidTabName( rName, '_' ); -} - void ScfTools::ConvertToScDefinedName( String& rName ) { xub_StrLen nLen = rName.Len(); diff -ru sc/source/filter/inc/ftools.hxx sc/source/filter/inc/ftools.hxx --- openoffice.org.orig/sc/source/filter/inc/ftools.hxx 2008-05-01 14:06:25.000000000 +0100 +++ openoffice.org/sc/source/filter/inc/ftools.hxx 2008-05-01 14:07:19.000000000 +0100 @@ -292,10 +292,6 @@ // *** conversion of names *** ------------------------------------------------ - /** Converts a string to a valid Calc sheet name. - @descr Sheet names in Calc may contain letters, digits, underscores, and spaces - (space characters are not allowed at first position). */ - static void ConvertToScSheetName( String& rName ); /** Converts a string to a valid Calc defined name or database range name. @descr Defined names in Calc may contain letters, digits (*), underscores, periods (*), colons (*), question marks, and dollar signs. diff -ru sc/source/filter/xcl97/XclImpChangeTrack.cxx sc/source/filter/xcl97/XclImpChangeTrack.cxx --- openoffice.org.orig/sc/source/filter/xcl97/XclImpChangeTrack.cxx 2008-05-01 14:06:25.000000000 +0100 +++ openoffice.org/sc/source/filter/xcl97/XclImpChangeTrack.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -179,7 +179,6 @@ pStrm->Ignore( 1 ); // - sheet name, always separated from URL String aTabName( pStrm->ReadUniString() ); - ScfTools::ConvertToScSheetName( aTabName ); pStrm->Ignore( 1 ); rFirstTab = rLastTab = static_cast(GetLinkManager().GetScTab( aUrl, aTabName )); } diff -ru sc/source/ui/vba/vbaworksheets.cxx sc/source/ui/vba/vbaworksheets.cxx --- openoffice.org.orig/sc/source/ui/vba/vbaworksheets.cxx 2008-05-01 14:06:23.000000000 +0100 +++ openoffice.org/sc/source/ui/vba/vbaworksheets.cxx 2008-05-01 14:07:19.000000000 +0100 @@ -402,9 +402,7 @@ uno::Any ScVbaWorksheets::getItemByStringIndex( const rtl::OUString& sIndex ) throw (uno::RuntimeException) { - String sScIndex = sIndex; - ScDocument::ConvertToValidTabName( sScIndex, '_' ); - return ScVbaWorksheets_BASE::getItemByStringIndex( sScIndex ); + return ScVbaWorksheets_BASE::getItemByStringIndex( sIndex ); } rtl::OUString&