Use icu::UnicodeString directly
Change-Id: I41b4e64d6d3a9310d819904c8d32c689e6300bcd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131296 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -27,7 +27,6 @@
|
|||||||
#include <unicode/regex.h>
|
#include <unicode/regex.h>
|
||||||
|
|
||||||
using namespace ::com::sun::star;
|
using namespace ::com::sun::star;
|
||||||
typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
|
|
||||||
|
|
||||||
class TestTextSearch : public test::BootstrapFixtureBase
|
class TestTextSearch : public test::BootstrapFixtureBase
|
||||||
{
|
{
|
||||||
@@ -59,11 +58,11 @@ void TestTextSearch::testICU()
|
|||||||
|
|
||||||
OUString aString( "abcdefgh" );
|
OUString aString( "abcdefgh" );
|
||||||
OUString aPattern( "e" );
|
OUString aPattern( "e" );
|
||||||
IcuUniString aSearchPat( reinterpret_cast<const UChar*>(aPattern.getStr()), aPattern.getLength() );
|
icu::UnicodeString aSearchPat( reinterpret_cast<const UChar*>(aPattern.getStr()), aPattern.getLength() );
|
||||||
|
|
||||||
std::unique_ptr<icu::RegexMatcher> pRegexMatcher(new icu::RegexMatcher( aSearchPat, nSearchFlags, nErr ));
|
std::unique_ptr<icu::RegexMatcher> pRegexMatcher(new icu::RegexMatcher( aSearchPat, nSearchFlags, nErr ));
|
||||||
|
|
||||||
IcuUniString aSource( reinterpret_cast<const UChar*>(aString.getStr()), aString.getLength() );
|
icu::UnicodeString aSource( reinterpret_cast<const UChar*>(aString.getStr()), aString.getLength() );
|
||||||
pRegexMatcher->reset( aSource );
|
pRegexMatcher->reset( aSource );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
|
CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
|
||||||
@@ -76,10 +75,10 @@ void TestTextSearch::testICU()
|
|||||||
OUString aString2( "acababaabcababadcdaa" );
|
OUString aString2( "acababaabcababadcdaa" );
|
||||||
OUString aPattern2( "a" );
|
OUString aPattern2( "a" );
|
||||||
|
|
||||||
IcuUniString aSearchPat2( reinterpret_cast<const UChar*>(aPattern2.getStr()), aPattern2.getLength() );
|
icu::UnicodeString aSearchPat2( reinterpret_cast<const UChar*>(aPattern2.getStr()), aPattern2.getLength() );
|
||||||
pRegexMatcher.reset(new icu::RegexMatcher( aSearchPat2, nSearchFlags, nErr ));
|
pRegexMatcher.reset(new icu::RegexMatcher( aSearchPat2, nSearchFlags, nErr ));
|
||||||
|
|
||||||
IcuUniString aSource2( reinterpret_cast<const UChar*>(aString2.getStr()), aString2.getLength() );
|
icu::UnicodeString aSource2( reinterpret_cast<const UChar*>(aString2.getStr()), aString2.getLength() );
|
||||||
pRegexMatcher->reset( aSource2 );
|
pRegexMatcher->reset( aSource2 );
|
||||||
|
|
||||||
CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
|
CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
|
||||||
|
@@ -877,19 +877,19 @@ void TextSearch::RESrchPrepare( const css::util::SearchOptions2& rOptions)
|
|||||||
nIcuSearchFlags |= UREGEX_CASE_INSENSITIVE;
|
nIcuSearchFlags |= UREGEX_CASE_INSENSITIVE;
|
||||||
UErrorCode nIcuErr = U_ZERO_ERROR;
|
UErrorCode nIcuErr = U_ZERO_ERROR;
|
||||||
// assumption: transliteration didn't mangle regexp control chars
|
// assumption: transliteration didn't mangle regexp control chars
|
||||||
IcuUniString aIcuSearchPatStr( reinterpret_cast<const UChar*>(rPatternStr.getStr()), rPatternStr.getLength());
|
icu::UnicodeString aIcuSearchPatStr( reinterpret_cast<const UChar*>(rPatternStr.getStr()), rPatternStr.getLength());
|
||||||
#ifndef DISABLE_WORDBOUND_EMULATION
|
#ifndef DISABLE_WORDBOUND_EMULATION
|
||||||
// for convenience specific syntax elements of the old regex engine are emulated
|
// for convenience specific syntax elements of the old regex engine are emulated
|
||||||
// - by replacing \< with "word-break followed by a look-ahead word-char"
|
// - by replacing \< with "word-break followed by a look-ahead word-char"
|
||||||
static const IcuUniString aChevronPatternB( "\\\\<", -1, IcuUniString::kInvariant);
|
static const icu::UnicodeString aChevronPatternB( "\\\\<", -1, icu::UnicodeString::kInvariant);
|
||||||
static const IcuUniString aChevronReplaceB( "\\\\b(?=\\\\w)", -1, IcuUniString::kInvariant);
|
static const icu::UnicodeString aChevronReplaceB( "\\\\b(?=\\\\w)", -1, icu::UnicodeString::kInvariant);
|
||||||
static icu::RegexMatcher aChevronMatcherB( aChevronPatternB, 0, nIcuErr);
|
static icu::RegexMatcher aChevronMatcherB( aChevronPatternB, 0, nIcuErr);
|
||||||
aChevronMatcherB.reset( aIcuSearchPatStr);
|
aChevronMatcherB.reset( aIcuSearchPatStr);
|
||||||
aIcuSearchPatStr = aChevronMatcherB.replaceAll( aChevronReplaceB, nIcuErr);
|
aIcuSearchPatStr = aChevronMatcherB.replaceAll( aChevronReplaceB, nIcuErr);
|
||||||
aChevronMatcherB.reset();
|
aChevronMatcherB.reset();
|
||||||
// - by replacing \> with "look-behind word-char followed by a word-break"
|
// - by replacing \> with "look-behind word-char followed by a word-break"
|
||||||
static const IcuUniString aChevronPatternE( "\\\\>", -1, IcuUniString::kInvariant);
|
static const icu::UnicodeString aChevronPatternE( "\\\\>", -1, icu::UnicodeString::kInvariant);
|
||||||
static const IcuUniString aChevronReplaceE( "(?<=\\\\w)\\\\b", -1, IcuUniString::kInvariant);
|
static const icu::UnicodeString aChevronReplaceE( "(?<=\\\\w)\\\\b", -1, icu::UnicodeString::kInvariant);
|
||||||
static icu::RegexMatcher aChevronMatcherE( aChevronPatternE, 0, nIcuErr);
|
static icu::RegexMatcher aChevronMatcherE( aChevronPatternE, 0, nIcuErr);
|
||||||
aChevronMatcherE.reset( aIcuSearchPatStr);
|
aChevronMatcherE.reset( aIcuSearchPatStr);
|
||||||
aIcuSearchPatStr = aChevronMatcherE.replaceAll( aChevronReplaceE, nIcuErr);
|
aIcuSearchPatStr = aChevronMatcherE.replaceAll( aChevronReplaceE, nIcuErr);
|
||||||
@@ -957,7 +957,7 @@ SearchResult TextSearch::RESrchFrwrd( const OUString& searchStr,
|
|||||||
|
|
||||||
// use the ICU RegexMatcher to find the matches
|
// use the ICU RegexMatcher to find the matches
|
||||||
UErrorCode nIcuErr = U_ZERO_ERROR;
|
UErrorCode nIcuErr = U_ZERO_ERROR;
|
||||||
const IcuUniString aSearchTargetStr(false, reinterpret_cast<const UChar*>(searchStr.getStr()),
|
const icu::UnicodeString aSearchTargetStr(false, reinterpret_cast<const UChar*>(searchStr.getStr()),
|
||||||
searchStr.getLength());
|
searchStr.getLength());
|
||||||
pRegexMatcher->reset( aSearchTargetStr);
|
pRegexMatcher->reset( aSearchTargetStr);
|
||||||
// search until there is a valid match
|
// search until there is a valid match
|
||||||
@@ -1014,7 +1014,7 @@ SearchResult TextSearch::RESrchBkwrd( const OUString& searchStr,
|
|||||||
// TODO: use ICU's backward searching once it becomes available
|
// TODO: use ICU's backward searching once it becomes available
|
||||||
// as its replacement using forward search is not as good as the real thing
|
// as its replacement using forward search is not as good as the real thing
|
||||||
UErrorCode nIcuErr = U_ZERO_ERROR;
|
UErrorCode nIcuErr = U_ZERO_ERROR;
|
||||||
const IcuUniString aSearchTargetStr(false, reinterpret_cast<const UChar*>(searchStr.getStr()),
|
const icu::UnicodeString aSearchTargetStr(false, reinterpret_cast<const UChar*>(searchStr.getStr()),
|
||||||
searchStr.getLength());
|
searchStr.getLength());
|
||||||
pRegexMatcher->reset( aSearchTargetStr);
|
pRegexMatcher->reset( aSearchTargetStr);
|
||||||
if (!lcl_findRegex( pRegexMatcher, endPos, startPos, nIcuErr))
|
if (!lcl_findRegex( pRegexMatcher, endPos, startPos, nIcuErr))
|
||||||
|
@@ -38,8 +38,6 @@ namespace com::sun::star::i18n { class XExtendedTransliteration; }
|
|||||||
namespace com::sun::star::uno { class XComponentContext; }
|
namespace com::sun::star::uno { class XComponentContext; }
|
||||||
|
|
||||||
|
|
||||||
typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
|
|
||||||
|
|
||||||
class WLevDistance;
|
class WLevDistance;
|
||||||
typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
|
typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user