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:
Mike Kaganski
2022-03-10 09:44:14 +03:00
parent 41cbbb6ecb
commit 0dc4cbe342
3 changed files with 11 additions and 14 deletions

View File

@@ -27,7 +27,6 @@
#include <unicode/regex.h>
using namespace ::com::sun::star;
typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
class TestTextSearch : public test::BootstrapFixtureBase
{
@@ -59,11 +58,11 @@ void TestTextSearch::testICU()
OUString aString( "abcdefgh" );
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 ));
IcuUniString aSource( reinterpret_cast<const UChar*>(aString.getStr()), aString.getLength() );
icu::UnicodeString aSource( reinterpret_cast<const UChar*>(aString.getStr()), aString.getLength() );
pRegexMatcher->reset( aSource );
CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );
@@ -76,10 +75,10 @@ void TestTextSearch::testICU()
OUString aString2( "acababaabcababadcdaa" );
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 ));
IcuUniString aSource2( reinterpret_cast<const UChar*>(aString2.getStr()), aString2.getLength() );
icu::UnicodeString aSource2( reinterpret_cast<const UChar*>(aString2.getStr()), aString2.getLength() );
pRegexMatcher->reset( aSource2 );
CPPUNIT_ASSERT( pRegexMatcher->find( 0, nErr ) );

View File

@@ -877,19 +877,19 @@ void TextSearch::RESrchPrepare( const css::util::SearchOptions2& rOptions)
nIcuSearchFlags |= UREGEX_CASE_INSENSITIVE;
UErrorCode nIcuErr = U_ZERO_ERROR;
// 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
// for convenience specific syntax elements of the old regex engine are emulated
// - by replacing \< with "word-break followed by a look-ahead word-char"
static const IcuUniString aChevronPatternB( "\\\\<", -1, IcuUniString::kInvariant);
static const IcuUniString aChevronReplaceB( "\\\\b(?=\\\\w)", -1, IcuUniString::kInvariant);
static const icu::UnicodeString aChevronPatternB( "\\\\<", -1, icu::UnicodeString::kInvariant);
static const icu::UnicodeString aChevronReplaceB( "\\\\b(?=\\\\w)", -1, icu::UnicodeString::kInvariant);
static icu::RegexMatcher aChevronMatcherB( aChevronPatternB, 0, nIcuErr);
aChevronMatcherB.reset( aIcuSearchPatStr);
aIcuSearchPatStr = aChevronMatcherB.replaceAll( aChevronReplaceB, nIcuErr);
aChevronMatcherB.reset();
// - by replacing \> with "look-behind word-char followed by a word-break"
static const IcuUniString aChevronPatternE( "\\\\>", -1, IcuUniString::kInvariant);
static const IcuUniString aChevronReplaceE( "(?<=\\\\w)\\\\b", -1, IcuUniString::kInvariant);
static const icu::UnicodeString aChevronPatternE( "\\\\>", -1, icu::UnicodeString::kInvariant);
static const icu::UnicodeString aChevronReplaceE( "(?<=\\\\w)\\\\b", -1, icu::UnicodeString::kInvariant);
static icu::RegexMatcher aChevronMatcherE( aChevronPatternE, 0, nIcuErr);
aChevronMatcherE.reset( aIcuSearchPatStr);
aIcuSearchPatStr = aChevronMatcherE.replaceAll( aChevronReplaceE, nIcuErr);
@@ -957,7 +957,7 @@ SearchResult TextSearch::RESrchFrwrd( const OUString& searchStr,
// use the ICU RegexMatcher to find the matches
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());
pRegexMatcher->reset( aSearchTargetStr);
// 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
// as its replacement using forward search is not as good as the real thing
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());
pRegexMatcher->reset( aSearchTargetStr);
if (!lcl_findRegex( pRegexMatcher, endPos, startPos, nIcuErr))

View File

@@ -38,8 +38,6 @@ namespace com::sun::star::i18n { class XExtendedTransliteration; }
namespace com::sun::star::uno { class XComponentContext; }
typedef U_ICU_NAMESPACE::UnicodeString IcuUniString;
class WLevDistance;
typedef ::std::map< sal_Unicode, sal_Int32 > TextSearchJumpTable;