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
41 #define SCRIPT_HANJA 1
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));
102 if (block <= scriptList[i].
to)
break;
104 return (i < SAL_N_ELEMENTS(scriptList) && block >= scriptList[i].from) ? scriptList[i].
script :
SCRIPT_OTHERS;
107 #ifdef DISABLE_DYNLOADING
111 const Hangul_Index* getHangul2HanjaIndex();
112 sal_Int16 getHangul2HanjaIndexCount();
113 const 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();
142 while (bottom <= top) {
143 sal_Int16 current = (top + bottom) / 2;
147 else if (ch > current_ch)
148 bottom = current + 1;
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)
166 std::unique_ptr<sal_Unicode[]> newStr(
new sal_Unicode[nLength+1]);
168 while (count < nLength)
170 ch = aText[nStartPos + count];
171 sal_Unicode address = getHanja2HangulIndex()[ch>>8];
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())
198 TextConversionResult SAL_CALL
200 const Locale& aLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
202 TextConversionResult
result;
204 result.Boundary.startPos = result.Boundary.endPos = 0;
207 if (nConversionType != TextConversionType::TO_HANGUL &&
208 nConversionType != TextConversionType::TO_HANJA)
209 throw NoSupportException();
212 if (length < 0 || nStartPos < 0)
214 else if (length > nLength)
219 bool toHanja = (nConversionType == TextConversionType::TO_HANJA);
222 ConversionDirection eDirection = toHanja ? ConversionDirection_FROM_LEFT : ConversionDirection_FROM_RIGHT;
224 if (maxLength == 0) maxLength = 1;
227 for (start = 0, end = 0; start < length; start++) {
230 if (nConversionType == TextConversionType::TO_HANJA) {
239 if (nConversionOptions & TextConversionOption::CHARACTER_BY_CHARACTER) {
242 for (; end < length && end - start < maxLength; end++)
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) {
268 result.Candidates =
getCharConversions(aText, nStartPos + start, length - start, toHanja);
269 if (result.Candidates.hasElements())
270 len = result.Candidates[0].getLength();
272 if (result.Candidates.hasElements())
277 if (result.Candidates.hasElements()) {
278 result.Boundary.startPos = start + nStartPos;
279 result.Boundary.endPos = start + len + nStartPos;
289 const Locale& aLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
291 sal_Int32
length = aText.getLength() - nStartPos;
293 if (length <= 0 || nStartPos < 0)
295 else if (length > nLength)
298 OUStringBuffer
aBuf(length + 1);
299 TextConversionResult
result;
302 for (sal_Int32
start = nStartPos; length + nStartPos >
start; start = result.Boundary.endPos) {
304 result =
getConversions(aText, start, length + nStartPos - start, aLocale, nConversionType, nConversionOptions);
306 if (result.Boundary.endPos > 0) {
307 if (result.Boundary.startPos > start)
308 aBuf.append(str + start, result.Boundary.startPos - start);
309 aBuf.append(result.Candidates[0]);
311 aBuf.append(str + start, length + nStartPos - start);
316 return aBuf.makeStringAndClear();
321 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions,
Sequence<sal_Int32>& offset)
324 return getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
exports com.sun.star. script
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
css::uno::Reference< css::linguistic2::XConversionDictionary > xCD
css::uno::Reference< css::linguistic2::XConversionDictionaryList > xCDL
static Sequence< OUString > & operator+=(Sequence< OUString > &rSeq1, const Sequence< OUString > &rSeq2)
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
#define SAL_N_ELEMENTS(arr)
css::uno::Sequence< T > combineSequences(css::uno::Sequence< T > const &left, css::uno::Sequence< T > const &right)
const UBlockScript scriptList[]
css::uno::Sequence< OUString > getCharConversions(const OUString &aText, sal_Int32 nStartPos, sal_Int32 nLength, bool toHanja)
Constant values shared between i18npool and, for example, the number formatter.
oslGenericFunction getFunctionBySymbol(const char *func)
enumrange< T >::Iterator end(enumrange< T >)
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
static sal_Int16 checkScriptType(sal_Unicode c)
sal_Bool SAL_CALL interactiveConversion(const css::lang::Locale &aLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions) override