summaryrefslogtreecommitdiff
path: root/include/i18nutil
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 /include/i18nutil
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 'include/i18nutil')
-rw-r--r--include/i18nutil/casefolding.hxx5
-rw-r--r--include/i18nutil/searchopt.hxx142
-rw-r--r--include/i18nutil/transliteration.hxx132
3 files changed, 277 insertions, 2 deletions
diff --git a/include/i18nutil/casefolding.hxx b/include/i18nutil/casefolding.hxx
index 31a6d4ffe586..493875a340a4 100644
--- a/include/i18nutil/casefolding.hxx
+++ b/include/i18nutil/casefolding.hxx
@@ -20,12 +20,13 @@
#define INCLUDED_I18NUTIL_CASEFOLDING_HXX
#include <sal/types.h>
-#include <com/sun/star/i18n/TransliterationModules.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>
#include <i18nutil/i18nutildllapi.h>
#include <o3tl/typed_flags_set.hxx>
+enum class TransliterationFlags;
+
enum class MappingType {
NONE = 0x00,
LowerToUpper = 0x01, // Upper to Lower mapping
@@ -77,7 +78,7 @@ public:
/// @throws css::uno::RuntimeException
static Mapping& getConditionalValue(const sal_Unicode* str, sal_Int32 pos, sal_Int32 len, css::lang::Locale& aLocale, MappingType nMappingType);
/// @throws 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);
+ static sal_Unicode getNextChar(const sal_Unicode *str, sal_Int32& idx, sal_Int32 len, MappingElement& e, css::lang::Locale& aLocale, MappingType nMappingtype, TransliterationFlags moduleLoaded);
};
diff --git a/include/i18nutil/searchopt.hxx b/include/i18nutil/searchopt.hxx
new file mode 100644
index 000000000000..5fc8b1a9afdf
--- /dev/null
+++ b/include/i18nutil/searchopt.hxx
@@ -0,0 +1,142 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef INCLUDED_I18NUTIL_SEARCHOPT_HXX
+#define INCLUDED_I18NUTIL_SEARCHOPT_HXX
+
+#include <sal/types.h>
+#include "com/sun/star/lang/Locale.hpp"
+#include "com/sun/star/util/SearchAlgorithms.hpp"
+#include "com/sun/star/util/SearchOptions2.hpp"
+#include <i18nutil/i18nutildllapi.h>
+#include <i18nutil/transliteration.hxx>
+
+namespace i18nutil
+{
+
+/**
+ * This is a wrapper around com::sun::star::util::SearchOptions
+ * but using the more type-safe TransliterationFlags enum.
+ */
+struct I18NUTIL_DLLPUBLIC SAL_WARN_UNUSED SearchOptions {
+ css::util::SearchAlgorithms algorithmType;
+ sal_Int32 searchFlag;
+ OUString searchString;
+ OUString replaceString;
+ css::lang::Locale Locale;
+ sal_Int32 changedChars;
+ sal_Int32 deletedChars;
+ sal_Int32 insertedChars;
+ TransliterationFlags transliterateFlags;
+
+ SearchOptions& operator=(css::util::SearchOptions const & other)
+ {
+ algorithmType = other.algorithmType;
+ searchFlag = other.searchFlag;
+ searchString = other.searchString;
+ replaceString = other.replaceString;
+ Locale = other.Locale;
+ changedChars = other.changedChars;
+ deletedChars = other.deletedChars;
+ insertedChars = other.insertedChars;
+ transliterateFlags = (TransliterationFlags)other.transliterateFlags;
+ return *this;
+ }
+
+ SearchOptions()
+ : algorithmType(::css::util::SearchAlgorithms_ABSOLUTE)
+ , searchFlag(0)
+ , searchString()
+ , replaceString()
+ , Locale()
+ , changedChars(0)
+ , deletedChars(0)
+ , insertedChars(0)
+ , transliterateFlags(TransliterationFlags::NONE)
+ {
+ }
+
+ SearchOptions(const css::util::SearchAlgorithms& algorithmType_, const sal_Int32 searchFlag_,
+ const OUString& searchString_, const OUString& replaceString_,
+ const css::lang::Locale& Locale_,
+ const sal_Int32 changedChars_, const sal_Int32 deletedChars_, const sal_Int32 insertedChars_,
+ const TransliterationFlags& transliterateFlags_)
+ : algorithmType(algorithmType_)
+ , searchFlag(searchFlag_)
+ , searchString(searchString_)
+ , replaceString(replaceString_)
+ , Locale(Locale_)
+ , changedChars(changedChars_)
+ , deletedChars(deletedChars_)
+ , insertedChars(insertedChars_)
+ , transliterateFlags(transliterateFlags_)
+ {
+ }
+};
+
+/**
+ * This is a wrapper around com::sun::star::util::SearchOptions and SearchOptions2,
+ * but using the more type-safe TransliterationFlags enum.
+ */
+struct I18NUTIL_DLLPUBLIC SAL_WARN_UNUSED SearchOptions2 : public SearchOptions {
+
+ sal_Int16 AlgorithmType2;
+ sal_Int32 WildcardEscapeCharacter;
+
+ SearchOptions2& operator=(css::util::SearchOptions2 const & other)
+ {
+ SearchOptions::operator=(other);
+ AlgorithmType2 = other.AlgorithmType2;
+ WildcardEscapeCharacter = other.WildcardEscapeCharacter;
+ return *this;
+ }
+
+
+ css::util::SearchOptions2 toUnoSearchOptions2() const
+ {
+ return css::util::SearchOptions2(algorithmType, searchFlag,
+ searchString, replaceString,
+ Locale,
+ changedChars, deletedChars, insertedChars,
+ (sal_Int32)transliterateFlags,
+ AlgorithmType2, WildcardEscapeCharacter);
+ }
+
+ SearchOptions2()
+ : SearchOptions()
+ , AlgorithmType2(0)
+ , WildcardEscapeCharacter(0)
+ {}
+
+ SearchOptions2(const css::util::SearchAlgorithms& algorithmType_, const sal_Int32 searchFlag_,
+ const OUString& searchString_, const OUString& replaceString_,
+ const css::lang::Locale& Locale_,
+ const sal_Int32 changedChars_, const sal_Int32 deletedChars_, const sal_Int32 insertedChars_,
+ const TransliterationFlags& transliterateFlags_,
+ const sal_Int16 AlgorithmType2_, const sal_Int32 WildcardEscapeCharacter_)
+ : SearchOptions(algorithmType_, searchFlag_, searchString_, replaceString_, Locale_, changedChars_, deletedChars_, insertedChars_, transliterateFlags_)
+ , AlgorithmType2(AlgorithmType2_)
+ , WildcardEscapeCharacter(WildcardEscapeCharacter_)
+ {}
+};
+
+}; // namespace
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/i18nutil/transliteration.hxx b/include/i18nutil/transliteration.hxx
new file mode 100644
index 000000000000..b8cafa68f14f
--- /dev/null
+++ b/include/i18nutil/transliteration.hxx
@@ -0,0 +1,132 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef INCLUDED_I18NUTIL_TRANSLITERATION_HXX
+#define INCLUDED_I18NUTIL_TRANSLITERATION_HXX
+
+#include <sal/types.h>
+#include <com/sun/star/i18n/TransliterationModules.hpp>
+#include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
+#include <o3tl/typed_flags_set.hxx>
+
+/**
+ * This is a superset type of the com::sun::star::i18n::TransliterationModules and TransliterationModulesExtra,
+ * with some extra type checking
+ */
+enum class TransliterationFlags {
+ NONE = 0,
+ /// Transliterate a string from upper case to lower case
+ UPPERCASE_LOWERCASE = css::i18n::TransliterationModules_UPPERCASE_LOWERCASE,
+ /// Transliterate a string from lower case to upper case
+ LOWERCASE_UPPERCASE = css::i18n::TransliterationModules_LOWERCASE_UPPERCASE,
+ /// Transliterate a string from half width character to full width character
+ HALFWIDTH_FULLWIDTH = css::i18n::TransliterationModules_HALFWIDTH_FULLWIDTH,
+ /// Transliterate a string from full width character to half width character
+ FULLWIDTH_HALFWIDTH = css::i18n::TransliterationModules_FULLWIDTH_HALFWIDTH,
+ /// Transliterate a Japanese string from Katakana to Hiragana
+ KATAKANA_HIRAGANA = css::i18n::TransliterationModules_KATAKANA_HIRAGANA,
+ /// Transliterate a Japanese string from Hiragana to Katakana
+ HIRAGANA_KATAKANA = css::i18n::TransliterationModules_HIRAGANA_KATAKANA,
+ /// Transliterate an ASCII number string to Simplified Chinese lower case number string in spellout format
+ NumToTextLower_zh_CN = css::i18n::TransliterationModules_NumToTextLower_zh_CN,
+ /// Transliterate an ASCII number string to Simplified Chinese upper case number string in spellout format
+ NumToTextUpper_zh_CN = css::i18n::TransliterationModules_NumToTextUpper_zh_CN,
+ /// Transliterate an ASCII number string to Traditional Chinese lower case number string in spellout format
+ NumToTextLower_zh_TW = css::i18n::TransliterationModules_NumToTextLower_zh_TW,
+ /// Transliterate an ASCII number string to Traditional Chinese upper case number string in spellout format
+ NumToTextUpper_zh_TW = css::i18n::TransliterationModules_NumToTextUpper_zh_TW,
+ /// Transliterate an ASCII number string to formal Korean Hangul number string in spellout format
+ NumToTextFormalHangul_ko = css::i18n::TransliterationModules_NumToTextFormalHangul_ko,
+ /// Transliterate an ASCII number string to formal Korean Hanja lower case number string in spellout format
+ NumToTextFormalLower_ko = css::i18n::TransliterationModules_NumToTextFormalLower_ko,
+ /// Transliterate an ASCII number string to formal Korean Hanja upper case number string in spellout format
+ NumToTextFormalUpper_ko = css::i18n::TransliterationModules_NumToTextFormalUpper_ko,
+
+ /** The first character of the sentence is put in upper case
+ */
+ SENTENCE_CASE = css::i18n::TransliterationModulesExtra::SENTENCE_CASE,
+
+
+ /** The first character of the word is put in upper case.
+ * This one is part
+ */
+ TITLE_CASE = css::i18n::TransliterationModulesExtra::TITLE_CASE,
+
+
+ /** All characters of the word are to change their case from small letters
+ * to capital letters and vice versa.
+ */
+ TOGGLE_CASE = css::i18n::TransliterationModulesExtra::TOGGLE_CASE,
+
+ NON_IGNORE_MASK = css::i18n::TransliterationModules_NON_IGNORE_MASK,
+ IGNORE_MASK = 0x7fffff00,
+
+ /// Ignore case when comparing strings by transliteration service
+ IGNORE_CASE = css::i18n::TransliterationModules_IGNORE_CASE,
+ /// Ignore Hiragana and Katakana when comparing strings by transliteration service
+ IGNORE_KANA = css::i18n::TransliterationModules_IGNORE_KANA, // ja_JP
+ /// Ignore full width and half width character when comparing strings by transliteration service
+ IGNORE_WIDTH = css::i18n::TransliterationModules_IGNORE_WIDTH, // ja_JP
+ /// Ignore Japanese traditional Kanji character in Japanese fuzzy search
+ ignoreTraditionalKanji_ja_JP = css::i18n::TransliterationModules_ignoreTraditionalKanji_ja_JP,
+ /// Ignore Japanese traditional Katakana and Hiragana character in Japanese fuzzy search
+ ignoreTraditionalKana_ja_JP = css::i18n::TransliterationModules_ignoreTraditionalKana_ja_JP,
+ /// Ignore dash or minus sign in Japanese fuzzy search
+ ignoreMinusSign_ja_JP = css::i18n::TransliterationModules_ignoreMinusSign_ja_JP,
+ /// Ignore Hiragana and Katakana iteration mark in Japanese fuzzy search
+ ignoreIterationMark_ja_JP = css::i18n::TransliterationModules_ignoreIterationMark_ja_JP,
+ /// Ignore separator punctuations in Japanese fuzzy search
+ ignoreSeparator_ja_JP = css::i18n::TransliterationModules_ignoreSeparator_ja_JP,
+ /// Ignore Katakana and Hiragana Zi/Zi and Zu/Zu in Japanese fuzzy search
+ ignoreZiZu_ja_JP = css::i18n::TransliterationModules_ignoreZiZu_ja_JP,
+ /// Ignore Katakana and Hiragana Ba/Gua and Ha/Fa in Japanese fuzzy search
+ ignoreBaFa_ja_JP = css::i18n::TransliterationModules_ignoreBaFa_ja_JP,
+ /// Ignore Katakana and Hiragana Tsui/Tea/Ti and Dyi/Ji in Japanese fuzzy search
+ ignoreTiJi_ja_JP = css::i18n::TransliterationModules_ignoreTiJi_ja_JP,
+ /// Ignore Katakana and Hiragana Hyu/Fyu and Byu/Gyu in Japanese fuzzy search
+ ignoreHyuByu_ja_JP = css::i18n::TransliterationModules_ignoreHyuByu_ja_JP,
+ /// Ignore Katakana and Hiragana Se/Sye and Ze/Je in Japanese fuzzy search
+ ignoreSeZe_ja_JP = css::i18n::TransliterationModules_ignoreSeZe_ja_JP,
+ /// Ignore Katakana YA/A which follows the character in either I or E row in Japanese fuzzy search
+ ignoreIandEfollowedByYa_ja_JP = css::i18n::TransliterationModules_ignoreIandEfollowedByYa_ja_JP,
+ /// Ignore Katakana KI/KU which follows the character in SA column in Japanese fuzzy search
+ ignoreKiKuFollowedBySa_ja_JP = css::i18n::TransliterationModules_ignoreKiKuFollowedBySa_ja_JP,
+ /// Ignore Japanese normal and small sized character in Japanese fuzzy search
+ ignoreSize_ja_JP = css::i18n::TransliterationModules_ignoreSize_ja_JP,
+ /// Ignore Japanese prolonged sound mark in Japanese fuzzy search
+ ignoreProlongedSoundMark_ja_JP = css::i18n::TransliterationModules_ignoreProlongedSoundMark_ja_JP,
+ /// Ignore middle dot in Japanese fuzzy search
+ ignoreMiddleDot_ja_JP = css::i18n::TransliterationModules_ignoreMiddleDot_ja_JP,
+ /// Ignore white space characters, include space, TAB, return, etc. in Japanese fuzzy search
+ ignoreSpace_ja_JP = css::i18n::TransliterationModules_ignoreSpace_ja_JP,
+ /// transliterate Japanese small sized character to normal sized character
+ smallToLarge_ja_JP = css::i18n::TransliterationModules_smallToLarge_ja_JP,
+ /// transliterate Japanese normal sized character to small sized character
+ largeToSmall_ja_JP = css::i18n::TransliterationModules_largeToSmall_ja_JP,
+
+ IGNORE_DIACRITICS_CTL = css::i18n::TransliterationModulesExtra::IGNORE_DIACRITICS_CTL,
+ IGNORE_KASHIDA_CTL = css::i18n::TransliterationModulesExtra::IGNORE_KASHIDA_CTL
+};
+namespace o3tl {
+ template<> struct typed_flags<TransliterationFlags> : is_typed_flags<TransliterationFlags, 0x7fffffff> {};
+}
+
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */