Lines Matching +full:utf +full:- +full:8
4 * Copyright 2007-2014 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products.
14 #include "cups-private.h"
15 #include "debug-internal.h"
30 static iconv_t map_from_utf8 = (iconv_t)-1;
31 /* Convert from UTF-8 to charset */
32 static iconv_t map_to_utf8 = (iconv_t)-1;
33 /* Convert from charset to UTF-8 */
40 * '_cupsCharmapFlush()' - Flush all character set maps out of cache.
47 if (map_from_utf8 != (iconv_t)-1) in _cupsCharmapFlush()
50 map_from_utf8 = (iconv_t)-1; in _cupsCharmapFlush()
53 if (map_to_utf8 != (iconv_t)-1) in _cupsCharmapFlush()
56 map_to_utf8 = (iconv_t)-1; in _cupsCharmapFlush()
65 * 'cupsCharsetToUTF8()' - Convert legacy character set to UTF-8.
68 int /* O - Count or -1 on error */
70 cups_utf8_t *dest, /* O - Target string */ in cupsCharsetToUTF8()
71 const char *src, /* I - Source string */ in cupsCharsetToUTF8()
72 const int maxout, /* I - Max output */ in cupsCharsetToUTF8()
73 const cups_encoding_t encoding) /* I - Encoding */ in cupsCharsetToUTF8()
75 cups_utf8_t *destptr; /* Pointer into UTF-8 buffer */ in cupsCharsetToUTF8()
93 DEBUG_puts("3cupsCharsetToUTF8: Bad arguments, returning -1"); in cupsCharsetToUTF8()
94 return (-1); in cupsCharsetToUTF8()
109 * Handle ISO-8859-1 to UTF-8 directly... in cupsCharsetToUTF8()
117 cups_utf8_t *destend; /* End of UTF-8 buffer */ in cupsCharsetToUTF8()
120 destend = dest + maxout - 2; in cupsCharsetToUTF8()
137 return ((int)(destptr - dest)); in cupsCharsetToUTF8()
141 * Convert input legacy charset to UTF-8... in cupsCharsetToUTF8()
156 map_from_utf8 = iconv_open(_cupsEncodingName(encoding), "UTF-8"); in cupsCharsetToUTF8()
157 map_to_utf8 = iconv_open("UTF-8", toset); in cupsCharsetToUTF8()
160 if (map_to_utf8 != (iconv_t)-1) in cupsCharsetToUTF8()
162 char *altdestptr = (char *)dest; /* Silence bogus GCC type-punned */ in cupsCharsetToUTF8()
165 outBytesLeft = (size_t)maxout - 1; in cupsCharsetToUTF8()
172 return ((int)(altdestptr - (char *)dest)); in cupsCharsetToUTF8()
184 return (-1); in cupsCharsetToUTF8()
189 * 'cupsUTF8ToCharset()' - Convert UTF-8 to legacy character set.
192 int /* O - Count or -1 on error */
194 char *dest, /* O - Target string */ in cupsUTF8ToCharset()
195 const cups_utf8_t *src, /* I - Source string */ in cupsUTF8ToCharset()
196 const int maxout, /* I - Max output */ in cupsUTF8ToCharset()
197 const cups_encoding_t encoding) /* I - Encoding */ in cupsUTF8ToCharset()
215 return (-1); in cupsUTF8ToCharset()
230 * Handle UTF-8 to ISO-8859-1 directly... in cupsUTF8ToCharset()
239 char *destend; /* End of ISO-8859-1 buffer */ in cupsUTF8ToCharset()
242 destend = dest + maxout - 1; in cupsUTF8ToCharset()
266 return ((int)(destptr - dest)); in cupsUTF8ToCharset()
271 * Convert input UTF-8 to legacy charset... in cupsUTF8ToCharset()
285 map_from_utf8 = iconv_open(_cupsEncodingName(encoding), "UTF-8"); in cupsUTF8ToCharset()
286 map_to_utf8 = iconv_open("UTF-8", toset); in cupsUTF8ToCharset()
289 if (map_from_utf8 != (iconv_t)-1) in cupsUTF8ToCharset()
291 char *altsrc = (char *)src; /* Silence bogus GCC type-punned */ in cupsUTF8ToCharset()
294 outBytesLeft = (size_t)maxout - 1; in cupsUTF8ToCharset()
301 return ((int)(destptr - dest)); in cupsUTF8ToCharset()
313 return (-1); in cupsUTF8ToCharset()
318 * 'cupsUTF8ToUTF32()' - Convert UTF-8 to UTF-32.
320 * 32-bit UTF-32 (actually 21-bit) maps to UTF-8 as follows...
322 * UTF-32 char UTF-8 char(s)
323 * --------------------------------------------------
324 * 0 to 127 = 0xxxxxxx (US-ASCII)
329 * UTF-32 prohibits chars beyond Plane 16 (> 0x10ffff) in UCS-4,
330 * which would convert to five- or six-octet UTF-8 sequences...
333 int /* O - Count or -1 on error */
335 cups_utf32_t *dest, /* O - Target string */ in cupsUTF8ToUTF32()
336 const cups_utf8_t *src, /* I - Source string */ in cupsUTF8ToUTF32()
337 const int maxout) /* I - Max output */ in cupsUTF8ToUTF32()
342 cups_utf32_t ch32; /* UTF-32 character value */ in cupsUTF8ToUTF32()
356 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad arguments)"); in cupsUTF8ToUTF32()
358 return (-1); in cupsUTF8ToUTF32()
362 * Convert input UTF-8 to output UTF-32... in cupsUTF8ToUTF32()
365 for (i = maxout - 1; *src && i > 0; i --) in cupsUTF8ToUTF32()
370 * Convert UTF-8 character(s) to UTF-32 character... in cupsUTF8ToUTF32()
376 * One-octet UTF-8 <= 127 (US-ASCII)... in cupsUTF8ToUTF32()
381 DEBUG_printf(("4cupsUTF8ToUTF32: %02x => %08X", src[-1], ch)); in cupsUTF8ToUTF32()
387 * Two-octet UTF-8 <= 2047 (Latin-x)... in cupsUTF8ToUTF32()
393 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
395 return (-1); in cupsUTF8ToUTF32()
401 * Check for non-shortest form (invalid UTF-8)... in cupsUTF8ToUTF32()
406 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
408 return (-1); in cupsUTF8ToUTF32()
414 src[-2], src[-1], (unsigned)ch32)); in cupsUTF8ToUTF32()
419 * Three-octet UTF-8 <= 65535 (Plane 0 - BMP)... in cupsUTF8ToUTF32()
425 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
427 return (-1); in cupsUTF8ToUTF32()
435 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
437 return (-1); in cupsUTF8ToUTF32()
443 * Check for non-shortest form (invalid UTF-8)... in cupsUTF8ToUTF32()
448 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
450 return (-1); in cupsUTF8ToUTF32()
456 src[-3], src[-2], src[-1], (unsigned)ch32)); in cupsUTF8ToUTF32()
461 * Four-octet UTF-8... in cupsUTF8ToUTF32()
467 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
469 return (-1); in cupsUTF8ToUTF32()
477 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
479 return (-1); in cupsUTF8ToUTF32()
487 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
489 return (-1); in cupsUTF8ToUTF32()
495 * Check for non-shortest form (invalid UTF-8)... in cupsUTF8ToUTF32()
500 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
502 return (-1); in cupsUTF8ToUTF32()
508 src[-4], src[-3], src[-2], src[-1], (unsigned)ch32)); in cupsUTF8ToUTF32()
513 * More than 4-octet (invalid UTF-8 sequence)... in cupsUTF8ToUTF32()
516 DEBUG_puts("3cupsUTF8ToUTF32: Returning -1 (bad UTF-8 sequence)"); in cupsUTF8ToUTF32()
518 return (-1); in cupsUTF8ToUTF32()
522 * Check for UTF-16 surrogate (illegal UTF-8)... in cupsUTF8ToUTF32()
526 return (-1); in cupsUTF8ToUTF32()
531 DEBUG_printf(("3cupsUTF8ToUTF32: Returning %d characters", maxout - 1 - i)); in cupsUTF8ToUTF32()
533 return (maxout - 1 - i); in cupsUTF8ToUTF32()
538 * 'cupsUTF32ToUTF8()' - Convert UTF-32 to UTF-8.
540 * 32-bit UTF-32 (actually 21-bit) maps to UTF-8 as follows...
542 * UTF-32 char UTF-8 char(s)
543 * --------------------------------------------------
544 * 0 to 127 = 0xxxxxxx (US-ASCII)
549 * UTF-32 prohibits chars beyond Plane 16 (> 0x10ffff) in UCS-4,
550 * which would convert to five- or six-octet UTF-8 sequences...
553 int /* O - Count or -1 on error */
555 cups_utf8_t *dest, /* O - Target string */ in cupsUTF32ToUTF8()
556 const cups_utf32_t *src, /* I - Source string */ in cupsUTF32ToUTF8()
557 const int maxout) /* I - Max output */ in cupsUTF32ToUTF8()
561 int swap; /* Byte-swap input to output */ in cupsUTF32ToUTF8()
576 DEBUG_puts("3cupsUTF32ToUTF8: Returning -1 (bad args)"); in cupsUTF32ToUTF8()
578 return (-1); in cupsUTF32ToUTF8()
582 * Check for leading BOM in UTF-32 and inverted BOM... in cupsUTF32ToUTF8()
594 * Convert input UTF-32 to output UTF-8... in cupsUTF32ToUTF8()
597 for (i = maxout - 1; *src && i > 0;) in cupsUTF32ToUTF8()
602 * Byte swap input UTF-32, if necessary... in cupsUTF32ToUTF8()
603 * (only byte-swapping 24 of 32 bits) in cupsUTF32ToUTF8()
607 ch = ((ch >> 24) | ((ch >> 8) & 0xff00) | ((ch << 8) & 0xff0000)); in cupsUTF32ToUTF8()
610 * Check for beyond Plane 16 (invalid UTF-32)... in cupsUTF32ToUTF8()
615 DEBUG_puts("3cupsUTF32ToUTF8: Returning -1 (character out of range)"); in cupsUTF32ToUTF8()
617 return (-1); in cupsUTF32ToUTF8()
621 * Convert UTF-32 character to UTF-8 character(s)... in cupsUTF32ToUTF8()
627 * One-octet UTF-8 <= 127 (US-ASCII)... in cupsUTF32ToUTF8()
631 i --; in cupsUTF32ToUTF8()
633 DEBUG_printf(("4cupsUTF32ToUTF8: %08x => %02x", (unsigned)ch, dest[-1])); in cupsUTF32ToUTF8()
638 * Two-octet UTF-8 <= 2047 (Latin-x)... in cupsUTF32ToUTF8()
643 DEBUG_puts("3cupsUTF32ToUTF8: Returning -1 (too long 2)"); in cupsUTF32ToUTF8()
645 return (-1); in cupsUTF32ToUTF8()
650 i -= 2; in cupsUTF32ToUTF8()
653 dest[-2], dest[-1])); in cupsUTF32ToUTF8()
658 * Three-octet UTF-8 <= 65535 (Plane 0 - BMP)... in cupsUTF32ToUTF8()
663 DEBUG_puts("3cupsUTF32ToUTF8: Returning -1 (too long 3)"); in cupsUTF32ToUTF8()
665 return (-1); in cupsUTF32ToUTF8()
671 i -= 3; in cupsUTF32ToUTF8()
674 dest[-3], dest[-2], dest[-1])); in cupsUTF32ToUTF8()
679 * Four-octet UTF-8... in cupsUTF32ToUTF8()
684 DEBUG_puts("3cupsUTF32ToUTF8: Returning -1 (too long 4)"); in cupsUTF32ToUTF8()
686 return (-1); in cupsUTF32ToUTF8()
693 i -= 4; in cupsUTF32ToUTF8()
696 (unsigned)ch, dest[-4], dest[-3], dest[-2], dest[-1])); in cupsUTF32ToUTF8()
702 DEBUG_printf(("3cupsUTF32ToUTF8: Returning %d", (int)(dest - start))); in cupsUTF32ToUTF8()
704 return ((int)(dest - start)); in cupsUTF32ToUTF8()