source: trunk/libtransmission/ConvertUTF.c @ 7656

Last change on this file since 7656 was 7656, checked in by charles, 13 years ago

(trunk libT) #1675: better utf8 validation of metainfo name, creator, and comment fields

File size: 20.2 KB
Line 
1/*
2 * Copyright 2001-2004 Unicode, Inc.
3 *
4 * Disclaimer
5 *
6 * This source code is provided as is by Unicode, Inc. No claims are
7 * made as to fitness for any particular purpose. No warranties of any
8 * kind are expressed or implied. The recipient agrees to determine
9 * applicability of information provided. If this file has been
10 * purchased on magnetic or optical media from Unicode, Inc., the
11 * sole remedy for any claim will be exchange of defective media
12 * within 90 days of receipt.
13 *
14 * Limitations on Rights to Redistribute This Code
15 *
16 * Unicode, Inc. hereby grants the right to freely use the information
17 * supplied in this file in the creation of products supporting the
18 * Unicode Standard, and to make copies of this file in any form
19 * for internal or external distribution as long as this notice
20 * remains attached.
21 */
22
23/* ---------------------------------------------------------------------
24
25    Conversions between UTF32, UTF-16, and UTF-8. Source code file.
26    Author: Mark E. Davis, 1994.
27    Rev History: Rick McGowan, fixes & updates May 2001.
28    Sept 2001: fixed const & error conditions per
29        mods suggested by S. Parent & A. Lillich.
30    June 2002: Tim Dodd added detection and handling of incomplete
31        source sequences, enhanced error detection, added casts
32        to eliminate compiler warnings.
33    July 2003: slight mods to back out aggressive FFFE detection.
34    Jan 2004: updated switches in from-UTF8 conversions.
35    Oct 2004: updated to use UNI_MAX_LEGAL_UTF32 in UTF-32 conversions.
36    May 2006: updated isLegalUTF8Sequence.
37
38    See the header file "ConvertUTF.h" for complete documentation.
39
40------------------------------------------------------------------------ */
41
42#ifdef CVTUTF_DEBUG
43 #include <stdio.h>
44#endif
45#include <string.h> /* strlen() */
46#include <unistd.h> /* ssize_t */
47#include "ConvertUTF.h"
48
49static const int halfShift  = 10; /* used for shifting by 10 bits */
50
51static const UTF32 halfBase = 0x0010000UL;
52static const UTF32 halfMask = 0x3FFUL;
53
54#define UNI_SUR_HIGH_START  (UTF32)0xD800
55#define UNI_SUR_HIGH_END    (UTF32)0xDBFF
56#define UNI_SUR_LOW_START   (UTF32)0xDC00
57#define UNI_SUR_LOW_END     (UTF32)0xDFFF
58#define false      0
59#define true        1
60
61/* --------------------------------------------------------------------- */
62
63ConversionResult ConvertUTF32toUTF16 (
64        const UTF32** sourceStart, const UTF32* sourceEnd, 
65        UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
66    ConversionResult result = conversionOK;
67    const UTF32* source = *sourceStart;
68    UTF16* target = *targetStart;
69    while (source < sourceEnd) {
70        UTF32 ch;
71        if (target >= targetEnd) {
72            result = targetExhausted; break;
73        }
74        ch = *source++;
75        if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
76            /* UTF-16 surrogate values are illegal in UTF-32; 0xffff or 0xfffe are both reserved values */
77            if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
78                if (flags == strictConversion) {
79                    --source; /* return to the illegal value itself */
80                    result = sourceIllegal;
81                    break;
82                } else {
83                    *target++ = UNI_REPLACEMENT_CHAR;
84                }
85            } else {
86                *target++ = (UTF16)ch; /* normal case */
87            }
88        } else if (ch > UNI_MAX_LEGAL_UTF32) {
89            if (flags == strictConversion) {
90                result = sourceIllegal;
91            } else {
92                *target++ = UNI_REPLACEMENT_CHAR;
93            }
94        } else {
95            /* target is a character in range 0xFFFF - 0x10FFFF. */
96            if (target + 1 >= targetEnd) {
97                --source; /* Back up source pointer! */
98                result = targetExhausted; break;
99            }
100            ch -= halfBase;
101            *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
102            *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
103        }
104    }
105    *sourceStart = source;
106    *targetStart = target;
107    return result;
108}
109
110/* --------------------------------------------------------------------- */
111
112ConversionResult ConvertUTF16toUTF32 (
113        const UTF16** sourceStart, const UTF16* sourceEnd, 
114        UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
115    ConversionResult result = conversionOK;
116    const UTF16* source = *sourceStart;
117    UTF32* target = *targetStart;
118    UTF32 ch, ch2;
119    while (source < sourceEnd) {
120        const UTF16* oldSource = source; /*  In case we have to back up because of target overflow. */
121        ch = *source++;
122        /* If we have a surrogate pair, convert to UTF32 first. */
123        if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
124            /* If the 16 bits following the high surrogate are in the source buffer... */
125            if (source < sourceEnd) {
126                ch2 = *source;
127                /* If it's a low surrogate, convert to UTF32. */
128                if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
129                    ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
130                        + (ch2 - UNI_SUR_LOW_START) + halfBase;
131                    ++source;
132                } else if (flags == strictConversion) { /* it's an unpaired high surrogate */
133                    --source; /* return to the illegal value itself */
134                    result = sourceIllegal;
135                    break;
136                }
137            } else { /* We don't have the 16 bits following the high surrogate. */
138                --source; /* return to the high surrogate */
139                result = sourceExhausted;
140                break;
141            }
142        } else if (flags == strictConversion) {
143            /* UTF-16 surrogate values are illegal in UTF-32 */
144            if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
145                --source; /* return to the illegal value itself */
146                result = sourceIllegal;
147                break;
148            }
149        }
150        if (target >= targetEnd) {
151            source = oldSource; /* Back up source pointer! */
152            result = targetExhausted; break;
153        }
154        *target++ = ch;
155    }
156    *sourceStart = source;
157    *targetStart = target;
158#ifdef CVTUTF_DEBUG
159if (result == sourceIllegal) {
160    fprintf(stderr, "ConvertUTF16toUTF32 illegal seq 0x%04x,%04x\n", ch, ch2);
161    fflush(stderr);
162}
163#endif
164    return result;
165}
166
167/* --------------------------------------------------------------------- */
168
169/*
170 * Index into the table below with the first byte of a UTF-8 sequence to
171 * get the number of trailing bytes that are supposed to follow it.
172 * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
173 * left as-is for anyone who may want to do such conversion, which was
174 * allowed in earlier algorithms.
175 */
176static const char trailingBytesForUTF8[256] = {
177    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
178    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
179    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
180    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
181    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
182    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
183    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
184    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
185};
186
187/*
188 * Magic values subtracted from a buffer value during UTF8 conversion.
189 * This table contains as many values as there might be trailing bytes
190 * in a UTF-8 sequence.
191 */
192static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL, 
193                     0x03C82080UL, 0xFA082080UL, 0x82082080UL };
194
195/*
196 * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
197 * into the first byte, depending on how many bytes follow.  There are
198 * as many entries in this table as there are UTF-8 sequence types.
199 * (I.e., one byte sequence, two byte... etc.). Remember that sequencs
200 * for *legal* UTF-8 will be 4 or fewer bytes total.
201 */
202static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
203
204/* --------------------------------------------------------------------- */
205
206/* The interface converts a whole buffer to avoid function-call overhead.
207 * Constants have been gathered. Loops & conditionals have been removed as
208 * much as possible for efficiency, in favor of drop-through switches.
209 * (See "Note A" at the bottom of the file for equivalent code.)
210 * If your compiler supports it, the "isLegalUTF8" call can be turned
211 * into an inline function.
212 */
213
214/* --------------------------------------------------------------------- */
215
216ConversionResult ConvertUTF16toUTF8 (
217        const UTF16** sourceStart, const UTF16* sourceEnd, 
218        UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
219    ConversionResult result = conversionOK;
220    const UTF16* source = *sourceStart;
221    UTF8* target = *targetStart;
222    while (source < sourceEnd) {
223        UTF32 ch;
224        unsigned short bytesToWrite = 0;
225        const UTF32 byteMask = 0xBF;
226        const UTF32 byteMark = 0x80; 
227        const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
228        ch = *source++;
229        /* If we have a surrogate pair, convert to UTF32 first. */
230        if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
231            /* If the 16 bits following the high surrogate are in the source buffer... */
232            if (source < sourceEnd) {
233                UTF32 ch2 = *source;
234                /* If it's a low surrogate, convert to UTF32. */
235                if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
236                    ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
237                        + (ch2 - UNI_SUR_LOW_START) + halfBase;
238                    ++source;
239                } else if (flags == strictConversion) { /* it's an unpaired high surrogate */
240                    --source; /* return to the illegal value itself */
241                    result = sourceIllegal;
242                    break;
243                }
244            } else { /* We don't have the 16 bits following the high surrogate. */
245                --source; /* return to the high surrogate */
246                result = sourceExhausted;
247                break;
248            }
249        } else if (flags == strictConversion) {
250            /* UTF-16 surrogate values are illegal in UTF-32 */
251            if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
252                --source; /* return to the illegal value itself */
253                result = sourceIllegal;
254                break;
255            }
256        }
257        /* Figure out how many bytes the result will require */
258        if (ch < (UTF32)0x80) {      bytesToWrite = 1;
259        } else if (ch < (UTF32)0x800) {     bytesToWrite = 2;
260        } else if (ch < (UTF32)0x10000) {   bytesToWrite = 3;
261        } else if (ch < (UTF32)0x110000) {  bytesToWrite = 4;
262        } else {                            bytesToWrite = 3;
263                                            ch = UNI_REPLACEMENT_CHAR;
264        }
265
266        target += bytesToWrite;
267        if (target > targetEnd) {
268            source = oldSource; /* Back up source pointer! */
269            target -= bytesToWrite; result = targetExhausted; break;
270        }
271        switch (bytesToWrite) { /* note: everything falls through. */
272            case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
273            case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
274            case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
275            case 1: *--target =  (UTF8)(ch | firstByteMark[bytesToWrite]);
276        }
277        target += bytesToWrite;
278    }
279    *sourceStart = source;
280    *targetStart = target;
281    return result;
282}
283
284/* --------------------------------------------------------------------- */
285
286/*
287 * Utility routine to tell whether a sequence of bytes is legal UTF-8.
288 * This must be called with the length pre-determined by the first byte.
289 * If not calling this from ConvertUTF8to*, then the length can be set by:
290 *  length = trailingBytesForUTF8[*source]+1;
291 * and the sequence is illegal right away if there aren't that many bytes
292 * available.
293 * If presented with a length > 4, this returns false.  The Unicode
294 * definition of UTF-8 goes up to 4-byte sequences.
295 */
296
297static Boolean isLegalUTF8(const UTF8 *source, int length) {
298    UTF8 a;
299    const UTF8 *srcptr = source+length;
300    switch (length) {
301    default: return false;
302        /* Everything else falls through when "true"... */
303    case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
304    case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
305    case 2: if ((a = (*--srcptr)) > 0xBF) return false;
306
307        switch (*source) {
308            /* no fall-through in this inner switch */
309            case 0xE0: if (a < 0xA0) return false; break;
310            case 0xED: if ((a < 0x80) || (a > 0x9F)) return false; break;
311            case 0xF0: if (a < 0x90) return false; break;
312            case 0xF4: if (a > 0x8F) return false; break;
313            default:   if (a < 0x80) return false;
314        }
315
316    case 1: if (*source >= 0x80 && *source < 0xC2) return false;
317    }
318    if (*source > 0xF4) return false;
319    return true;
320}
321
322/* --------------------------------------------------------------------- */
323
324/*
325 * Exported function to return whether a UTF-8 sequence is legal or not.
326 * This is not used here; it's just exported.
327 */
328
329Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
330    int length;
331    if (source == sourceEnd) {
332        return true;
333    }
334    while (true) {
335        length = trailingBytesForUTF8[*source]+1;
336        if (source+length > sourceEnd) {
337            return false;
338        }
339        if (!isLegalUTF8(source, length)) {
340            return false;
341        }
342        source += length;
343        if (source >= sourceEnd) {
344            return true;
345        }
346    }
347}
348
349/**
350 * This is a variation of isLegalUTF8Sequence() that behaves like g_utf8_validate().
351 * In addition to knowing if the sequence is legal, it also tells you the last good character.
352 */
353Boolean
354tr_utf8_validate( const char * str, ssize_t max_len, const char ** end )
355{
356    const UTF8* source = (const UTF8*) str;
357    const UTF8* sourceEnd = source;
358
359    if( max_len == 0 )
360        return true;
361
362    if( str == NULL )
363        return false;
364
365    sourceEnd = source + ((max_len < 0) ? strlen(str) : (size_t)max_len);
366
367    if( source == sourceEnd )
368    {
369        if( end != NULL )
370            *end = (const char*) source;
371        return true;
372    }
373
374    for( ;; )
375    {
376        const int length = trailingBytesForUTF8[*source] + 1;
377        if (source + length > sourceEnd) {
378            if( end != NULL )
379                *end = (const char*) source;
380            return false;
381        }
382        if (!isLegalUTF8(source, length)) {
383            if( end != NULL )
384                *end = (const char*) source;
385            return false;
386        }
387        source += length;
388        if (source >= sourceEnd) {
389            if( end != NULL )
390                *end = (const char*) source;
391            return true;
392        }
393    }
394
395   
396}
397
398
399/* --------------------------------------------------------------------- */
400
401ConversionResult ConvertUTF8toUTF16 (
402        const UTF8** sourceStart, const UTF8* sourceEnd, 
403        UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
404    ConversionResult result = conversionOK;
405    const UTF8* source = *sourceStart;
406    UTF16* target = *targetStart;
407    while (source < sourceEnd) {
408        UTF32 ch = 0;
409        unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
410        if (source + extraBytesToRead >= sourceEnd) {
411            result = sourceExhausted; break;
412        }
413        /* Do this check whether lenient or strict */
414        if (! isLegalUTF8(source, extraBytesToRead+1)) {
415            result = sourceIllegal;
416            break;
417        }
418        /*
419         * The cases all fall through. See "Note A" below.
420         */
421        switch (extraBytesToRead) {
422            case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
423            case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
424            case 3: ch += *source++; ch <<= 6;
425            case 2: ch += *source++; ch <<= 6;
426            case 1: ch += *source++; ch <<= 6;
427            case 0: ch += *source++;
428        }
429        ch -= offsetsFromUTF8[extraBytesToRead];
430
431        if (target >= targetEnd) {
432            source -= (extraBytesToRead+1); /* Back up source pointer! */
433            result = targetExhausted; break;
434        }
435        if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
436            /* UTF-16 surrogate values are illegal in UTF-32 */
437            if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
438                if (flags == strictConversion) {
439                    source -= (extraBytesToRead+1); /* return to the illegal value itself */
440                    result = sourceIllegal;
441                    break;
442                } else {
443                    *target++ = UNI_REPLACEMENT_CHAR;
444                }
445            } else {
446                *target++ = (UTF16)ch; /* normal case */
447            }
448        } else if (ch > UNI_MAX_UTF16) {
449            if (flags == strictConversion) {
450                result = sourceIllegal;
451                source -= (extraBytesToRead+1); /* return to the start */
452                break; /* Bail out; shouldn't continue */
453            } else {
454                *target++ = UNI_REPLACEMENT_CHAR;
455            }
456        } else {
457            /* target is a character in range 0xFFFF - 0x10FFFF. */
458            if (target + 1 >= targetEnd) {
459                source -= (extraBytesToRead+1); /* Back up source pointer! */
460                result = targetExhausted; break;
461            }
462            ch -= halfBase;
463            *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
464            *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
465        }
466    }
467    *sourceStart = source;
468    *targetStart = target;
469    return result;
470}
471
472/* --------------------------------------------------------------------- */
473
474ConversionResult ConvertUTF32toUTF8 (
475        const UTF32** sourceStart, const UTF32* sourceEnd, 
476        UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
477    ConversionResult result = conversionOK;
478    const UTF32* source = *sourceStart;
479    UTF8* target = *targetStart;
480    while (source < sourceEnd) {
481        UTF32 ch;
482        unsigned short bytesToWrite = 0;
483        const UTF32 byteMask = 0xBF;
484        const UTF32 byteMark = 0x80; 
485        ch = *source++;
486        if (flags == strictConversion ) {
487            /* UTF-16 surrogate values are illegal in UTF-32 */
488            if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
489                --source; /* return to the illegal value itself */
490                result = sourceIllegal;
491                break;
492            }
493        }
494        /*
495         * Figure out how many bytes the result will require. Turn any
496         * illegally large UTF32 things (> Plane 17) into replacement chars.
497         */
498        if (ch < (UTF32)0x80) {      bytesToWrite = 1;
499        } else if (ch < (UTF32)0x800) {     bytesToWrite = 2;
500        } else if (ch < (UTF32)0x10000) {   bytesToWrite = 3;
501        } else if (ch <= UNI_MAX_LEGAL_UTF32) {  bytesToWrite = 4;
502        } else {                            bytesToWrite = 3;
503                                            ch = UNI_REPLACEMENT_CHAR;
504                                            result = sourceIllegal;
505        }
506       
507        target += bytesToWrite;
508        if (target > targetEnd) {
509            --source; /* Back up source pointer! */
510            target -= bytesToWrite; result = targetExhausted; break;
511        }
512        switch (bytesToWrite) { /* note: everything falls through. */
513            case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
514            case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
515            case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
516            case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
517        }
518        target += bytesToWrite;
519    }
520    *sourceStart = source;
521    *targetStart = target;
522    return result;
523}
524
525/* --------------------------------------------------------------------- */
526
527ConversionResult ConvertUTF8toUTF32 (
528        const UTF8** sourceStart, const UTF8* sourceEnd, 
529        UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
530    ConversionResult result = conversionOK;
531    const UTF8* source = *sourceStart;
532    UTF32* target = *targetStart;
533    while (source < sourceEnd) {
534        UTF32 ch = 0;
535        unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
536        if (source + extraBytesToRead >= sourceEnd) {
537            result = sourceExhausted; break;
538        }
539        /* Do this check whether lenient or strict */
540        if (! isLegalUTF8(source, extraBytesToRead+1)) {
541            result = sourceIllegal;
542            break;
543        }
544        /*
545         * The cases all fall through. See "Note A" below.
546         */
547        switch (extraBytesToRead) {
548            case 5: ch += *source++; ch <<= 6;
549            case 4: ch += *source++; ch <<= 6;
550            case 3: ch += *source++; ch <<= 6;
551            case 2: ch += *source++; ch <<= 6;
552            case 1: ch += *source++; ch <<= 6;
553            case 0: ch += *source++;
554        }
555        ch -= offsetsFromUTF8[extraBytesToRead];
556
557        if (target >= targetEnd) {
558            source -= (extraBytesToRead+1); /* Back up the source pointer! */
559            result = targetExhausted; break;
560        }
561        if (ch <= UNI_MAX_LEGAL_UTF32) {
562            /*
563             * UTF-16 surrogate values are illegal in UTF-32, and anything
564             * over Plane 17 (> 0x10FFFF) is illegal.
565             */
566            if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
567                if (flags == strictConversion) {
568                    source -= (extraBytesToRead+1); /* return to the illegal value itself */
569                    result = sourceIllegal;
570                    break;
571                } else {
572                    *target++ = UNI_REPLACEMENT_CHAR;
573                }
574            } else {
575                *target++ = ch;
576            }
577        } else { /* i.e., ch > UNI_MAX_LEGAL_UTF32 */
578            result = sourceIllegal;
579            *target++ = UNI_REPLACEMENT_CHAR;
580        }
581    }
582    *sourceStart = source;
583    *targetStart = target;
584    return result;
585}
586
587/* ---------------------------------------------------------------------
588
589    Note A.
590    The fall-through switches in UTF-8 reading code save a
591    temp variable, some decrements & conditionals.  The switches
592    are equivalent to the following loop:
593        {
594            int tmpBytesToRead = extraBytesToRead+1;
595            do {
596                ch += *source++;
597                --tmpBytesToRead;
598                if (tmpBytesToRead) ch <<= 6;
599            } while (tmpBytesToRead > 0);
600        }
601    In UTF-8 writing code, the switches on "bytesToWrite" are
602    similarly unrolled loops.
603
604   --------------------------------------------------------------------- */
Note: See TracBrowser for help on using the repository browser.