tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / sal / textenc / tcvtmb.cxx
blob89e89c56c6284b0e92372e10c333b72cd74c10d8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <rtl/textcvt.h>
24 #include "handleundefinedunicodetotextchar.hxx"
25 #include "tenchelp.hxx"
26 #include "unichars.hxx"
28 /* DBCS to Unicode conversion routine use a lead table for the first byte, */
29 /* where we determine the trail table or for single byte chars the unicode */
30 /* value. We have for all lead byte a separate table, because we can */
31 /* then share many tables for different charset encodings. */
33 sal_Size ImplDBCSToUnicode( const void* pData, SAL_UNUSED_PARAMETER void*,
34 const char* pSrcBuf, sal_Size nSrcBytes,
35 sal_Unicode* pDestBuf, sal_Size nDestChars,
36 sal_uInt32 nFlags, sal_uInt32* pInfo,
37 sal_Size* pSrcCvtBytes )
39 unsigned char cTrail;
40 sal_Unicode cConv;
41 const ImplDBCSToUniLeadTab* pLeadEntry;
42 const ImplDBCSConvertData* pConvertData = static_cast<const ImplDBCSConvertData*>(pData);
43 const ImplDBCSToUniLeadTab* pLeadTab = pConvertData->mpToUniLeadTab;
44 sal_Unicode* pEndDestBuf;
45 const char* pEndSrcBuf;
46 char const * startOfCurrentChar = pSrcBuf;
48 *pInfo = 0;
49 pEndDestBuf = pDestBuf+nDestChars;
50 pEndSrcBuf = pSrcBuf+nSrcBytes;
51 while ( pSrcBuf < pEndSrcBuf )
53 unsigned char cLead = static_cast<unsigned char>(*pSrcBuf);
55 /* get entry for the lead byte */
56 pLeadEntry = pLeadTab+cLead;
58 /* SingleByte char? */
59 if (pLeadEntry->mpToUniTrailTab == nullptr
60 || cLead < pConvertData->mnLeadStart
61 || cLead > pConvertData->mnLeadEnd)
63 cConv = pLeadEntry->mnUniChar;
64 if ( !cConv && (cLead != 0) )
66 *pInfo |= RTL_TEXTTOUNICODE_INFO_UNDEFINED;
67 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR )
69 if ((nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0) {
70 ++pSrcBuf;
71 } else {
72 pSrcBuf = startOfCurrentChar;
74 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
75 break;
77 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE )
79 pSrcBuf++;
80 startOfCurrentChar = pSrcBuf;
81 continue;
83 cConv = ImplGetUndefinedUnicodeChar(cLead, nFlags);
86 else
88 /* Source buffer too small */
89 if ( pSrcBuf +1 == pEndSrcBuf )
91 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0 )
93 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL;
94 break;
96 cConv = 0;
98 else
100 pSrcBuf++;
101 cTrail = static_cast<unsigned char>(*pSrcBuf);
102 if ( (cTrail >= pLeadEntry->mnTrailStart) && (cTrail <= pLeadEntry->mnTrailEnd) )
103 cConv = pLeadEntry->mpToUniTrailTab[cTrail-pLeadEntry->mnTrailStart];
104 else
105 cConv = 0;
107 if ( !cConv )
109 /* EUDC Ranges */
110 sal_uInt16 i;
111 const ImplDBCSEUDCData* pEUDCTab = pConvertData->mpEUDCTab;
112 for ( i = 0; i < pConvertData->mnEUDCCount; i++ )
114 if ( (cLead >= pEUDCTab->mnLeadStart) &&
115 (cLead <= pEUDCTab->mnLeadEnd) )
117 if ( (cTrail >= pEUDCTab->mnTrail1Start) &&
118 (cTrail <= pEUDCTab->mnTrail1End) )
120 cConv = pEUDCTab->mnUniStart+
121 ((cLead-pEUDCTab->mnLeadStart)*pEUDCTab->mnTrailRangeCount)+
122 (cTrail-pEUDCTab->mnTrail1Start);
123 break;
125 sal_uInt16 nTrailCount = pEUDCTab->mnTrail1End-pEUDCTab->mnTrail1Start+1;
126 if ( (pEUDCTab->mnTrailCount >= 2) &&
127 (cTrail >= pEUDCTab->mnTrail2Start) &&
128 (cTrail <= pEUDCTab->mnTrail2End) )
130 cConv = pEUDCTab->mnUniStart+
131 ((cLead-pEUDCTab->mnLeadStart)*pEUDCTab->mnTrailRangeCount)+
132 nTrailCount+
133 (cTrail-pEUDCTab->mnTrail2Start);
134 break;
136 nTrailCount = pEUDCTab->mnTrail2End-pEUDCTab->mnTrail2Start+1;
137 if ( (pEUDCTab->mnTrailCount >= 3) &&
138 (cTrail >= pEUDCTab->mnTrail3Start) &&
139 (cTrail <= pEUDCTab->mnTrail3End) )
141 cConv = pEUDCTab->mnUniStart+
142 ((cLead-pEUDCTab->mnLeadStart)*pEUDCTab->mnTrailRangeCount)+
143 nTrailCount+
144 (cTrail-pEUDCTab->mnTrail3Start);
145 break;
149 pEUDCTab++;
152 if ( !cConv )
154 /* We compare the full range of the trail we defined, */
155 /* which can often be greater than the limit. We do this */
156 /* so that extensions that don't consider encodings */
157 /* correctly treat double-byte characters as a single */
158 /* character as much as possible. */
160 if (cLead < pConvertData->mnLeadStart
161 || cLead > pConvertData->mnLeadEnd
162 || cTrail < pConvertData->mnTrailStart
163 || cTrail > pConvertData->mnTrailEnd)
165 *pInfo |= RTL_TEXTTOUNICODE_INFO_INVALID;
166 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR )
168 if ((nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0) {
169 ++pSrcBuf;
170 } else {
171 pSrcBuf = startOfCurrentChar;
173 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
174 break;
176 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE )
178 pSrcBuf++;
179 startOfCurrentChar = pSrcBuf;
180 continue;
182 cConv = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
187 if ( !cConv )
189 *pInfo |= RTL_TEXTTOUNICODE_INFO_MBUNDEFINED;
190 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR )
192 if ((nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0) {
193 ++pSrcBuf;
194 } else {
195 pSrcBuf = startOfCurrentChar;
197 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
198 break;
200 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE )
202 pSrcBuf++;
203 startOfCurrentChar = pSrcBuf;
204 continue;
206 cConv = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
210 if ( pDestBuf == pEndDestBuf )
212 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOOSMALL;
213 break;
216 *pDestBuf = cConv;
217 pDestBuf++;
218 pSrcBuf++;
219 startOfCurrentChar = pSrcBuf;
222 *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
223 return (nDestChars - (pEndDestBuf-pDestBuf));
226 sal_Size ImplUnicodeToDBCS( const void* pData, SAL_UNUSED_PARAMETER void*,
227 const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
228 char* pDestBuf, sal_Size nDestBytes,
229 sal_uInt32 nFlags, sal_uInt32* pInfo,
230 sal_Size* pSrcCvtChars )
232 sal_uInt16 cConv;
233 sal_Unicode c;
234 const ImplUniToDBCSHighTab* pHighEntry;
235 const ImplDBCSConvertData* pConvertData = static_cast<const ImplDBCSConvertData*>(pData);
236 const ImplUniToDBCSHighTab* pHighTab = pConvertData->mpToDBCSHighTab;
237 char* pEndDestBuf;
238 const sal_Unicode* pEndSrcBuf;
240 bool bCheckRange =
241 pConvertData->mnLeadStart != 0 || pConvertData->mnLeadEnd != 0xFF;
242 /* this statement has the effect that this extra check is only done for
243 EUC-KR, which uses the MS-949 tables, but does not support the full
244 range of MS-949 */
246 *pInfo = 0;
247 pEndDestBuf = pDestBuf+nDestBytes;
248 pEndSrcBuf = pSrcBuf+nSrcChars;
249 while ( pSrcBuf < pEndSrcBuf )
251 c = *pSrcBuf;
252 unsigned char nHighChar = static_cast<unsigned char>((c >> 8) & 0xFF);
253 unsigned char nLowChar = static_cast<unsigned char>(c & 0xFF);
255 /* get entry for the high byte */
256 pHighEntry = pHighTab+nHighChar;
258 /* is low byte in the table range */
259 if ( (nLowChar >= pHighEntry->mnLowStart) && (nLowChar <= pHighEntry->mnLowEnd) )
261 cConv = pHighEntry->mpToUniTrailTab[nLowChar-pHighEntry->mnLowStart];
262 if (bCheckRange && cConv > 0x7F
263 && ((cConv >> 8) < pConvertData->mnLeadStart
264 || (cConv >> 8) > pConvertData->mnLeadEnd
265 || (cConv & 0xFF) < pConvertData->mnTrailStart
266 || (cConv & 0xFF) > pConvertData->mnTrailEnd))
267 cConv = 0;
269 else
270 cConv = 0;
272 if (cConv == 0 && c != 0)
274 /* Map to EUDC ranges: */
275 ImplDBCSEUDCData const * pEUDCTab = pConvertData->mpEUDCTab;
276 sal_uInt32 i;
277 for (i = 0; i < pConvertData->mnEUDCCount; ++i)
279 if (c >= pEUDCTab->mnUniStart && c <= pEUDCTab->mnUniEnd)
281 sal_uInt32 nIndex = c - pEUDCTab->mnUniStart;
282 sal_uInt32 nLeadOff
283 = nIndex / pEUDCTab->mnTrailRangeCount;
284 sal_uInt32 nTrailOff
285 = nIndex % pEUDCTab->mnTrailRangeCount;
286 sal_uInt32 nSize;
287 cConv = static_cast<sal_uInt16>((pEUDCTab->mnLeadStart + nLeadOff) << 8);
288 nSize
289 = pEUDCTab->mnTrail1End - pEUDCTab->mnTrail1Start + 1;
290 if (nTrailOff < nSize)
292 cConv |= pEUDCTab->mnTrail1Start + nTrailOff;
293 break;
295 nTrailOff -= nSize;
296 nSize
297 = pEUDCTab->mnTrail2End - pEUDCTab->mnTrail2Start + 1;
298 if (nTrailOff < nSize)
300 cConv |= pEUDCTab->mnTrail2Start + nTrailOff;
301 break;
303 nTrailOff -= nSize;
304 cConv |= pEUDCTab->mnTrail3Start + nTrailOff;
305 break;
307 pEUDCTab++;
310 /* FIXME
311 * SB: Not sure why this is in here. Plus, it does not work as
312 * intended when (c & 0xFF) == 0, because the next !cConv check
313 * will then think c has not yet been converted...
315 if (c >= RTL_TEXTCVT_BYTE_PRIVATE_START
316 && c <= RTL_TEXTCVT_BYTE_PRIVATE_END)
318 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 )
319 cConv = static_cast< char >(static_cast< unsigned char >(c & 0xFF));
323 if (cConv == 0 && c != 0)
325 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE )
327 /* !!! */
330 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR )
332 /* !!! */
335 /* Handle undefined and surrogates characters */
336 /* (all surrogates characters are undefined) */
337 if (sal::detail::textenc::handleUndefinedUnicodeToTextChar(
338 &pSrcBuf, pEndSrcBuf, &pDestBuf, pEndDestBuf, nFlags,
339 pInfo))
340 continue;
341 break;
344 /* SingleByte */
345 if ( !(cConv & 0xFF00) )
347 if ( pDestBuf == pEndDestBuf )
349 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
350 break;
353 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
354 pDestBuf++;
356 else
358 if ( pDestBuf+1 >= pEndDestBuf )
360 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
361 break;
364 *pDestBuf = static_cast< char >(static_cast< unsigned char >((cConv >> 8) & 0xFF));
365 pDestBuf++;
366 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
367 pDestBuf++;
370 pSrcBuf++;
373 *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
374 return (nDestBytes - (pEndDestBuf-pDestBuf));
377 #define JIS_EUC_LEAD_OFF 0x80
378 #define JIS_EUC_TRAIL_OFF 0x80
380 sal_Size ImplEUCJPToUnicode( const void* pData,
381 SAL_UNUSED_PARAMETER void*,
382 const char* pSrcBuf, sal_Size nSrcBytes,
383 sal_Unicode* pDestBuf, sal_Size nDestChars,
384 sal_uInt32 nFlags, sal_uInt32* pInfo,
385 sal_Size* pSrcCvtBytes )
387 unsigned char cLead = '\0';
388 unsigned char cTrail = '\0';
389 sal_Unicode cConv;
390 const ImplDBCSToUniLeadTab* pLeadEntry;
391 const ImplDBCSToUniLeadTab* pLeadTab;
392 const ImplEUCJPConvertData* pConvertData = static_cast<const ImplEUCJPConvertData*>(pData);
393 sal_Unicode* pEndDestBuf;
394 const char* pEndSrcBuf;
395 char const * startOfCurrentChar = pSrcBuf;
397 *pInfo = 0;
398 pEndDestBuf = pDestBuf+nDestChars;
399 pEndSrcBuf = pSrcBuf+nSrcBytes;
400 while ( pSrcBuf < pEndSrcBuf )
402 unsigned char c = static_cast<unsigned char>(*pSrcBuf);
404 /* ASCII */
405 if ( c <= 0x7F )
406 cConv = c;
407 else
409 /* SS2 - Half-width katakana */
410 /* 8E + A1-DF */
411 if ( c == 0x8E )
413 /* Source buffer too small */
414 if ( pSrcBuf + 1 == pEndSrcBuf )
416 *pInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL;
417 break;
420 pSrcBuf++;
421 c = static_cast<unsigned char>(*pSrcBuf);
422 if ( (c >= 0xA1) && (c <= 0xDF) )
423 cConv = 0xFF61+(c-0xA1);
424 else
426 cConv = 0;
427 cLead = 0x8E;
428 cTrail = c;
431 else
433 /* SS3 - JIS 0212-1990 */
434 /* 8F + A1-FE + A1-FE */
435 if ( c == 0x8F )
437 /* Source buffer too small */
438 if (pEndSrcBuf - pSrcBuf < 3)
440 *pInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL;
441 break;
444 pSrcBuf++;
445 cLead = static_cast<unsigned char>(*pSrcBuf);
446 pSrcBuf++;
447 cTrail = static_cast<unsigned char>(*pSrcBuf);
448 pLeadTab = pConvertData->mpJIS0212ToUniLeadTab;
450 /* CodeSet 2 JIS 0208-1997 */
451 /* A1-FE + A1-FE */
452 else
454 /* Source buffer too small */
455 if ( pSrcBuf + 1 == pEndSrcBuf )
457 *pInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOOSMALL;
458 break;
461 cLead = c;
462 pSrcBuf++;
463 cTrail = static_cast<unsigned char>(*pSrcBuf);
464 pLeadTab = pConvertData->mpJIS0208ToUniLeadTab;
467 /* Undefined Range */
468 if ( (cLead < JIS_EUC_LEAD_OFF) || (cTrail < JIS_EUC_TRAIL_OFF) )
469 cConv = 0;
470 else
472 cLead -= JIS_EUC_LEAD_OFF;
473 cTrail -= JIS_EUC_TRAIL_OFF;
474 pLeadEntry = pLeadTab+cLead;
475 if ( (cTrail >= pLeadEntry->mnTrailStart) && (cTrail <= pLeadEntry->mnTrailEnd) )
476 cConv = pLeadEntry->mpToUniTrailTab[cTrail-pLeadEntry->mnTrailStart];
477 else
478 cConv = 0;
482 if ( !cConv )
484 /* We compare the full range of the trail we defined, */
485 /* which can often be greater than the limit. We do this */
486 /* so that extensions that don't consider encodings */
487 /* correctly treat double-byte characters as a single */
488 /* character as much as possible. */
490 if ( (cLead < JIS_EUC_LEAD_OFF) || (cTrail < JIS_EUC_TRAIL_OFF) )
492 *pInfo |= RTL_TEXTTOUNICODE_INFO_INVALID;
493 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR )
495 if ((nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0) {
496 ++pSrcBuf;
497 } else {
498 pSrcBuf = startOfCurrentChar;
500 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
501 break;
503 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE )
505 pSrcBuf++;
506 startOfCurrentChar = pSrcBuf;
507 continue;
509 cConv = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
511 else
513 if ((nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0) {
514 ++pSrcBuf;
515 } else {
516 pSrcBuf = startOfCurrentChar;
518 *pInfo |= RTL_TEXTTOUNICODE_INFO_MBUNDEFINED;
519 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR )
521 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
522 break;
524 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE )
526 pSrcBuf++;
527 startOfCurrentChar = pSrcBuf;
528 continue;
530 cConv = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
535 if ( pDestBuf == pEndDestBuf )
537 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOOSMALL;
538 break;
541 *pDestBuf = cConv;
542 pDestBuf++;
543 pSrcBuf++;
544 startOfCurrentChar = pSrcBuf;
547 *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
548 return (nDestChars - (pEndDestBuf-pDestBuf));
551 sal_Size ImplUnicodeToEUCJP( const void* pData,
552 SAL_UNUSED_PARAMETER void*,
553 const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
554 char* pDestBuf, sal_Size nDestBytes,
555 sal_uInt32 nFlags, sal_uInt32* pInfo,
556 sal_Size* pSrcCvtChars )
558 sal_uInt32 cConv;
559 sal_Unicode c;
560 unsigned char nHighChar;
561 unsigned char nLowChar;
562 const ImplUniToDBCSHighTab* pHighEntry;
563 const ImplUniToDBCSHighTab* pHighTab;
564 const ImplEUCJPConvertData* pConvertData = static_cast<const ImplEUCJPConvertData*>(pData);
565 char* pEndDestBuf;
566 const sal_Unicode* pEndSrcBuf;
568 *pInfo = 0;
569 pEndDestBuf = pDestBuf+nDestBytes;
570 pEndSrcBuf = pSrcBuf+nSrcChars;
571 while ( pSrcBuf < pEndSrcBuf )
573 c = *pSrcBuf;
575 /* ASCII */
576 if ( c <= 0x7F )
577 cConv = c;
578 /* Half-width katakana */
579 else if ( (c >= 0xFF61) && (c <= 0xFF9F) )
580 cConv = 0x8E00+0xA1+(c-0xFF61);
581 else
583 nHighChar = static_cast<unsigned char>((c >> 8) & 0xFF);
584 nLowChar = static_cast<unsigned char>(c & 0xFF);
586 /* JIS 0208 */
587 pHighTab = pConvertData->mpUniToJIS0208HighTab;
588 pHighEntry = pHighTab+nHighChar;
589 if ( (nLowChar >= pHighEntry->mnLowStart) && (nLowChar <= pHighEntry->mnLowEnd) )
591 cConv = pHighEntry->mpToUniTrailTab[nLowChar-pHighEntry->mnLowStart];
592 if (cConv != 0)
593 cConv |= 0x8080;
595 else
596 cConv = 0;
598 /* JIS 0212 */
599 if ( !cConv )
601 pHighTab = pConvertData->mpUniToJIS0212HighTab;
602 pHighEntry = pHighTab+nHighChar;
603 if ( (nLowChar >= pHighEntry->mnLowStart) && (nLowChar <= pHighEntry->mnLowEnd) )
605 cConv = pHighEntry->mpToUniTrailTab[nLowChar-pHighEntry->mnLowStart];
606 if (cConv != 0)
607 cConv |= 0x8F8080;
610 if ( !cConv )
612 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE )
614 /* !!! */
617 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR )
619 /* !!! */
622 /* Handle undefined and surrogates characters */
623 /* (all surrogates characters are undefined) */
624 if (sal::detail::textenc::handleUndefinedUnicodeToTextChar(
625 &pSrcBuf, pEndSrcBuf, &pDestBuf, pEndDestBuf,
626 nFlags, pInfo))
627 continue;
628 break;
633 /* SingleByte */
634 if ( !(cConv & 0xFFFF00) )
636 if ( pDestBuf == pEndDestBuf )
638 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
639 break;
642 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
643 pDestBuf++;
645 /* DoubleByte */
646 else if ( !(cConv & 0xFF0000) )
648 if ( pDestBuf+1 >= pEndDestBuf )
650 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
651 break;
654 *pDestBuf = static_cast< char >(static_cast< unsigned char >((cConv >> 8) & 0xFF));
655 pDestBuf++;
656 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
657 pDestBuf++;
659 else
661 if ( pDestBuf+2 >= pEndDestBuf )
663 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
664 break;
667 *pDestBuf = static_cast< char >(static_cast< unsigned char >((cConv >> 16) & 0xFF));
668 pDestBuf++;
669 *pDestBuf = static_cast< char >(static_cast< unsigned char >((cConv >> 8) & 0xFF));
670 pDestBuf++;
671 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
672 pDestBuf++;
675 pSrcBuf++;
678 *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
679 return (nDestBytes - (pEndDestBuf-pDestBuf));
682 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */