24#include <com/sun/star/i18n/LocaleData2.hpp>
25#include <com/sun/star/i18n/TransliterationType.hpp>
26#include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
31#include <rtl/ustring.hxx>
44#define TmItem1( name ) \
45 {TransliterationModules_##name, TransliterationModulesNew_##name, #name}
47#define TmItem2( name ) \
48 {TransliterationModules(0), TransliterationModulesNew_##name, #name}
54 TransliterationModules
tm;
55 TransliterationModulesNew
tmn;
68 {TransliterationModules_IgnoreTraditionalKanji_ja_JP,
69 TransliterationModulesNew_IgnoreTraditionalKanji_ja_JP,
"ignoreTraditionalKanji_ja_JP"},
71 {TransliterationModules_IgnoreTraditionalKana_ja_JP,
72 TransliterationModulesNew_IgnoreTraditionalKana_ja_JP,
"ignoreTraditionalKana_ja_JP"},
74 {TransliterationModules_IgnoreMinusSign_ja_JP, TransliterationModulesNew_IgnoreMinusSign_ja_JP,
75 "ignoreMinusSign_ja_JP"},
76 {TransliterationModules_IgnoreIterationMark_ja_JP,
77 TransliterationModulesNew_IgnoreIterationMark_ja_JP,
"ignoreIterationMark_ja_JP"},
79 {TransliterationModules_IgnoreSeparator_ja_JP, TransliterationModulesNew_IgnoreSeparator_ja_JP,
80 "ignoreSeparator_ja_JP"},
81 {TransliterationModules_IgnoreSize_ja_JP, TransliterationModulesNew_IgnoreSize_ja_JP,
83 {TransliterationModules_IgnoreMiddleDot_ja_JP, TransliterationModulesNew_IgnoreMiddleDot_ja_JP,
84 "ignoreMiddleDot_ja_JP"},
85 {TransliterationModules_IgnoreSpace_ja_JP, TransliterationModulesNew_IgnoreSpace_ja_JP,
87 {TransliterationModules_IgnoreZiZu_ja_JP, TransliterationModulesNew_IgnoreZiZu_ja_JP,
89 {TransliterationModules_IgnoreBaFa_ja_JP, TransliterationModulesNew_IgnoreBaFa_ja_JP,
91 {TransliterationModules_IgnoreTiJi_ja_JP, TransliterationModulesNew_IgnoreTiJi_ja_JP,
93 {TransliterationModules_IgnoreHyuByu_ja_JP, TransliterationModulesNew_IgnoreHyuByu_ja_JP,
94 "ignoreHyuByu_ja_JP"},
95 {TransliterationModules_IgnoreSeZe_ja_JP, TransliterationModulesNew_IgnoreSeZe_ja_JP,
97 {TransliterationModules_IgnoreIandEfollowedByYa_ja_JP,
98 TransliterationModulesNew_IgnoreIandEfollowedByYa_ja_JP,
"ignoreIandEfollowedByYa_ja_JP"},
100 {TransliterationModules_IgnoreKiKuFollowedBySa_ja_JP,
101 TransliterationModulesNew_IgnoreKiKuFollowedBySa_ja_JP,
"ignoreKiKuFollowedBySa_ja_JP"},
103 {TransliterationModules_IgnoreProlongedSoundMark_ja_JP,
104 TransliterationModulesNew_IgnoreProlongedSoundMark_ja_JP,
"ignoreProlongedSoundMark_ja_JP"},
114 {TransliterationModules_SmallToLarge_ja_JP, TransliterationModulesNew_SmallToLarge_ja_JP,
115 "smallToLarge_ja_JP"},
116 {TransliterationModules_LargeToSmall_ja_JP, TransliterationModulesNew_LargeToSmall_ja_JP,
117 "largeToSmall_ja_JP"},
125 TmItem2 (NumToTextInformalHangul_ko),
126 TmItem2 (NumToTextInformalLower_ko),
127 TmItem2 (NumToTextInformalUpper_ko),
128 TmItem2 (NumToCharLower_zh_CN),
129 TmItem2 (NumToCharUpper_zh_CN),
130 TmItem2 (NumToCharLower_zh_TW),
131 TmItem2 (NumToCharUpper_zh_TW),
136 TmItem2 (NumToCharKanjiShort_ja_JP),
137 TmItem2 (TextToNumLower_zh_CN),
138 TmItem2 (TextToNumUpper_zh_CN),
139 TmItem2 (TextToNumLower_zh_TW),
140 TmItem2 (TextToNumUpper_zh_TW),
141 TmItem2 (TextToNumFormalHangul_ko),
142 TmItem2 (TextToNumFormalLower_ko),
143 TmItem2 (TextToNumFormalUpper_ko),
144 TmItem2 (TextToNumInformalHangul_ko),
145 TmItem2 (TextToNumInformalLower_ko),
146 TmItem2 (TextToNumInformalUpper_ko),
148 TmItem2 (CharToNumLower_zh_CN),
149 TmItem2 (CharToNumUpper_zh_CN),
150 TmItem2 (CharToNumLower_zh_TW),
151 TmItem2 (CharToNumUpper_zh_TW),
161 {TransliterationModules(0), TransliterationModulesNew(0),
nullptr}
187 return ( OUString(
"Not Loaded"));
195 return (TransliterationType::CASCADE|TransliterationType::IGNORE);
201static TransliterationModules
operator&(TransliterationModules lhs, TransliterationModules rhs) {
202 return TransliterationModules(sal_Int32(lhs) & sal_Int32(rhs));
204static TransliterationModules
operator|(TransliterationModules lhs, TransliterationModules rhs) {
205 return TransliterationModules(sal_Int32(lhs) | sal_Int32(rhs));
212 if (
bool(modType & TransliterationModules_IGNORE_MASK) &&
213 bool(modType & TransliterationModules_NON_IGNORE_MASK))
216 }
else if (
bool(modType & TransliterationModules_IGNORE_MASK)) {
217#define TransliterationModules_IGNORE_CASE_MASK (TransliterationModules_IGNORE_CASE | \
218 TransliterationModules_IGNORE_WIDTH | \
219 TransliterationModules_IGNORE_KANA)
222 for (sal_Int16
i = 0; bool(
TMlist[
i].
tm & mask);
i++) {
229 if (
bool(modType & TransliterationModules(TransliterationModulesExtra::IGNORE_DIACRITICS_CTL)))
234 if (
bool(modType & TransliterationModules(TransliterationModulesExtra::IGNORE_KASHIDA_CTL)))
238 }
else if (
bool(modType & TransliterationModules_NON_IGNORE_MASK)) {
253 TransliterationModules mask = TransliterationModules_END_OF_MODULE;
254 sal_Int32
count = modType.getLength();
257 for (sal_Int32
i = 0;
i <
count;
i++) {
258 for (sal_Int16 j = 0; bool(
TMlist[j].
tmn); j++) {
260 if (mask == TransliterationModules_END_OF_MODULE)
261 mask = bool(
TMlist[
i].
tm) && bool(
TMlist[
i].
tm & TransliterationModules_IGNORE_MASK) ?
262 TransliterationModules_IGNORE_MASK : TransliterationModules_NON_IGNORE_MASK;
263 else if (mask == TransliterationModules_IGNORE_MASK &&
264 (
TMlist[
i].
tm&TransliterationModules_IGNORE_MASK) == TransliterationModules_END_OF_MODULE)
286 if (implNameList.getLength() >
maxCascade || implNameList.getLength() <= 0)
290 for (
const auto& rName : implNameList)
300 std::vector<OUString> r;
301 r.reserve(translist.getLength());
303 for (
const auto& rTrans : translist)
306 if (body->getType() &
sType)
324 if ( startPos == 0 &&
nCount == inStr.getLength() )
328 OUString tmpStr = inStr.copy(startPos,
nCount);
332 for (sal_Int32 & j : asNonConstRange(offset))
340 OUString tmpStr = inStr.copy(startPos,
nCount);
342 auto [
begin,
end] = asNonConstRange(offset);
350 nCount = tmpStr.getLength();
354 for (sal_Int32& ix : asNonConstRange(
to))
370 if (offset.getLength() !=
nCount)
374 if ( startPos == 0 &&
nCount == inStr.getLength() )
378 OUString tmpStr = inStr.copy(startPos,
nCount);
382 for (sal_Int32 & j : asNonConstRange(offset))
390 OUString tmpStr = inStr.copy(startPos,
nCount);
392 auto [
begin,
end] = asNonConstRange(offset);
401 nCount = tmpStr.getLength();
405 for (sal_Int32& ix : asNonConstRange(
to))
421 OUString tmpStr =
bodyCascade[0]->transliterateString2String(inStr, startPos,
nCount);
433 return OUString(&inChar, 1);
435 return bodyCascade[0]->transliterateChar2String( inChar);
437 OUString tmpStr =
bodyCascade[0]->transliterateChar2String(inChar);
457 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
458 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
469 if ( !nCount1 || !nCount2 ||
470 pos1 >= str1.getLength() || pos2 >= str2.getLength() ||
471 pos1 < 0 || pos2 < 0 ) {
472 nMatch1 = nMatch2 = 0;
474 return !nCount1 && !nCount2 && pos1 == str1.getLength() && pos2 == str2.getLength();
476 if ( pos1 + nCount1 > str1.getLength() )
477 nCount1 = str1.getLength() - pos1;
478 if ( pos2 + nCount2 > str2.getLength() )
479 nCount2 = str2.getLength() - pos2;
482 return caseignore->equals(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2);
486 OUString tmpStr1 =
folding(str1, pos1, nCount1, offset1);
487 OUString tmpStr2 =
folding(str2, pos2, nCount2, offset2);
493 sal_Int32
i, nLen = ::std::min( tmpStr1.getLength(), tmpStr2.getLength());
494 for (
i = 0;
i < nLen; ++
i, ++p1, ++p2 ) {
497 nMatch1 = (
i < offset1.getLength()) ? offset1.getConstArray()[
i] :
i;
498 nMatch2 = (
i < offset2.getLength()) ? offset2.getConstArray()[
i] :
i;
503 if ( tmpStr1.getLength() != tmpStr2.getLength() ) {
505 nMatch1 = (
i <= offset1.getLength()) ? offset1.getConstArray()[
i-1] + 1 :
i;
506 nMatch2 = (
i <= offset2.getLength()) ? offset2.getConstArray()[
i-1] + 1 :
i;
517 const sal_Int32 length, sal_Int16 _numCascade)
523 constexpr sal_Int32 nMaxOutput = 2;
524 const sal_Int32 nMaxOutputLength = nMaxOutput*
length;
525 std::vector<OUString> ostr;
526 ostr.reserve(nMaxOutputLength);
527 for (sal_Int32 j = 0; j <
length; j+=2) {
530 for (
const auto& rStr : temp) {
532 ostr.push_back(rStr);
544 return bodyCascade[0]->transliterateRange(str1, str2);
554 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
555 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
558 return caseignore->compareSubstring(str1, off1, len1, str2, off2, len2);
566 sal_Int32 strlen1 = in_str1.getLength();
567 sal_Int32 strlen2 = in_str2.getLength();
569 while (strlen1 && strlen2) {
570 if (*unistr1 != *unistr2)
571 return *unistr1 > *unistr2 ? 1 : -1;
573 unistr1++; unistr2++; strlen1--; strlen2--;
575 return strlen1 == strlen2 ? 0 : (strlen1 > strlen2 ? 1 : -1);
585 return compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength());
606 css::uno::Reference< css::i18n::XExtendedTransliteration >
Body;
613 static std::mutex transBodyMutex;
614 std::unique_lock guard(transBodyMutex);
615 static TransBody lastTransBody;
618 lastTransBody.Body.set(
622 body = lastTransBody.Body;
632 body->loadModule(TransliterationModules(0), rLocale);
635 for (sal_Int16
i = 0;
i < 3;
i++) {
638 body->loadModule(
TMlist[0].
tm, rLocale);
657 return "com.sun.star.i18n.Transliteration";
669 return {
"com.sun.star.i18n.Transliteration" };
674extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
676 css::uno::XComponentContext *context,
677 css::uno::Sequence<css::uno::Any>
const &)
css::uno::Reference< css::i18n::XExtendedTransliteration > caseignore
virtual OUString SAL_CALL folding(const OUString &inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 > &offset) override
virtual void SAL_CALL loadModuleNew(const css::uno::Sequence< css::i18n::TransliterationModulesNew > &modName, const css::lang::Locale &rLocale) override
virtual void SAL_CALL loadModulesByImplNames(const css::uno::Sequence< OUString > &modNamelist, const css::lang::Locale &rLocale) override
virtual sal_Int32 SAL_CALL compareString(const OUString &s1, const OUString &s2) override
virtual OUString SAL_CALL transliterateString2String(const OUString &inStr, sal_Int32 startPos, sal_Int32 nCount) override
virtual css::uno::Sequence< OUString > SAL_CALL transliterateRange(const OUString &str1, const OUString &str2) override
virtual OUString SAL_CALL transliterateChar2String(sal_Unicode inChar) override
virtual sal_Int32 SAL_CALL compareSubstring(const OUString &s1, sal_Int32 off1, sal_Int32 len1, const OUString &s2, sal_Int32 off2, sal_Int32 len2) override
virtual sal_Unicode SAL_CALL transliterateChar2Char(sal_Unicode inChar) override
virtual OUString SAL_CALL getName() override
css::uno::Sequence< OUString > getRange(const css::uno::Sequence< OUString > &inStrs, sal_Int32 length, const sal_Int16 _nCascade)
virtual OUString SAL_CALL transliterate(const OUString &inStr, sal_Int32 startPos, sal_Int32 nCount, css::uno::Sequence< sal_Int32 > &offset) override
virtual void SAL_CALL loadModule(css::i18n::TransliterationModules modName, const css::lang::Locale &rLocale) override
virtual ~TransliterationImpl() override
virtual void SAL_CALL loadModuleByImplName(const OUString &implName, const css::lang::Locale &rLocale) override
virtual sal_Bool SAL_CALL equals(const OUString &str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32 &nMatch1, const OUString &str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32 &nMatch2) override
virtual sal_Int16 SAL_CALL getType() override
TransliterationImpl(const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual css::uno::Sequence< OUString > SAL_CALL getAvailableModules(const css::lang::Locale &rLocale, sal_Int16 sType) override
void loadBody(OUString const &implName, css::uno::Reference< css::i18n::XExtendedTransliteration > &body)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::uno::XComponentContext > mxContext
bool loadModuleByName(std::u16string_view implName, css::uno::Reference< css::i18n::XExtendedTransliteration > &body, const css::lang::Locale &rLocale)
css::uno::Reference< css::i18n::XLocaleData5 > mxLocaledata
css::uno::Reference< css::i18n::XExtendedTransliteration > bodyCascade[maxCascade]
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Constant values shared between i18npool and, for example, the number formatter.
static TransliterationModules operator&(TransliterationModules lhs, TransliterationModules rhs)
static TransliterationModules operator|(TransliterationModules lhs, TransliterationModules rhs)
enumrange< T >::Iterator begin(enumrange< T >)
bool equalsAscii(std::u16string_view s1, std::string_view s2)
#define TRLT_IMPLNAME_PREFIX
TransliterationModulesNew tmn
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_i18n_Transliteration_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
TransliterationModules tm
#define TransliterationModules_IGNORE_CASE_MASK
@ NumToTextFormalUpper_ko
@ NumToTextFormalHangul_ko
@ NumToTextFormalLower_ko