summaryrefslogtreecommitdiff
path: root/i18npool
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-02-23 16:15:18 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-03-01 07:28:03 +0000
commit4c09fc48e9fa9114f32f2973090cbe75177cdd37 (patch)
tree09d4ee3c2d75d038f45ba13a086a344d35aeadb6 /i18npool
parentd97380c66904328e9d706a0b03a6800dc048aa7d (diff)
typesafe wrappers for css::i18nutil::TransliterationModules
and related css::util::SearchOptions2 The TransliterationModules enum has it's constants spread over multiple UNO enum/constant-collections - TransliterationModules and TransliterationModulesExtra, which means that most code simply uses sal_Int32. Wrap them up into a better bundle so that only the lowest layer needs to deal directly with the UNO constants. Change-Id: I1edeab79fcc7817a4a97c933ef84ab7015bb849b Reviewed-on: https://gerrit.libreoffice.org/34582 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'i18npool')
-rw-r--r--i18npool/inc/transliteration_caseignore.hxx2
-rw-r--r--i18npool/qa/cppunit/test_textsearch.cxx5
-rw-r--r--i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx1
-rw-r--r--i18npool/source/search/textsearch.cxx77
-rw-r--r--i18npool/source/transliteration/transliteration_caseignore.cxx5
5 files changed, 47 insertions, 43 deletions
diff --git a/i18npool/inc/transliteration_caseignore.hxx b/i18npool/inc/transliteration_caseignore.hxx
index 93c91ea05703..dff9a94b7f63 100644
--- a/i18npool/inc/transliteration_caseignore.hxx
+++ b/i18npool/inc/transliteration_caseignore.hxx
@@ -49,7 +49,7 @@ public:
const OUString& s2) override;
protected:
- TransliterationModules moduleLoaded;
+ TransliterationFlags moduleLoaded;
private:
/// @throws css::uno::RuntimeException
sal_Int32 SAL_CALL compare(
diff --git a/i18npool/qa/cppunit/test_textsearch.cxx b/i18npool/qa/cppunit/test_textsearch.cxx
index a5a62436535d..1118b5a427e5 100644
--- a/i18npool/qa/cppunit/test_textsearch.cxx
+++ b/i18npool/qa/cppunit/test_textsearch.cxx
@@ -25,6 +25,7 @@
#include <com/sun/star/util/XTextSearch2.hpp>
#include <com/sun/star/i18n/Transliteration.hpp>
#include <unotest/bootstrapfixturebase.hxx>
+#include <i18nutil/transliteration.hxx>
#include <unicode/regex.h>
@@ -127,8 +128,8 @@ void TestTextSearch::testSearches()
CPPUNIT_ASSERT_EQUAL( bStartRes, aRes.startOffset[0] );
CPPUNIT_ASSERT_EQUAL( bEndRes, aRes.endOffset[0] );
- aOptions.transliterateFlags = ::css::i18n::TransliterationModules::TransliterationModules_IGNORE_CASE
- | ::css::i18n::TransliterationModules::TransliterationModules_IGNORE_WIDTH;
+ aOptions.transliterateFlags = (sal_Int32) (TransliterationFlags::IGNORE_CASE
+ | TransliterationFlags::IGNORE_WIDTH);
aOptions.searchString = "([^ ]*)[ ]*([^ ]*)";
m_xSearch->setOptions(aOptions);
aRes = m_xSearch->searchForward("11 22 33", 2, 7);
diff --git a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
index 847434dc594d..e9a3e299bccc 100644
--- a/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
+++ b/i18npool/source/defaultnumberingprovider/defaultnumberingprovider.cxx
@@ -56,7 +56,6 @@
#include <rtl/ustrbuf.hxx>
#include <com/sun/star/i18n/XTransliteration.hpp>
#include <com/sun/star/i18n/TransliterationType.hpp>
-#include <com/sun/star/i18n/TransliterationModulesNew.hpp>
#include <com/sun/star/i18n/XLocaleData.hpp>
#include <bullet.h>
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index f1e09da1d075..6eef20d8aafb 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -36,6 +36,7 @@
#include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/weak.hxx>
+#include <i18nutil/transliteration.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -54,56 +55,56 @@ using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star;
-const sal_Int32 COMPLEX_TRANS_MASK =
- TransliterationModules_ignoreBaFa_ja_JP |
- TransliterationModules_ignoreIterationMark_ja_JP |
- TransliterationModules_ignoreTiJi_ja_JP |
- TransliterationModules_ignoreHyuByu_ja_JP |
- TransliterationModules_ignoreSeZe_ja_JP |
- TransliterationModules_ignoreIandEfollowedByYa_ja_JP |
- TransliterationModules_ignoreKiKuFollowedBySa_ja_JP |
- TransliterationModules_ignoreProlongedSoundMark_ja_JP;
+const TransliterationFlags COMPLEX_TRANS_MASK =
+ TransliterationFlags::ignoreBaFa_ja_JP |
+ TransliterationFlags::ignoreIterationMark_ja_JP |
+ TransliterationFlags::ignoreTiJi_ja_JP |
+ TransliterationFlags::ignoreHyuByu_ja_JP |
+ TransliterationFlags::ignoreSeZe_ja_JP |
+ TransliterationFlags::ignoreIandEfollowedByYa_ja_JP |
+ TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP |
+ TransliterationFlags::ignoreProlongedSoundMark_ja_JP;
namespace
{
-sal_Int32 maskComplexTrans( sal_Int32 n )
+TransliterationFlags maskComplexTrans( TransliterationFlags n )
{
// IGNORE_KANA and FULLWIDTH_HALFWIDTH are simple but need to take effect
// in complex transliteration.
return
n & (COMPLEX_TRANS_MASK | // all set ignore bits
- TransliterationModules_IGNORE_KANA | // plus IGNORE_KANA bit
- TransliterationModules_FULLWIDTH_HALFWIDTH); // and the FULLWIDTH_HALFWIDTH value
+ TransliterationFlags::IGNORE_KANA | // plus IGNORE_KANA bit
+ TransliterationFlags::FULLWIDTH_HALFWIDTH); // and the FULLWIDTH_HALFWIDTH value
}
-bool isComplexTrans( sal_Int32 n )
+bool isComplexTrans( TransliterationFlags n )
{
- return n & COMPLEX_TRANS_MASK;
+ return bool(n & COMPLEX_TRANS_MASK);
}
-sal_Int32 maskSimpleTrans( sal_Int32 n )
+TransliterationFlags maskSimpleTrans( TransliterationFlags n )
{
return n & ~COMPLEX_TRANS_MASK;
}
-bool isSimpleTrans( sal_Int32 n )
+bool isSimpleTrans( TransliterationFlags n )
{
- return maskSimpleTrans(n) != 0;
+ return bool(maskSimpleTrans(n));
}
// Regex patterns are case sensitive.
-sal_Int32 maskSimpleRegexTrans( sal_Int32 n )
+TransliterationFlags maskSimpleRegexTrans( TransliterationFlags n )
{
- sal_Int32 m = (n & TransliterationModules_IGNORE_MASK) & ~TransliterationModules_IGNORE_CASE;
- sal_Int32 v = n & TransliterationModules_NON_IGNORE_MASK;
- if (v == TransliterationModules_UPPERCASE_LOWERCASE || v == TransliterationModules_LOWERCASE_UPPERCASE)
- v = 0;
+ TransliterationFlags m = (n & TransliterationFlags::IGNORE_MASK) & ~TransliterationFlags::IGNORE_CASE;
+ TransliterationFlags v = n & TransliterationFlags::NON_IGNORE_MASK;
+ if (v == TransliterationFlags::UPPERCASE_LOWERCASE || v == TransliterationFlags::LOWERCASE_UPPERCASE)
+ v = TransliterationFlags::NONE;
return (m | v) & ~COMPLEX_TRANS_MASK;
}
-bool isSimpleRegexTrans( sal_Int32 n )
+bool isSimpleRegexTrans( TransliterationFlags n )
{
- return maskSimpleRegexTrans(n) != 0;
+ return bool(maskSimpleRegexTrans(n));
}
};
@@ -144,27 +145,28 @@ void TextSearch::setOptions2( const SearchOptions2& rOptions )
pJumpTable2 = nullptr;
maWildcardReversePattern.clear();
maWildcardReversePattern2.clear();
+ TransliterationFlags transliterateFlags = (TransliterationFlags) aSrchPara.transliterateFlags;
// Create Transliteration class
- if( isSimpleTrans( aSrchPara.transliterateFlags) )
+ if( isSimpleTrans( transliterateFlags) )
{
if( !xTranslit.is() )
xTranslit.set( Transliteration::create( m_xContext ) );
xTranslit->loadModule(
- (TransliterationModules) maskSimpleTrans( aSrchPara.transliterateFlags),
+ (TransliterationModules)maskSimpleTrans(transliterateFlags),
aSrchPara.Locale);
}
else if( xTranslit.is() )
xTranslit = nullptr;
// Create Transliteration for 2<->1, 2<->2 transliteration
- if ( isComplexTrans( aSrchPara.transliterateFlags) )
+ if ( isComplexTrans( transliterateFlags) )
{
if( !xTranslit2.is() )
xTranslit2.set( Transliteration::create( m_xContext ) );
// Load transliteration module
xTranslit2->loadModule(
- (TransliterationModules) maskComplexTrans( aSrchPara.transliterateFlags),
+ (TransliterationModules) maskComplexTrans(transliterateFlags),
aSrchPara.Locale);
}
@@ -176,17 +178,17 @@ void TextSearch::setOptions2( const SearchOptions2& rOptions )
// Transliterate search string.
if (aSrchPara.AlgorithmType2 == SearchAlgorithms2::REGEXP)
{
- if (isSimpleRegexTrans( aSrchPara.transliterateFlags))
+ if (isSimpleRegexTrans(transliterateFlags))
{
- if (maskSimpleRegexTrans( aSrchPara.transliterateFlags) !=
- maskSimpleTrans( aSrchPara.transliterateFlags))
+ if (maskSimpleRegexTrans(transliterateFlags) !=
+ maskSimpleTrans(transliterateFlags))
{
css::uno::Reference< XExtendedTransliteration > xTranslitPattern(
Transliteration::create( m_xContext ));
if (xTranslitPattern.is())
{
xTranslitPattern->loadModule(
- (TransliterationModules) maskSimpleRegexTrans( aSrchPara.transliterateFlags),
+ (TransliterationModules) maskSimpleRegexTrans(transliterateFlags),
aSrchPara.Locale);
sSrchStr = xTranslitPattern->transliterateString2String(
aSrchPara.searchString, 0, aSrchPara.searchString.getLength());
@@ -205,11 +207,11 @@ void TextSearch::setOptions2( const SearchOptions2& rOptions )
}
else
{
- if ( xTranslit.is() && isSimpleTrans( aSrchPara.transliterateFlags) )
+ if ( xTranslit.is() && isSimpleTrans(transliterateFlags) )
sSrchStr = xTranslit->transliterateString2String(
aSrchPara.searchString, 0, aSrchPara.searchString.getLength());
- if ( xTranslit2.is() && isComplexTrans( aSrchPara.transliterateFlags) )
+ if ( xTranslit2.is() && isComplexTrans(transliterateFlags) )
sSrchStr2 = xTranslit2->transliterateString2String(
aSrchPara.searchString, 0, aSrchPara.searchString.getLength());
}
@@ -827,10 +829,11 @@ SearchResult TextSearch::NSrchBkwrd( const OUString& searchStr, sal_Int32 startP
void TextSearch::RESrchPrepare( const css::util::SearchOptions2& rOptions)
{
+ TransliterationFlags transliterateFlags = (TransliterationFlags)rOptions.transliterateFlags;
// select the transliterated pattern string
const OUString& rPatternStr =
- (isSimpleTrans( rOptions.transliterateFlags) ? sSrchStr
- : (isComplexTrans( rOptions.transliterateFlags) ? sSrchStr2 : rOptions.searchString));
+ (isSimpleTrans(transliterateFlags) ? sSrchStr
+ : (isComplexTrans(transliterateFlags) ? sSrchStr2 : rOptions.searchString));
sal_uInt32 nIcuSearchFlags = UREGEX_UWORD; // request UAX#29 unicode capability
// map css::util::SearchFlags to ICU uregex.h flags
@@ -842,7 +845,7 @@ void TextSearch::RESrchPrepare( const css::util::SearchOptions2& rOptions)
// Note that the search flag ALL_IGNORE_CASE is deprecated in UNO
// probably because the transliteration flag IGNORE_CASE handles it as well.
if( (rOptions.searchFlag & css::util::SearchFlags::ALL_IGNORE_CASE) != 0
- || (rOptions.transliterateFlags & TransliterationModules_IGNORE_CASE) != 0)
+ || (transliterateFlags & TransliterationFlags::IGNORE_CASE))
nIcuSearchFlags |= UREGEX_CASE_INSENSITIVE;
UErrorCode nIcuErr = U_ZERO_ERROR;
// assumption: transliteration didn't mangle regexp control chars
diff --git a/i18npool/source/transliteration/transliteration_caseignore.cxx b/i18npool/source/transliteration/transliteration_caseignore.cxx
index e6f0061efc8a..9ac4712ba233 100644
--- a/i18npool/source/transliteration/transliteration_caseignore.cxx
+++ b/i18npool/source/transliteration/transliteration_caseignore.cxx
@@ -22,6 +22,7 @@
#include <i18nutil/oneToOneMapping.hxx>
#include <i18nutil/casefolding.hxx>
+#include <i18nutil/transliteration.hxx>
#include "transliteration_caseignore.hxx"
@@ -33,7 +34,7 @@ namespace com { namespace sun { namespace star { namespace i18n {
Transliteration_caseignore::Transliteration_caseignore()
{
nMappingType = MappingType::FullFolding;
- moduleLoaded = (TransliterationModules)0;
+ moduleLoaded = TransliterationFlags::NONE;
transliterationName = "case ignore (generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
}
@@ -41,7 +42,7 @@ Transliteration_caseignore::Transliteration_caseignore()
void SAL_CALL
Transliteration_caseignore::loadModule( TransliterationModules modName, const Locale& rLocale )
{
- moduleLoaded = (TransliterationModules) (moduleLoaded|modName);
+ moduleLoaded |= (TransliterationFlags)modName;
aLocale = rLocale;
}