From d210c6ccc30466e98240c1409df0550514668d68 Mon Sep 17 00:00:00 2001 From: Xiaofei Zhang Date: Thu, 29 Jul 2010 10:56:19 +0800 Subject: #i112600#: clean up l10ntools, rsc, sot, svl, tools and unotools --- unotools/source/i18n/textsearch.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'unotools/source/i18n/textsearch.cxx') diff --git a/unotools/source/i18n/textsearch.cxx b/unotools/source/i18n/textsearch.cxx index 3f722adb0dba..317e6f9b6e45 100644 --- a/unotools/source/i18n/textsearch.cxx +++ b/unotools/source/i18n/textsearch.cxx @@ -52,9 +52,9 @@ namespace utl SearchParam::SearchParam( const String &rText, SearchType eType, - BOOL bCaseSensitive, - BOOL bWrdOnly, - BOOL bSearchInSel ) + sal_Bool bCaseSensitive, + sal_Bool bWrdOnly, + sal_Bool bSearchInSel ) { sSrchStr = rText; eSrchType = eType; @@ -66,7 +66,7 @@ SearchParam::SearchParam( const String &rText, nTransliterationFlags = 0; // Werte fuer "Gewichtete Levenshtein-Distanz" - bLEV_Relaxed = TRUE; + bLEV_Relaxed = sal_True; nLEV_OtherX = 2; nLEV_ShorterY = 1; nLEV_LongerZ = 3; @@ -299,8 +299,8 @@ void TextSearch::ReplaceBackReferences( String& rReplaceStr, const String &rStr, { if( rReplaceStr.GetChar( nPos ) == '&') { - USHORT nStart = (USHORT)(rResult.startOffset[0]); - USHORT nLength = (USHORT)(rResult.endOffset[0] - rResult.startOffset[0]); + sal_uInt16 nStart = (sal_uInt16)(rResult.startOffset[0]); + sal_uInt16 nLength = (sal_uInt16)(rResult.endOffset[0] - rResult.startOffset[0]); rReplaceStr.Erase( nPos, 1 ); // delete ampersand // replace by found string rReplaceStr.Insert( rStr, nStart, nLength, nPos ); @@ -329,17 +329,17 @@ void TextSearch::ReplaceBackReferences( String& rReplaceStr, const String &rStr, int i = sFndChar - '0'; // index if(i < rResult.subRegExpressions) { - USHORT nSttReg = (USHORT)(rResult.startOffset[i]); - USHORT nRegLen = (USHORT)(rResult.endOffset[i]); + sal_uInt16 nSttReg = (sal_uInt16)(rResult.startOffset[i]); + sal_uInt16 nRegLen = (sal_uInt16)(rResult.endOffset[i]); if( nRegLen > nSttReg ) nRegLen = nRegLen - nSttReg; else { nRegLen = nSttReg - nRegLen; - nSttReg = (USHORT)(rResult.endOffset[i]); + nSttReg = (sal_uInt16)(rResult.endOffset[i]); } // Copy reference from found string - sTmp = rStr.Copy((USHORT)nSttReg, (USHORT)nRegLen); + sTmp = rStr.Copy((sal_uInt16)nSttReg, (sal_uInt16)nRegLen); // insert rReplaceStr.Insert( sTmp, nPos ); // and step over -- cgit From 94e7f1d15d1e9eefadbfe8e5912fee0ebccba0ca Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Sat, 15 Jan 2011 22:08:33 +0100 Subject: locales34: #i116429# ensure shutdown of the CachedTextSearch global before the things it needs in its dtor are destructed; patch from --- unotools/source/i18n/textsearch.cxx | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'unotools/source/i18n/textsearch.cxx') diff --git a/unotools/source/i18n/textsearch.cxx b/unotools/source/i18n/textsearch.cxx index 3f722adb0dba..1254ddc983d8 100644 --- a/unotools/source/i18n/textsearch.cxx +++ b/unotools/source/i18n/textsearch.cxx @@ -40,6 +40,7 @@ #include #include #include +#include using namespace ::com::sun::star::util; using namespace ::com::sun::star::uno; @@ -90,13 +91,6 @@ SearchParam::SearchParam( const SearchParam& rParam ) nTransliterationFlags = rParam.nTransliterationFlags; } -// Klasse zum Suchen eines Strings in einem Text. Es wird genau nach -// dem String gesucht. -// ( Die Unterscheidung der Gross/Klein-Schreibung kann mit einen Flag -// unterdrueckt werden ) - -TextSearch::CachedTextSearch TextSearch::maCache; - static bool lcl_Equals( const SearchOptions& rSO1, const SearchOptions& rSO2 ) { return rSO1.algorithmType == rSO2.algorithmType && @@ -112,27 +106,42 @@ static bool lcl_Equals( const SearchOptions& rSO1, const SearchOptions& rSO2 ) rSO1.transliterateFlags == rSO2.transliterateFlags; } +namespace +{ + struct CachedTextSearch + { + ::osl::Mutex mutex; + ::com::sun::star::util::SearchOptions Options; + ::com::sun::star::uno::Reference< ::com::sun::star::util::XTextSearch > xTextSearch; + }; + + struct theCachedTextSearch + : public rtl::Static< CachedTextSearch, theCachedTextSearch > {}; +} + Reference TextSearch::getXTextSearch( const SearchOptions& rPara ) { - osl::MutexGuard aGuard(maCache.mutex); + CachedTextSearch &rCache = theCachedTextSearch::get(); + + osl::MutexGuard aGuard(rCache.mutex); - if ( lcl_Equals(maCache.Options, rPara) ) - return maCache.xTextSearch; + if ( lcl_Equals(rCache.Options, rPara) ) + return rCache.xTextSearch; try { Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory(); - maCache.xTextSearch.set( xMSF->createInstance( + rCache.xTextSearch.set( xMSF->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.TextSearch" ) ) ), UNO_QUERY_THROW ); - maCache.xTextSearch->setOptions( rPara ); - maCache.Options = rPara; + rCache.xTextSearch->setOptions( rPara ); + rCache.Options = rPara; } catch ( Exception& ) { DBG_ERRORFILE( "TextSearch ctor: Exception caught!" ); } - return maCache.xTextSearch; + return rCache.xTextSearch; } TextSearch::TextSearch(const SearchParam & rParam, LanguageType eLang ) -- cgit