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 TmItem1 (IgnoreTraditionalKanji_ja_JP),
69 TmItem1 (IgnoreTraditionalKana_ja_JP),
70 TmItem1 (IgnoreMinusSign_ja_JP),
71 TmItem1 (IgnoreIterationMark_ja_JP),
72 TmItem1 (IgnoreSeparator_ja_JP),
74 TmItem1 (IgnoreMiddleDot_ja_JP),
81 TmItem1 (IgnoreIandEfollowedByYa_ja_JP),
82 TmItem1 (IgnoreKiKuFollowedBySa_ja_JP),
83 TmItem1 (IgnoreProlongedSoundMark_ja_JP),
101 TmItem2 (NumToTextInformalHangul_ko),
102 TmItem2 (NumToTextInformalLower_ko),
103 TmItem2 (NumToTextInformalUpper_ko),
104 TmItem2 (NumToCharLower_zh_CN),
105 TmItem2 (NumToCharUpper_zh_CN),
106 TmItem2 (NumToCharLower_zh_TW),
107 TmItem2 (NumToCharUpper_zh_TW),
112 TmItem2 (NumToCharKanjiShort_ja_JP),
113 TmItem2 (TextToNumLower_zh_CN),
114 TmItem2 (TextToNumUpper_zh_CN),
115 TmItem2 (TextToNumLower_zh_TW),
116 TmItem2 (TextToNumUpper_zh_TW),
117 TmItem2 (TextToNumFormalHangul_ko),
118 TmItem2 (TextToNumFormalLower_ko),
119 TmItem2 (TextToNumFormalUpper_ko),
120 TmItem2 (TextToNumInformalHangul_ko),
121 TmItem2 (TextToNumInformalLower_ko),
122 TmItem2 (TextToNumInformalUpper_ko),
124 TmItem2 (CharToNumLower_zh_CN),
125 TmItem2 (CharToNumUpper_zh_CN),
126 TmItem2 (CharToNumLower_zh_TW),
127 TmItem2 (CharToNumUpper_zh_TW),
137 {TransliterationModules(0), TransliterationModulesNew(0),
nullptr}
163 return ( OUString(
"Not Loaded"));
171 return (TransliterationType::CASCADE|TransliterationType::IGNORE);
177static TransliterationModules
operator&(TransliterationModules lhs, TransliterationModules rhs) {
178 return TransliterationModules(sal_Int32(lhs) & sal_Int32(rhs));
180static TransliterationModules
operator|(TransliterationModules lhs, TransliterationModules rhs) {
181 return TransliterationModules(sal_Int32(lhs) | sal_Int32(rhs));
188 if (
bool(modType & TransliterationModules_IGNORE_MASK) &&
189 bool(modType & TransliterationModules_NON_IGNORE_MASK))
192 }
else if (
bool(modType & TransliterationModules_IGNORE_MASK)) {
193#define TransliterationModules_IGNORE_CASE_MASK (TransliterationModules_IGNORE_CASE | \
194 TransliterationModules_IGNORE_WIDTH | \
195 TransliterationModules_IGNORE_KANA)
198 for (sal_Int16
i = 0; bool(
TMlist[
i].
tm & mask);
i++) {
205 if (
bool(modType & TransliterationModules(TransliterationModulesExtra::IGNORE_DIACRITICS_CTL)))
210 if (
bool(modType & TransliterationModules(TransliterationModulesExtra::IGNORE_KASHIDA_CTL)))
214 }
else if (
bool(modType & TransliterationModules_NON_IGNORE_MASK)) {
229 TransliterationModules mask = TransliterationModules_END_OF_MODULE;
230 sal_Int32
count = modType.getLength();
233 for (sal_Int32
i = 0;
i <
count;
i++) {
234 for (sal_Int16 j = 0; bool(
TMlist[j].
tmn); j++) {
236 if (mask == TransliterationModules_END_OF_MODULE)
237 mask = bool(
TMlist[
i].
tm) && bool(
TMlist[
i].
tm & TransliterationModules_IGNORE_MASK) ?
238 TransliterationModules_IGNORE_MASK : TransliterationModules_NON_IGNORE_MASK;
239 else if (mask == TransliterationModules_IGNORE_MASK &&
240 (
TMlist[
i].
tm&TransliterationModules_IGNORE_MASK) == TransliterationModules_END_OF_MODULE)
262 if (implNameList.getLength() >
maxCascade || implNameList.getLength() <= 0)
266 for (
const auto& rName : implNameList)
276 std::vector<OUString> r;
277 r.reserve(translist.getLength());
279 for (
const auto& rTrans : translist)
282 if (body->getType() &
sType)
300 if ( startPos == 0 &&
nCount == inStr.getLength() )
304 OUString tmpStr = inStr.copy(startPos,
nCount);
308 for (sal_Int32 & j : asNonConstRange(offset))
316 OUString tmpStr = inStr.copy(startPos,
nCount);
318 auto [
begin,
end] = asNonConstRange(offset);
326 nCount = tmpStr.getLength();
330 for (sal_Int32& ix : asNonConstRange(
to))
346 if (offset.getLength() !=
nCount)
350 if ( startPos == 0 &&
nCount == inStr.getLength() )
354 OUString tmpStr = inStr.copy(startPos,
nCount);
358 for (sal_Int32 & j : asNonConstRange(offset))
366 OUString tmpStr = inStr.copy(startPos,
nCount);
368 auto [
begin,
end] = asNonConstRange(offset);
377 nCount = tmpStr.getLength();
381 for (sal_Int32& ix : asNonConstRange(
to))
397 OUString tmpStr =
bodyCascade[0]->transliterateString2String(inStr, startPos,
nCount);
409 return OUString(&inChar, 1);
411 return bodyCascade[0]->transliterateChar2String( inChar);
413 OUString tmpStr =
bodyCascade[0]->transliterateChar2String(inChar);
433 const OUString& str1, sal_Int32 pos1, sal_Int32 nCount1, sal_Int32& nMatch1,
434 const OUString& str2, sal_Int32 pos2, sal_Int32 nCount2, sal_Int32& nMatch2)
445 if ( !nCount1 || !nCount2 ||
446 pos1 >= str1.getLength() || pos2 >= str2.getLength() ||
447 pos1 < 0 || pos2 < 0 ) {
448 nMatch1 = nMatch2 = 0;
450 return !nCount1 && !nCount2 && pos1 == str1.getLength() && pos2 == str2.getLength();
452 if ( pos1 + nCount1 > str1.getLength() )
453 nCount1 = str1.getLength() - pos1;
454 if ( pos2 + nCount2 > str2.getLength() )
455 nCount2 = str2.getLength() - pos2;
458 return caseignore->equals(str1, pos1, nCount1, nMatch1, str2, pos2, nCount2, nMatch2);
462 OUString tmpStr1 =
folding(str1, pos1, nCount1, offset1);
463 OUString tmpStr2 =
folding(str2, pos2, nCount2, offset2);
469 sal_Int32
i, nLen = ::std::min( tmpStr1.getLength(), tmpStr2.getLength());
470 for (
i = 0;
i < nLen; ++
i, ++p1, ++p2 ) {
473 nMatch1 = (
i < offset1.getLength()) ? offset1.getConstArray()[
i] :
i;
474 nMatch2 = (
i < offset2.getLength()) ? offset2.getConstArray()[
i] :
i;
479 if ( tmpStr1.getLength() != tmpStr2.getLength() ) {
481 nMatch1 = (
i <= offset1.getLength()) ? offset1.getConstArray()[
i-1] + 1 :
i;
482 nMatch2 = (
i <= offset2.getLength()) ? offset2.getConstArray()[
i-1] + 1 :
i;
493 const sal_Int32 length, sal_Int16 _numCascade)
499 constexpr sal_Int32 nMaxOutput = 2;
500 const sal_Int32 nMaxOutputLength = nMaxOutput*
length;
501 std::vector<OUString> ostr;
502 ostr.reserve(nMaxOutputLength);
503 for (sal_Int32 j = 0; j <
length; j+=2) {
506 for (
const auto& rStr : temp) {
508 ostr.push_back(rStr);
520 return bodyCascade[0]->transliterateRange(str1, str2);
530 const OUString& str1, sal_Int32 off1, sal_Int32 len1,
531 const OUString& str2, sal_Int32 off2, sal_Int32 len2)
534 return caseignore->compareSubstring(str1, off1, len1, str2, off2, len2);
542 sal_Int32 strlen1 = in_str1.getLength();
543 sal_Int32 strlen2 = in_str2.getLength();
545 while (strlen1 && strlen2) {
546 if (*unistr1 != *unistr2)
547 return *unistr1 > *unistr2 ? 1 : -1;
549 unistr1++; unistr2++; strlen1--; strlen2--;
551 return strlen1 == strlen2 ? 0 : (strlen1 > strlen2 ? 1 : -1);
561 return compareSubstring(str1, 0, str1.getLength(), str2, 0, str2.getLength());
582 css::uno::Reference< css::i18n::XExtendedTransliteration >
Body;
589 static std::mutex transBodyMutex;
590 std::unique_lock guard(transBodyMutex);
591 static TransBody lastTransBody;
594 lastTransBody.Body.set(
598 body = lastTransBody.Body;
608 body->loadModule(TransliterationModules(0), rLocale);
611 for (sal_Int16
i = 0;
i < 3;
i++) {
614 body->loadModule(
TMlist[0].
tm, rLocale);
633 return "com.sun.star.i18n.Transliteration";
645 return {
"com.sun.star.i18n.Transliteration" };
650extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
652 css::uno::XComponentContext *context,
653 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)
bool equalsAscii(std::u16string_view s1, const char *s2)
enumrange< T >::Iterator begin(enumrange< T >)
#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