[Libreoffice-commits] core.git: i18npool/source

Eike Rathke erack at redhat.com
Mon Nov 25 16:09:21 PST 2013


 i18npool/source/search/textsearch.cxx |   24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

New commits:
commit b32651febdaad5939250fb04f721d88952f54732
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Nov 26 01:07:38 2013 +0100

    encapsulate pRegexMatcher->find() to be able to monitor UErrorCode
    
    Change-Id: I73359a4e2c36ffeca71210971ba9be670e0a12ae

diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index ec7ce3c..593483c 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -766,6 +766,7 @@ void TextSearch::RESrchPrepare( const ::com::sun::star::util::SearchOptions& rOp
     pRegexMatcher = new RegexMatcher( aIcuSearchPatStr, nIcuSearchFlags, nIcuErr);
     if (nIcuErr)
     {
+        SAL_INFO( "i18npool", "TextSearch::RESrchPrepare UErrorCode " << nIcuErr);
         delete pRegexMatcher;
         pRegexMatcher = NULL;
     }
@@ -792,6 +793,21 @@ void TextSearch::RESrchPrepare( const ::com::sun::star::util::SearchOptions& rOp
 
 //---------------------------------------------------------------------------
 
+static bool lcl_findRegex( RegexMatcher * pRegexMatcher, sal_Int32 nStartPos, UErrorCode & rIcuErr )
+{
+    if (!pRegexMatcher->find( nStartPos, rIcuErr))
+    {
+        /* TODO: future versions could pass the UErrorCode or translations
+         * thereof to the caller, for example to inform the user of
+         * U_REGEX_TIME_OUT. The strange thing though is that an error is set
+         * only after the second call that returns immediately and not if
+         * timeout occurred on the first call?!? */
+        SAL_INFO( "i18npool", "lcl_findRegex UErrorCode " << rIcuErr);
+        return false;
+    }
+    return true;
+}
+
 SearchResult TextSearch::RESrchFrwrd( const OUString& searchStr,
                                       sal_Int32 startPos, sal_Int32 endPos )
             throw(RuntimeException)
@@ -811,7 +827,7 @@ SearchResult TextSearch::RESrchFrwrd( const OUString& searchStr,
     // search until there is a valid match
     for(;;)
     {
-        if( !pRegexMatcher->find( startPos, nIcuErr))
+        if (!lcl_findRegex( pRegexMatcher, startPos, nIcuErr))
             return aRet;
 
         // #i118887# ignore zero-length matches e.g. "a*" in "bc"
@@ -863,7 +879,7 @@ SearchResult TextSearch::RESrchBkwrd( const OUString& searchStr,
     UErrorCode nIcuErr = U_ZERO_ERROR;
     const IcuUniString aSearchTargetStr( (const UChar*)searchStr.getStr(), startPos);
     pRegexMatcher->reset( aSearchTargetStr);
-    if( !pRegexMatcher->find( endPos, nIcuErr))
+    if (!lcl_findRegex( pRegexMatcher, endPos, nIcuErr))
         return aRet;
 
     // find the last match
@@ -885,7 +901,7 @@ SearchResult TextSearch::RESrchBkwrd( const OUString& searchStr,
         bFirst = false;
         if( nFoundEnd == nLastPos)
             ++nFoundEnd;
-    } while( pRegexMatcher->find( nFoundEnd, nIcuErr));
+    } while( lcl_findRegex( pRegexMatcher, nFoundEnd, nIcuErr));
 
     // Ignore all zero-length matches except "$" anchor on first match.
     if (nGoodPos == nGoodEnd)
@@ -897,7 +913,7 @@ SearchResult TextSearch::RESrchBkwrd( const OUString& searchStr,
     }
 
     // find last match again to get its details
-    pRegexMatcher->find( nGoodPos, nIcuErr);
+    lcl_findRegex( pRegexMatcher, nGoodPos, nIcuErr);
 
     // fill in the details of the last match
     const int nGroupCount = pRegexMatcher->groupCount();


More information about the Libreoffice-commits mailing list