20#include <rtl/textcvt.h>
25#define MAX_CVT_SELECT 6
30 explicit ConverterCache();
34 void ensureConverter(
int nSelect );
39ConverterCache::ConverterCache()
43 maConverterCache[
i] =
nullptr;
44 maContexts[
i] =
nullptr;
48ConverterCache::~ConverterCache()
54 rtl_destroyUnicodeToTextContext( maConverterCache[i], maContexts[i] );
55 rtl_destroyUnicodeToTextConverter( maConverterCache[i] );
59void ConverterCache::ensureConverter(
int nSelect )
62 rtl_UnicodeToTextContext aContext = maContexts[ nSelect ];
65 rtl_TextEncoding eRecodeFrom = RTL_TEXTENCODING_UNICODE;
68 default: nSelect = 1; [[fallthrough]];
69 case 1: eRecodeFrom = RTL_TEXTENCODING_UNICODE;
break;
70 case 2: eRecodeFrom = RTL_TEXTENCODING_SHIFT_JIS;
break;
71 case 3: eRecodeFrom = RTL_TEXTENCODING_GB_2312;
break;
72 case 4: eRecodeFrom = RTL_TEXTENCODING_BIG5;
break;
73 case 5: eRecodeFrom = RTL_TEXTENCODING_MS_949;
break;
74 case 6: eRecodeFrom = RTL_TEXTENCODING_MS_1361;
break;
76 rtl_UnicodeToTextConverter aRecodeConverter = rtl_createUnicodeToTextConverter( eRecodeFrom );
77 maConverterCache[ nSelect ] = aRecodeConverter;
79 aContext = rtl_createUnicodeToTextContext( aRecodeConverter );
80 maContexts[ nSelect ] = aContext;
83 rtl_resetUnicodeToTextContext( maConverterCache[ nSelect ], aContext );
86sal_uInt16 ConverterCache::convertOne(
int nSelect,
sal_Unicode aChar )
88 ensureConverter( nSelect );
96 int nCodeLen = rtl_convertUnicodeToText(
97 maConverterCache[ nSelect ], maContexts[ nSelect ],
98 &aUCS2Char, 1, aTempArray,
sizeof(aTempArray),
99 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_0
100 | RTL_UNICODETOTEXT_FLAGS_INVALID_0,
101 &nCvtInfo, &nTempSize );
103 sal_uInt16 aCode = aTempArray[0];
104 for(
int i = 1;
i < nCodeLen; ++
i )
105 aCode = (aCode << 8) + (aTempArray[
i] & 0xFF);
118 return aCC.convertOne( 2, src);
123 return aCC.convertOne( 3, src);
128 return aCC.convertOne( 4, src);
133 return aCC.convertOne( 5, src);
138 return aCC.convertOne( 6, src);
sal_uInt16 TranslateChar15(sal_uInt16 src)
static ConverterCache aCC
sal_uInt16 TranslateChar14(sal_uInt16 src)
sal_uInt16 TranslateChar12(sal_uInt16 src)
sal_uInt16 TranslateChar13(sal_uInt16 src)
sal_uInt16 TranslateChar16(sal_uInt16 src)