bump product version to 5.0.4.1
[LibreOffice.git] / sal / textenc / tcvtmb.cxx
blob75e5b7f128624981e971c055412d8e17110bf668
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 /* ======================================================================= */
30 /* DBCS to Unicode conversion routine use a lead table for the first byte, */
31 /* where we determine the trail table or for single byte chars the unicode */
32 /* value. We have for all lead byte a separate table, because we can */
33 /* then share many tables for different charset encodings. */
35 /* ======================================================================= */
37 sal_Size ImplDBCSToUnicode( const void* pData, SAL_UNUSED_PARAMETER void*,
38 const char* pSrcBuf, sal_Size nSrcBytes,
39 sal_Unicode* pDestBuf, sal_Size nDestChars,
40 sal_uInt32 nFlags, sal_uInt32* pInfo,
41 sal_Size* pSrcCvtBytes )
43 unsigned char cLead;
44 unsigned char cTrail;
45 sal_Unicode cConv;
46 const ImplDBCSToUniLeadTab* pLeadEntry;
47 const ImplDBCSConvertData* pConvertData = static_cast<const ImplDBCSConvertData*>(pData);
48 const ImplDBCSToUniLeadTab* pLeadTab = pConvertData->mpToUniLeadTab;
49 sal_Unicode* pEndDestBuf;
50 const char* pEndSrcBuf;
52 *pInfo = 0;
53 pEndDestBuf = pDestBuf+nDestChars;
54 pEndSrcBuf = pSrcBuf+nSrcBytes;
55 while ( pSrcBuf < pEndSrcBuf )
57 cLead = (unsigned char)*pSrcBuf;
59 /* get entry for the lead byte */
60 pLeadEntry = pLeadTab+cLead;
62 /* SingleByte char? */
63 if (pLeadEntry->mpToUniTrailTab == NULL
64 || cLead < pConvertData->mnLeadStart
65 || cLead > pConvertData->mnLeadEnd)
67 cConv = pLeadEntry->mnUniChar;
68 if ( !cConv && (cLead != 0) )
70 *pInfo |= RTL_TEXTTOUNICODE_INFO_UNDEFINED;
71 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR )
73 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
74 break;
76 else if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE )
78 pSrcBuf++;
79 continue;
81 else
82 cConv = ImplGetUndefinedUnicodeChar(cLead, nFlags);
85 else
87 /* Source buffer to small */
88 if ( pSrcBuf +1 == pEndSrcBuf )
90 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_FLUSH) == 0 )
92 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
93 break;
95 cConv = 0;
97 else
99 pSrcBuf++;
100 cTrail = (unsigned char)*pSrcBuf;
101 if ( (cTrail >= pLeadEntry->mnTrailStart) && (cTrail <= pLeadEntry->mnTrailEnd) )
102 cConv = pLeadEntry->mpToUniTrailTab[cTrail-pLeadEntry->mnTrailStart];
103 else
104 cConv = 0;
106 if ( !cConv )
108 /* EUDC Ranges */
109 sal_uInt16 i;
110 const ImplDBCSEUDCData* pEUDCTab = pConvertData->mpEUDCTab;
111 for ( i = 0; i < pConvertData->mnEUDCCount; i++ )
113 if ( (cLead >= pEUDCTab->mnLeadStart) &&
114 (cLead <= pEUDCTab->mnLeadEnd) )
116 if ( (cTrail >= pEUDCTab->mnTrail1Start) &&
117 (cTrail <= pEUDCTab->mnTrail1End) )
119 cConv = pEUDCTab->mnUniStart+
120 ((cLead-pEUDCTab->mnLeadStart)*pEUDCTab->mnTrailRangeCount)+
121 (cTrail-pEUDCTab->mnTrail1Start);
122 break;
124 else
126 sal_uInt16 nTrailCount = pEUDCTab->mnTrail1End-pEUDCTab->mnTrail1Start+1;
127 if ( (pEUDCTab->mnTrailCount >= 2) &&
128 (cTrail >= pEUDCTab->mnTrail2Start) &&
129 (cTrail <= pEUDCTab->mnTrail2End) )
131 cConv = pEUDCTab->mnUniStart+
132 ((cLead-pEUDCTab->mnLeadStart)*pEUDCTab->mnTrailRangeCount)+
133 nTrailCount+
134 (cTrail-pEUDCTab->mnTrail2Start);
135 break;
137 else
139 nTrailCount = pEUDCTab->mnTrail2End-pEUDCTab->mnTrail2Start+1;
140 if ( (pEUDCTab->mnTrailCount >= 3) &&
141 (cTrail >= pEUDCTab->mnTrail3Start) &&
142 (cTrail <= pEUDCTab->mnTrail3End) )
144 cConv = pEUDCTab->mnUniStart+
145 ((cLead-pEUDCTab->mnLeadStart)*pEUDCTab->mnTrailRangeCount)+
146 nTrailCount+
147 (cTrail-pEUDCTab->mnTrail3Start);
148 break;
154 pEUDCTab++;
157 if ( !cConv )
159 /* We compare the full range of the trail we defined, */
160 /* which can often be greater than the limit. We do this */
161 /* so that extensions that don't consider encodings */
162 /* correctly treat double-byte characters as a single */
163 /* character as much as possible. */
165 if (cLead < pConvertData->mnLeadStart
166 || cLead > pConvertData->mnLeadEnd
167 || cTrail < pConvertData->mnTrailStart
168 || cTrail > pConvertData->mnTrailEnd)
170 *pInfo |= RTL_TEXTTOUNICODE_INFO_INVALID;
171 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR )
173 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
174 break;
176 else if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE )
178 pSrcBuf++;
179 continue;
181 else
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 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
193 break;
195 else if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE )
197 pSrcBuf++;
198 continue;
200 else
201 cConv = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
205 if ( pDestBuf == pEndDestBuf )
207 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
208 break;
211 *pDestBuf = cConv;
212 pDestBuf++;
213 pSrcBuf++;
216 *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
217 return (nDestChars - (pEndDestBuf-pDestBuf));
220 /* ----------------------------------------------------------------------- */
222 sal_Size ImplUnicodeToDBCS( const void* pData, SAL_UNUSED_PARAMETER void*,
223 const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
224 char* pDestBuf, sal_Size nDestBytes,
225 sal_uInt32 nFlags, sal_uInt32* pInfo,
226 sal_Size* pSrcCvtChars )
228 sal_uInt16 cConv;
229 sal_Unicode c;
230 const ImplUniToDBCSHighTab* pHighEntry;
231 const ImplDBCSConvertData* pConvertData = static_cast<const ImplDBCSConvertData*>(pData);
232 const ImplUniToDBCSHighTab* pHighTab = pConvertData->mpToDBCSHighTab;
233 char* pEndDestBuf;
234 const sal_Unicode* pEndSrcBuf;
236 bool bCheckRange =
237 pConvertData->mnLeadStart != 0 || pConvertData->mnLeadEnd != 0xFF;
238 /* this statement has the effect that this extra check is only done for
239 EUC-KR, which uses the MS-949 tables, but does not support the full
240 range of MS-949 */
242 *pInfo = 0;
243 pEndDestBuf = pDestBuf+nDestBytes;
244 pEndSrcBuf = pSrcBuf+nSrcChars;
245 while ( pSrcBuf < pEndSrcBuf )
247 c = *pSrcBuf;
248 unsigned char nHighChar = (unsigned char)((c >> 8) & 0xFF);
249 unsigned char nLowChar = (unsigned char)(c & 0xFF);
251 /* get entry for the high byte */
252 pHighEntry = pHighTab+nHighChar;
254 /* is low byte in the table range */
255 if ( (nLowChar >= pHighEntry->mnLowStart) && (nLowChar <= pHighEntry->mnLowEnd) )
257 cConv = pHighEntry->mpToUniTrailTab[nLowChar-pHighEntry->mnLowStart];
258 if (bCheckRange && cConv > 0x7F
259 && ((cConv >> 8) < pConvertData->mnLeadStart
260 || (cConv >> 8) > pConvertData->mnLeadEnd
261 || (cConv & 0xFF) < pConvertData->mnTrailStart
262 || (cConv & 0xFF) > pConvertData->mnTrailEnd))
263 cConv = 0;
265 else
266 cConv = 0;
268 if (cConv == 0 && c != 0)
270 /* Map to EUDC ranges: */
271 ImplDBCSEUDCData const * pEUDCTab = pConvertData->mpEUDCTab;
272 sal_uInt32 i;
273 for (i = 0; i < pConvertData->mnEUDCCount; ++i)
275 if (c >= pEUDCTab->mnUniStart && c <= pEUDCTab->mnUniEnd)
277 sal_uInt32 nIndex = c - pEUDCTab->mnUniStart;
278 sal_uInt32 nLeadOff
279 = nIndex / pEUDCTab->mnTrailRangeCount;
280 sal_uInt32 nTrailOff
281 = nIndex % pEUDCTab->mnTrailRangeCount;
282 sal_uInt32 nSize;
283 cConv = (sal_uInt16)
284 ((pEUDCTab->mnLeadStart + nLeadOff) << 8);
285 nSize
286 = pEUDCTab->mnTrail1End - pEUDCTab->mnTrail1Start + 1;
287 if (nTrailOff < nSize)
289 cConv |= pEUDCTab->mnTrail1Start + nTrailOff;
290 break;
292 nTrailOff -= nSize;
293 nSize
294 = pEUDCTab->mnTrail2End - pEUDCTab->mnTrail2Start + 1;
295 if (nTrailOff < nSize)
297 cConv |= pEUDCTab->mnTrail2Start + nTrailOff;
298 break;
300 nTrailOff -= nSize;
301 cConv |= pEUDCTab->mnTrail3Start + nTrailOff;
302 break;
304 pEUDCTab++;
307 /* FIXME
308 * SB: Not sure why this is in here. Plus, it does not work as
309 * intended when (c & 0xFF) == 0, because the next !cConv check
310 * will then think c has not yet been converted...
312 if (c >= RTL_TEXTCVT_BYTE_PRIVATE_START
313 && c <= RTL_TEXTCVT_BYTE_PRIVATE_END)
315 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 )
316 cConv = static_cast< char >(static_cast< unsigned char >(c & 0xFF));
320 if ( !cConv )
322 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE )
324 /* !!! */
327 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR )
329 /* !!! */
332 /* Handle undefined and surrogates characters */
333 /* (all surrogates characters are undefined) */
334 if (sal::detail::textenc::handleUndefinedUnicodeToTextChar(
335 &pSrcBuf, pEndSrcBuf, &pDestBuf, pEndDestBuf, nFlags,
336 pInfo))
337 continue;
338 else
339 break;
342 /* SingleByte */
343 if ( !(cConv & 0xFF00) )
345 if ( pDestBuf == pEndDestBuf )
347 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
348 break;
351 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
352 pDestBuf++;
354 else
356 if ( pDestBuf+1 >= pEndDestBuf )
358 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
359 break;
362 *pDestBuf = static_cast< char >(static_cast< unsigned char >((cConv >> 8) & 0xFF));
363 pDestBuf++;
364 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
365 pDestBuf++;
368 pSrcBuf++;
371 *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
372 return (nDestBytes - (pEndDestBuf-pDestBuf));
375 /* ======================================================================= */
377 #define JIS_EUC_LEAD_OFF 0x80
378 #define JIS_EUC_TRAIL_OFF 0x80
380 /* ----------------------------------------------------------------------- */
382 sal_Size ImplEUCJPToUnicode( const void* pData,
383 SAL_UNUSED_PARAMETER void*,
384 const char* pSrcBuf, sal_Size nSrcBytes,
385 sal_Unicode* pDestBuf, sal_Size nDestChars,
386 sal_uInt32 nFlags, sal_uInt32* pInfo,
387 sal_Size* pSrcCvtBytes )
389 unsigned char cLead = '\0';
390 unsigned char cTrail = '\0';
391 sal_Unicode cConv;
392 const ImplDBCSToUniLeadTab* pLeadEntry;
393 const ImplDBCSToUniLeadTab* pLeadTab;
394 const ImplEUCJPConvertData* pConvertData = static_cast<const ImplEUCJPConvertData*>(pData);
395 sal_Unicode* pEndDestBuf;
396 const char* pEndSrcBuf;
398 *pInfo = 0;
399 pEndDestBuf = pDestBuf+nDestChars;
400 pEndSrcBuf = pSrcBuf+nSrcBytes;
401 while ( pSrcBuf < pEndSrcBuf )
403 unsigned char c = (unsigned char)*pSrcBuf;
405 /* ASCII */
406 if ( c <= 0x7F )
407 cConv = c;
408 else
410 /* SS2 - Half-width katakana */
411 /* 8E + A1-DF */
412 if ( c == 0x8E )
414 /* Source buffer to small */
415 if ( pSrcBuf + 1 == pEndSrcBuf )
417 *pInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
418 break;
421 pSrcBuf++;
422 c = (unsigned char)*pSrcBuf;
423 if ( (c >= 0xA1) && (c <= 0xDF) )
424 cConv = 0xFF61+(c-0xA1);
425 else
427 cConv = 0;
428 cLead = 0x8E;
429 cTrail = c;
432 else
434 /* SS3 - JIS 0212-1990 */
435 /* 8F + A1-FE + A1-FE */
436 if ( c == 0x8F )
438 /* Source buffer to small */
439 if (pEndSrcBuf - pSrcBuf < 3)
441 *pInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
442 break;
445 pSrcBuf++;
446 cLead = (unsigned char)*pSrcBuf;
447 pSrcBuf++;
448 cTrail = (unsigned char)*pSrcBuf;
449 pLeadTab = pConvertData->mpJIS0212ToUniLeadTab;
451 /* CodeSet 2 JIS 0208-1997 */
452 /* A1-FE + A1-FE */
453 else
455 /* Source buffer to small */
456 if ( pSrcBuf + 1 == pEndSrcBuf )
458 *pInfo |= RTL_TEXTTOUNICODE_INFO_SRCBUFFERTOSMALL;
459 break;
462 cLead = c;
463 pSrcBuf++;
464 cTrail = (unsigned char)*pSrcBuf;
465 pLeadTab = pConvertData->mpJIS0208ToUniLeadTab;
468 /* Undefined Range */
469 if ( (cLead < JIS_EUC_LEAD_OFF) || (cTrail < JIS_EUC_TRAIL_OFF) )
470 cConv = 0;
471 else
473 cLead -= JIS_EUC_LEAD_OFF;
474 cTrail -= JIS_EUC_TRAIL_OFF;
475 pLeadEntry = pLeadTab+cLead;
476 if ( (cTrail >= pLeadEntry->mnTrailStart) && (cTrail <= pLeadEntry->mnTrailEnd) )
477 cConv = pLeadEntry->mpToUniTrailTab[cTrail-pLeadEntry->mnTrailStart];
478 else
479 cConv = 0;
483 if ( !cConv )
485 /* We compare the full range of the trail we defined, */
486 /* which can often be greater than the limit. We do this */
487 /* so that extensions that don't consider encodings */
488 /* correctly treat double-byte characters as a single */
489 /* character as much as possible. */
491 if ( (cLead < JIS_EUC_LEAD_OFF) || (cTrail < JIS_EUC_TRAIL_OFF) )
493 *pInfo |= RTL_TEXTTOUNICODE_INFO_INVALID;
494 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR )
496 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
497 break;
499 else if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_INVALID_MASK) == RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE )
501 pSrcBuf++;
502 continue;
504 else
505 cConv = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
507 else
509 *pInfo |= RTL_TEXTTOUNICODE_INFO_MBUNDEFINED;
510 if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR )
512 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR;
513 break;
515 else if ( (nFlags & RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_MASK) == RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_IGNORE )
517 pSrcBuf++;
518 continue;
520 else
521 cConv = RTL_TEXTENC_UNICODE_REPLACEMENT_CHARACTER;
526 if ( pDestBuf == pEndDestBuf )
528 *pInfo |= RTL_TEXTTOUNICODE_INFO_ERROR | RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL;
529 break;
532 *pDestBuf = cConv;
533 pDestBuf++;
534 pSrcBuf++;
537 *pSrcCvtBytes = nSrcBytes - (pEndSrcBuf-pSrcBuf);
538 return (nDestChars - (pEndDestBuf-pDestBuf));
541 /* ----------------------------------------------------------------------- */
543 sal_Size ImplUnicodeToEUCJP( const void* pData,
544 SAL_UNUSED_PARAMETER void*,
545 const sal_Unicode* pSrcBuf, sal_Size nSrcChars,
546 char* pDestBuf, sal_Size nDestBytes,
547 sal_uInt32 nFlags, sal_uInt32* pInfo,
548 sal_Size* pSrcCvtChars )
550 sal_uInt32 cConv;
551 sal_Unicode c;
552 unsigned char nHighChar;
553 unsigned char nLowChar;
554 const ImplUniToDBCSHighTab* pHighEntry;
555 const ImplUniToDBCSHighTab* pHighTab;
556 const ImplEUCJPConvertData* pConvertData = static_cast<const ImplEUCJPConvertData*>(pData);
557 char* pEndDestBuf;
558 const sal_Unicode* pEndSrcBuf;
560 *pInfo = 0;
561 pEndDestBuf = pDestBuf+nDestBytes;
562 pEndSrcBuf = pSrcBuf+nSrcChars;
563 while ( pSrcBuf < pEndSrcBuf )
565 c = *pSrcBuf;
567 /* ASCII */
568 if ( c <= 0x7F )
569 cConv = c;
570 /* Half-width katakana */
571 else if ( (c >= 0xFF61) && (c <= 0xFF9F) )
572 cConv = 0x8E00+0xA1+(c-0xFF61);
573 else
575 nHighChar = (unsigned char)((c >> 8) & 0xFF);
576 nLowChar = (unsigned char)(c & 0xFF);
578 /* JIS 0208 */
579 pHighTab = pConvertData->mpUniToJIS0208HighTab;
580 pHighEntry = pHighTab+nHighChar;
581 if ( (nLowChar >= pHighEntry->mnLowStart) && (nLowChar <= pHighEntry->mnLowEnd) )
583 cConv = pHighEntry->mpToUniTrailTab[nLowChar-pHighEntry->mnLowStart];
584 if (cConv != 0)
585 cConv |= 0x8080;
587 else
588 cConv = 0;
590 /* JIS 0212 */
591 if ( !cConv )
593 pHighTab = pConvertData->mpUniToJIS0212HighTab;
594 pHighEntry = pHighTab+nHighChar;
595 if ( (nLowChar >= pHighEntry->mnLowStart) && (nLowChar <= pHighEntry->mnLowEnd) )
597 cConv = pHighEntry->mpToUniTrailTab[nLowChar-pHighEntry->mnLowStart];
598 if (cConv != 0)
599 cConv |= 0x8F8080;
602 if ( !cConv )
604 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE )
606 /* !!! */
609 if ( nFlags & RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACESTR )
611 /* !!! */
614 /* Handle undefined and surrogates characters */
615 /* (all surrogates characters are undefined) */
616 if (sal::detail::textenc::handleUndefinedUnicodeToTextChar(
617 &pSrcBuf, pEndSrcBuf, &pDestBuf, pEndDestBuf,
618 nFlags, pInfo))
619 continue;
620 else
621 break;
626 /* SingleByte */
627 if ( !(cConv & 0xFFFF00) )
629 if ( pDestBuf == pEndDestBuf )
631 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
632 break;
635 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
636 pDestBuf++;
638 /* DoubleByte */
639 else if ( !(cConv & 0xFF0000) )
641 if ( pDestBuf+1 >= pEndDestBuf )
643 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
644 break;
647 *pDestBuf = static_cast< char >(static_cast< unsigned char >((cConv >> 8) & 0xFF));
648 pDestBuf++;
649 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
650 pDestBuf++;
652 else
654 if ( pDestBuf+2 >= pEndDestBuf )
656 *pInfo |= RTL_UNICODETOTEXT_INFO_ERROR | RTL_UNICODETOTEXT_INFO_DESTBUFFERTOSMALL;
657 break;
660 *pDestBuf = static_cast< char >(static_cast< unsigned char >((cConv >> 16) & 0xFF));
661 pDestBuf++;
662 *pDestBuf = static_cast< char >(static_cast< unsigned char >((cConv >> 8) & 0xFF));
663 pDestBuf++;
664 *pDestBuf = static_cast< char >(static_cast< unsigned char >(cConv & 0xFF));
665 pDestBuf++;
668 pSrcBuf++;
671 *pSrcCvtChars = nSrcChars - (pEndSrcBuf-pSrcBuf);
672 return (nDestBytes - (pEndDestBuf-pDestBuf));
675 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */