summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2016-05-10 15:04:39 +0200
committerNoel Grandin <noelgrandin@gmail.com>2016-05-11 06:55:08 +0000
commit33efbfda45a96f540f976abf3dc00ab256872af4 (patch)
treea19925f0928a93474e47b6740470d6ed79c00507
parent265068d65b39688b8a4756dfbcd46453dd1f9b70 (diff)
convert MappingType to scoped enum
Change-Id: I1f00e1fbdb9213d0c2f30da116684b77842282f5 Reviewed-on: https://gerrit.libreoffice.org/24851 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r--i18npool/inc/transliteration_body.hxx4
-rw-r--r--i18npool/source/characterclassification/cclass_unicode.cxx6
-rw-r--r--i18npool/source/transliteration/transliteration_body.cxx38
-rw-r--r--i18npool/source/transliteration/transliteration_caseignore.cxx2
-rw-r--r--i18nutil/source/utility/casefolding.cxx30
-rw-r--r--include/i18nutil/casefolding.hxx38
6 files changed, 64 insertions, 54 deletions
diff --git a/i18npool/inc/transliteration_body.hxx b/i18npool/inc/transliteration_body.hxx
index 01757b95f4dd..55616997cdeb 100644
--- a/i18npool/inc/transliteration_body.hxx
+++ b/i18npool/inc/transliteration_body.hxx
@@ -56,7 +56,7 @@ public:
const OUString& str2 ) throw(css::uno::RuntimeException, std::exception) override;
protected:
- sal_uInt8 nMappingType;
+ MappingType nMappingType;
};
class Transliteration_u2l : public Transliteration_body
@@ -75,7 +75,7 @@ class Transliteration_casemapping : public Transliteration_body
{
public:
Transliteration_casemapping();
- void SAL_CALL setMappingType(const sal_uInt8 rMappingType, const css::lang::Locale& rLocale );
+ void SAL_CALL setMappingType(const MappingType rMappingType, const css::lang::Locale& rLocale );
};
class Transliteration_togglecase : public Transliteration_body
diff --git a/i18npool/source/characterclassification/cclass_unicode.cxx b/i18npool/source/characterclassification/cclass_unicode.cxx
index e9e9612f65f7..c4a8babb0a6f 100644
--- a/i18npool/source/characterclassification/cclass_unicode.cxx
+++ b/i18npool/source/characterclassification/cclass_unicode.cxx
@@ -63,7 +63,7 @@ cclass_Unicode::toUpper( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
if (nCount + nPos > len)
nCount = len - nPos;
- trans->setMappingType(MappingTypeToUpper, rLocale);
+ trans->setMappingType(MappingType::ToUpper, rLocale);
return trans->transliterateString2String(Text, nPos, nCount);
}
@@ -75,7 +75,7 @@ cclass_Unicode::toLower( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
if (nCount + nPos > len)
nCount = len - nPos;
- trans->setMappingType(MappingTypeToLower, rLocale);
+ trans->setMappingType(MappingType::ToLower, rLocale);
return trans->transliterateString2String(Text, nPos, nCount);
}
@@ -89,7 +89,7 @@ cclass_Unicode::toTitle( const OUString& Text, sal_Int32 nPos, sal_Int32 nCount,
if (nCount + nPos > len)
nCount = len - nPos;
- trans->setMappingType(MappingTypeToTitle, rLocale);
+ trans->setMappingType(MappingType::ToTitle, rLocale);
rtl_uString* pStr = rtl_uString_alloc(nCount);
sal_Unicode* out = pStr->buffer;
Reference< BreakIteratorImpl > xBrk(new BreakIteratorImpl(m_xContext));
diff --git a/i18npool/source/transliteration/transliteration_body.cxx b/i18npool/source/transliteration/transliteration_body.cxx
index 982c80c5ac02..0470ed4ac99b 100644
--- a/i18npool/source/transliteration/transliteration_body.cxx
+++ b/i18npool/source/transliteration/transliteration_body.cxx
@@ -40,7 +40,7 @@ namespace com { namespace sun { namespace star { namespace i18n {
Transliteration_body::Transliteration_body()
{
- nMappingType = 0;
+ nMappingType = MappingType::NONE;
transliterationName = "Transliteration_body";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_body";
}
@@ -68,22 +68,22 @@ Transliteration_body::transliterateRange( const OUString& str1, const OUString&
return ostr;
}
-static sal_uInt8 lcl_getMappingTypeForToggleCase( sal_uInt8 nMappingType, sal_Unicode cChar )
+static MappingType lcl_getMappingTypeForToggleCase( MappingType nMappingType, sal_Unicode cChar )
{
- sal_uInt8 nRes = nMappingType;
+ MappingType nRes = nMappingType;
// take care of TOGGLE_CASE transliteration:
// nMappingType should not be a combination of flags, thuse we decide now
// which one to use.
- if (nMappingType == (MappingTypeLowerToUpper | MappingTypeUpperToLower))
+ if (nMappingType == (MappingType::LowerToUpper | MappingType::UpperToLower))
{
const sal_Int16 nType = unicode::getUnicodeType( cChar );
if (nType & 0x02 /* lower case*/)
- nRes = MappingTypeLowerToUpper;
+ nRes = MappingType::LowerToUpper;
else
{
// should also work properly for non-upper characters like white spaces, numbers, ...
- nRes = MappingTypeUpperToLower;
+ nRes = MappingType::UpperToLower;
}
}
@@ -106,8 +106,8 @@ Transliteration_body::transliterate(
for (i = 0; i < nCount; i++)
{
// take care of TOGGLE_CASE transliteration:
- sal_uInt8 nTmpMappingType = nMappingType;
- if (nMappingType == (MappingTypeLowerToUpper | MappingTypeUpperToLower))
+ MappingType nTmpMappingType = nMappingType;
+ if (nMappingType == (MappingType::LowerToUpper | MappingType::UpperToLower))
nTmpMappingType = lcl_getMappingTypeForToggleCase( nMappingType, in[i] );
const Mapping &map = casefolding::getValue( in, i, nCount, aLocale, nTmpMappingType );
@@ -124,8 +124,8 @@ Transliteration_body::transliterate(
for (i = 0; i < nCount; i++)
{
// take care of TOGGLE_CASE transliteration:
- sal_uInt8 nTmpMappingType = nMappingType;
- if (nMappingType == (MappingTypeLowerToUpper | MappingTypeUpperToLower))
+ MappingType nTmpMappingType = nMappingType;
+ if (nMappingType == (MappingType::LowerToUpper | MappingType::UpperToLower))
nTmpMappingType = lcl_getMappingTypeForToggleCase( nMappingType, in[i] );
const Mapping &map = casefolding::getValue( in, i, nCount, aLocale, nTmpMappingType );
@@ -164,8 +164,8 @@ Transliteration_body::transliterate(
for ( sal_Int32 i = 0; i < nCount; i++)
{
// take care of TOGGLE_CASE transliteration:
- sal_uInt8 nTmpMappingType = nMappingType;
- if (nMappingType == (MappingTypeLowerToUpper | MappingTypeUpperToLower))
+ MappingType nTmpMappingType = nMappingType;
+ if (nMappingType == (MappingType::LowerToUpper | MappingType::UpperToLower))
nTmpMappingType = lcl_getMappingTypeForToggleCase( nMappingType, in[i] );
const Mapping &map = casefolding::getValue( in, i, nCount, aLocale, nTmpMappingType );
@@ -213,13 +213,13 @@ Transliteration_body::folding( const OUString& inStr, sal_Int32 startPos, sal_In
Transliteration_casemapping::Transliteration_casemapping()
{
- nMappingType = 0;
+ nMappingType = MappingType::NONE;
transliterationName = "casemapping(generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_casemapping";
}
void SAL_CALL
-Transliteration_casemapping::setMappingType( const sal_uInt8 rMappingType, const Locale& rLocale )
+Transliteration_casemapping::setMappingType( const MappingType rMappingType, const Locale& rLocale )
{
nMappingType = rMappingType;
aLocale = rLocale;
@@ -227,14 +227,14 @@ Transliteration_casemapping::setMappingType( const sal_uInt8 rMappingType, const
Transliteration_u2l::Transliteration_u2l()
{
- nMappingType = MappingTypeUpperToLower;
+ nMappingType = MappingType::UpperToLower;
transliterationName = "upper_to_lower(generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_u2l";
}
Transliteration_l2u::Transliteration_l2u()
{
- nMappingType = MappingTypeLowerToUpper;
+ nMappingType = MappingType::LowerToUpper;
transliterationName = "lower_to_upper(generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_l2u";
}
@@ -245,14 +245,14 @@ Transliteration_togglecase::Transliteration_togglecase()
// but we take care of that problem in Transliteration_body::transliterate above
// before that value is used. There we will decide which of both is to be used on
// a per character basis.
- nMappingType = MappingTypeLowerToUpper | MappingTypeUpperToLower;
+ nMappingType = MappingType::LowerToUpper | MappingType::UpperToLower;
transliterationName = "toggle(generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_togglecase";
}
Transliteration_titlecase::Transliteration_titlecase()
{
- nMappingType = MappingTypeToTitle;
+ nMappingType = MappingType::ToTitle;
transliterationName = "title(generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_titlecase";
}
@@ -316,7 +316,7 @@ OUString SAL_CALL Transliteration_titlecase::transliterate(
Transliteration_sentencecase::Transliteration_sentencecase()
{
- nMappingType = MappingTypeToTitle; // though only to be applied to the first word...
+ nMappingType = MappingType::ToTitle; // though only to be applied to the first word...
transliterationName = "sentence(generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_sentencecase";
}
diff --git a/i18npool/source/transliteration/transliteration_caseignore.cxx b/i18npool/source/transliteration/transliteration_caseignore.cxx
index 52f0cd2f21e4..e01eb1f2a71e 100644
--- a/i18npool/source/transliteration/transliteration_caseignore.cxx
+++ b/i18npool/source/transliteration/transliteration_caseignore.cxx
@@ -31,7 +31,7 @@ namespace com { namespace sun { namespace star { namespace i18n {
Transliteration_caseignore::Transliteration_caseignore()
{
- nMappingType = MappingTypeFullFolding;
+ nMappingType = MappingType::FullFolding;
moduleLoaded = (TransliterationModules)0;
transliterationName = "case ignore (generic)";
implementationName = "com.sun.star.i18n.Transliteration.Transliteration_caseignore";
diff --git a/i18nutil/source/utility/casefolding.cxx b/i18nutil/source/utility/casefolding.cxx
index 3fb7845afa66..88b32e3d3a68 100644
--- a/i18nutil/source/utility/casefolding.cxx
+++ b/i18nutil/source/utility/casefolding.cxx
@@ -42,13 +42,21 @@ static Mapping mapping_0130[] = {{0, 1, {0x0069, 0, 0}},{0, 1, {0x0130, 0, 0}}};
// only check simple case, there is more complicated case need to be checked.
#define type_i(ch) ((ch) == 0x0069 || (ch) == 0x006a)
-#define cased_letter(ch) (CaseMappingIndex[(ch)>>8] >= 0 && (CaseMappingValue[(CaseMappingIndex[(ch)>>8] << 8) + ((ch)&0xff)].type & CasedLetter))
+static bool cased_letter(sal_Unicode ch)
+{
+ int msb = ch >> 8;
+ int cmi = CaseMappingIndex[msb];
+ if (cmi < 0)
+ return false;
+ int cmv_idx = (cmi << 8) + (ch & 0xff);
+ return bool(((MappingType)CaseMappingValue[cmv_idx].type) & MappingType::CasedLetterMask);
+}
// for Lithuanian, condition to make explicit dot above when lowercasing capital I's and J's
// whenever there are more accents above.
#define accent_above(ch) (((ch) >= 0x0300 && (ch) <= 0x0314) || ((ch) >= 0x033D && (ch) <= 0x0344) || (ch) == 0x0346 || ((ch) >= 0x034A && (ch) <= 0x034C))
-Mapping& casefolding::getConditionalValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, Locale& aLocale, sal_uInt8 nMappingType) throw (RuntimeException)
+Mapping& casefolding::getConditionalValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, Locale& aLocale, MappingType nMappingType) throw (RuntimeException)
{
switch(str[pos]) {
case 0x03a3:
@@ -57,8 +65,8 @@ Mapping& casefolding::getConditionalValue(const sal_Unicode* str, sal_Int32 pos,
return !(pos < len && cased_letter(str[pos+1])) && (pos > 0 && cased_letter(str[pos-1])) ?
mapping_03a3[0] : mapping_03a3[1];
case 0x0307:
- return (((nMappingType == MappingTypeLowerToUpper && langIs("lt")) ||
- (nMappingType == MappingTypeUpperToLower && (langIs("tr") || langIs("az")))) &&
+ return (((nMappingType == MappingType::LowerToUpper && langIs("lt")) ||
+ (nMappingType == MappingType::UpperToLower && (langIs("tr") || langIs("az")))) &&
(pos > 0 && type_i(str[pos-1]))) ? // after_i
mapping_0307[0] : mapping_0307[1];
case 0x0130:
@@ -77,7 +85,7 @@ Mapping& casefolding::getConditionalValue(const sal_Unicode* str, sal_Int32 pos,
throw RuntimeException();
}
-Mapping& casefolding::getValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, Locale& aLocale, sal_uInt8 nMappingType) throw (RuntimeException)
+Mapping& casefolding::getValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, Locale& aLocale, MappingType nMappingType) throw (RuntimeException)
{
static Mapping dummy = { 0, 1, { 0, 0, 0 } };
sal_Int16 address = CaseMappingIndex[str[pos] >> 8];
@@ -86,16 +94,16 @@ Mapping& casefolding::getValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32
if (address >= 0) {
address = (address << 8) + (str[pos] & 0xFF);
- if (CaseMappingValue[address].type & nMappingType) {
- sal_uInt8 type = CaseMappingValue[address].type;
- if (type & ValueTypeNotValue) {
+ if ((MappingType)CaseMappingValue[address].type & nMappingType) {
+ MappingType type = (MappingType) CaseMappingValue[address].type;
+ if (type & MappingType::NotValue) {
if (CaseMappingValue[address].value == 0)
return getConditionalValue(str, pos, len, aLocale, nMappingType);
else {
for (int map = CaseMappingValue[address].value;
map < CaseMappingValue[address].value + MaxCaseMappingExtras; map++) {
- if (CaseMappingExtra[map].type & nMappingType) {
- if (CaseMappingExtra[map].type & ValueTypeNotValue)
+ if ((MappingType)CaseMappingExtra[map].type & nMappingType) {
+ if ((MappingType)CaseMappingExtra[map].type & MappingType::NotValue)
return getConditionalValue(str, pos, len, aLocale, nMappingType);
else
return CaseMappingExtra[map];
@@ -121,7 +129,7 @@ is_ja_voice_sound_mark(sal_Unicode& current, sal_Unicode next)
return c != 0;
}
-sal_Unicode casefolding::getNextChar(const sal_Unicode *str, sal_Int32& idx, sal_Int32 len, MappingElement& e, Locale& aLocale, sal_uInt8 nMappingType, TransliterationModules moduleLoaded) throw (RuntimeException)
+sal_Unicode casefolding::getNextChar(const sal_Unicode *str, sal_Int32& idx, sal_Int32 len, MappingElement& e, Locale& aLocale, MappingType nMappingType, TransliterationModules moduleLoaded) throw (RuntimeException)
{
if( idx >= len )
{
diff --git a/include/i18nutil/casefolding.hxx b/include/i18nutil/casefolding.hxx
index 091a7109f1f9..5ddb208ea566 100644
--- a/include/i18nutil/casefolding.hxx
+++ b/include/i18nutil/casefolding.hxx
@@ -24,23 +24,25 @@
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>
#include <i18nutil/i18nutildllapi.h>
+#include <o3tl/typed_flags_set.hxx>
-namespace com { namespace sun { namespace star { namespace i18n {
-
-#define MappingTypeLowerToUpper (1 << 0) // Upper to Lower mapping
-#define MappingTypeUpperToLower (1 << 1) // Lower to Upper mapping
-#define MappingTypeToUpper (1 << 2) // to Upper mapping
-#define MappingTypeToLower (1 << 3) // to Lower mapping
-#define MappingTypeToTitle (1 << 4) // to Title mapping
-#define MappingTypeSimpleFolding (1 << 5) // Simple Case Folding
-#define MappingTypeFullFolding (1 << 6) // Full Case Folding
-#define MappingTypeMask (MappingTypeLowerToUpper|MappingTypeUpperToLower|\
- MappingTypeToUpper|MappingTypeToLower|MappingTypeToTitle|\
- MappingTypeSimpleFolding|MappingTypeFullFolding)
-
-#define ValueTypeNotValue (1 << 7) // Value field is an address
+enum class MappingType {
+ NONE = 0x00,
+ LowerToUpper = 0x01, // Upper to Lower mapping
+ UpperToLower = 0x02, // Lower to Upper mapping
+ ToUpper = 0x04, // to Upper mapping
+ ToLower = 0x08, // to Lower mapping
+ ToTitle = 0x10, // to Title mapping
+ SimpleFolding = 0x20, // Simple Case Folding
+ FullFolding = 0x40, // Full Case Folding
+ CasedLetterMask = LowerToUpper | UpperToLower | ToUpper | ToLower | ToTitle | SimpleFolding | FullFolding, // for final sigmar
+ NotValue = 0x80, // Value field is an address
+};
+namespace o3tl {
+ template<> struct typed_flags<MappingType> : is_typed_flags<MappingType, 0xff> {};
+}
-#define CasedLetter (MappingTypeMask) // for final sigmar
+namespace com { namespace sun { namespace star { namespace i18n {
struct Value
{
@@ -70,9 +72,9 @@ struct MappingElement
class I18NUTIL_DLLPUBLIC casefolding
{
public:
- static Mapping& getValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, css::lang::Locale& aLocale, sal_uInt8 nMappingType) throw (css::uno::RuntimeException);
- static Mapping& getConditionalValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, css::lang::Locale& aLocale, sal_uInt8 nMappingType) throw (css::uno::RuntimeException);
- static sal_Unicode getNextChar(const sal_Unicode *str, sal_Int32& idx, sal_Int32 len, MappingElement& e, css::lang::Locale& aLocale,sal_uInt8 nMappingtype, TransliterationModules moduleLoaded) throw (css::uno::RuntimeException);
+ static Mapping& getValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, css::lang::Locale& aLocale, MappingType nMappingType) throw (css::uno::RuntimeException);
+ static Mapping& getConditionalValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, css::lang::Locale& aLocale, MappingType nMappingType) throw (css::uno::RuntimeException);
+ static sal_Unicode getNextChar(const sal_Unicode *str, sal_Int32& idx, sal_Int32 len, MappingElement& e, css::lang::Locale& aLocale, MappingType nMappingtype, TransliterationModules moduleLoaded) throw (css::uno::RuntimeException);
};