21#include <com/sun/star/i18n/TextConversionType.hpp>
22#include <com/sun/star/i18n/TextConversionOption.hpp>
23#include <com/sun/star/lang/NoSupportException.hpp>
24#include <com/sun/star/linguistic2/ConversionDirection.hpp>
25#include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
26#include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
28#include <rtl/ustrbuf.hxx>
29#include <unicode/uchar.h>
40#define SCRIPT_OTHERS 0
42#define SCRIPT_HANGUL 2
48 "com.sun.star.i18n.ConversionDictionary_ko", xContext);
51 xCD.set( xI, UNO_QUERY );
53 xCDL = ConversionDictionaryList::create(xContext);
59 Locale loc(
"ko",
"KR", OUString());
61 ConversionDictionaryType::HANGUL_HANJA,
62 ConversionDirection_FROM_LEFT);
64 ConversionDictionaryType::HANGUL_HANJA,
65 ConversionDirection_FROM_RIGHT);
67 sal_Int32 tmp =
xCD->getMaxCharCount(ConversionDirection_FROM_LEFT);
70 tmp =
xCD->getMaxCharCount(ConversionDirection_FROM_RIGHT);
74 }
else if (
xCD.is()) {
82 struct UBlock2Script {
90 {UBLOCK_CJK_RADICALS_SUPPLEMENT, UBLOCK_BOPOMOFO,
SCRIPT_HANJA},
91 {UBLOCK_HANGUL_COMPATIBILITY_JAMO, UBLOCK_HANGUL_COMPATIBILITY_JAMO,
SCRIPT_HANGUL},
93 {UBLOCK_HANGUL_SYLLABLES, UBLOCK_HANGUL_SYLLABLES,
SCRIPT_HANGUL},
94 {UBLOCK_CJK_COMPATIBILITY_IDEOGRAPHS, UBLOCK_CJK_COMPATIBILITY_IDEOGRAPHS,
SCRIPT_HANJA},
95 {UBLOCK_COMBINING_HALF_MARKS, UBLOCK_SMALL_FORM_VARIANTS,
SCRIPT_HANJA},
96 {UBLOCK_HALFWIDTH_AND_FULLWIDTH_FORMS, UBLOCK_HALFWIDTH_AND_FULLWIDTH_FORMS,
SCRIPT_HANJA},
99 UBlockCode block=ublock_getCode(
static_cast<sal_uInt32
>(c));
107#ifdef DISABLE_DYNLOADING
111const Hangul_Index* getHangul2HanjaIndex();
112sal_Int16 getHangul2HanjaIndexCount();
113const sal_uInt16* getHanja2HangulIndex();
124#ifndef DISABLE_DYNLOADING
127 sal_Int16 (*getHangul2HanjaIndexCount)() =
reinterpret_cast<sal_Int16 (*)()
>(
getFunctionBySymbol(
"getHangul2HanjaIndexCount"));
128 const sal_uInt16* (*getHanja2HangulIndex)() =
reinterpret_cast<const sal_uInt16* (*)()
>(
getFunctionBySymbol(
"getHanja2HangulIndex"));
131 if (toHanja && getHangul2HanjaIndex && getHangul2HanjaIndexCount && getHangul2HanjaData)
136 ch = aText[nStartPos];
138 sal_Int16
top = getHangul2HanjaIndexCount();
147 else if (
ch > current_ch)
152 output.realloc(
count);
153 auto poutput = output.getArray();
154 for (sal_Int16
i = 0;
i <
count;
i++)
155 poutput[
i] = OUString(ptr +
i, 1);
160#ifndef DISABLE_DYNLOADING
161 else if (!toHanja && getHanja2HangulIndex && getHanja2HangulData)
172 if (address != 0xFFFF)
173 address = getHanja2HangulData()[address + (
ch & 0xFF)];
175 if (address != 0xFFFF)
176 newStr[
count++] = address;
182 output = { OUString(newStr.get(),
count) };
190 if (! rSeq1.hasElements() && rSeq2.hasElements())
192 else if (rSeq2.hasElements())
198TextConversionResult SAL_CALL
200 const Locale& aLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
202 TextConversionResult
result;
207 if (nConversionType != TextConversionType::TO_HANGUL &&
208 nConversionType != TextConversionType::TO_HANJA)
209 throw NoSupportException();
212 if (
length < 0 || nStartPos < 0)
219 bool toHanja = (nConversionType == TextConversionType::TO_HANJA);
222 ConversionDirection eDirection = toHanja ? ConversionDirection_FROM_LEFT : ConversionDirection_FROM_RIGHT;
224 if (maxLength == 0) maxLength = 1;
230 if (nConversionType == TextConversionType::TO_HANJA) {
239 if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER) {
246 for (len =
end -
start; len > 0; len--) {
250 result.Candidates =
xCDL->queryConversions(aText,
start + nStartPos, len,
251 aLocale, ConversionDictionaryType::HANGUL_HANJA, eDirection, nConversionOptions);
253 catch ( NoSupportException & ) {
263 if (
xCD.is() && toHanja) {
264 candidates =
xCD->getConversions(aText,
start + nStartPos, len, eDirection, nConversionOptions);
265 result.Candidates += candidates;
267 }
else if (! toHanja) {
269 if (
result.Candidates.hasElements())
270 len =
result.Candidates[0].getLength();
272 if (
result.Candidates.hasElements())
277 if (
result.Candidates.hasElements()) {
289 const Locale& aLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
291 sal_Int32
length = aText.getLength() - nStartPos;
293 if (
length <= 0 || nStartPos < 0)
299 TextConversionResult
result;
306 if (
result.Boundary.endPos > 0) {
316 return aBuf.makeStringAndClear();
321 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions,
Sequence<sal_Int32>& offset)
oslGenericFunction getFunctionBySymbol(const char *func)
OUString SAL_CALL getConversion(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions) override
css::uno::Sequence< OUString > getCharConversions(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toHanja)
css::i18n::TextConversionResult SAL_CALL getConversions(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions) override
OUString SAL_CALL getConversionWithOffset(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions, css::uno::Sequence< sal_Int32 > &offset) override
css::uno::Reference< css::linguistic2::XConversionDictionaryList > xCDL
css::uno::Reference< css::linguistic2::XConversionDictionary > xCD
TextConversion_ko(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
sal_Bool SAL_CALL interactiveConversion(const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions) override
const UBlockScript scriptList[]
#define SAL_N_ELEMENTS(arr)
css::uno::Sequence< T > combineSequences(css::uno::Sequence< T > const &left, css::uno::Sequence< T > const &right)
Constant values shared between i18npool and, for example, the number formatter.
static sal_Int16 checkScriptType(sal_Unicode c)
static Sequence< OUString > & operator+=(Sequence< OUString > &rSeq1, const Sequence< OUString > &rSeq2)