ICU 58.2  58.2
utf_old.h
Go to the documentation of this file.
1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 *
6 * Copyright (C) 2002-2012, International Business Machines
7 * Corporation and others. All Rights Reserved.
8 *
9 *******************************************************************************
10 * file name: utf_old.h
11 * encoding: US-ASCII
12 * tab size: 8 (not used)
13 * indentation:4
14 *
15 * created on: 2002sep21
16 * created by: Markus W. Scherer
17 */
18 
145 #ifndef __UTF_OLD_H__
146 #define __UTF_OLD_H__
147 
148 #ifndef U_HIDE_DEPRECATED_API
149 
150 #include "unicode/utf.h"
151 #include "unicode/utf8.h"
152 #include "unicode/utf16.h"
153 
154 /* Formerly utf.h, part 1 --------------------------------------------------- */
155 
156 #ifdef U_USE_UTF_DEPRECATES
157 
164 typedef int32_t UTextOffset;
165 #endif
166 
168 #define UTF_SIZE 16
169 
176 #define UTF_SAFE
177 
178 #undef UTF_UNSAFE
179 
180 #undef UTF_STRICT
181 
196 #define UTF8_ERROR_VALUE_1 0x15
197 
203 #define UTF8_ERROR_VALUE_2 0x9f
204 
211 #define UTF_ERROR_VALUE 0xffff
212 
219 #define UTF_IS_ERROR(c) \
220  (((c)&0xfffe)==0xfffe || (c)==UTF8_ERROR_VALUE_1 || (c)==UTF8_ERROR_VALUE_2)
221 
227 #define UTF_IS_VALID(c) \
228  (UTF_IS_UNICODE_CHAR(c) && \
229  (c)!=UTF8_ERROR_VALUE_1 && (c)!=UTF8_ERROR_VALUE_2)
230 
235 #define UTF_IS_SURROGATE(uchar) (((uchar)&0xfffff800)==0xd800)
236 
242 #define UTF_IS_UNICODE_NONCHAR(c) \
243  ((c)>=0xfdd0 && \
244  ((uint32_t)(c)<=0xfdef || ((c)&0xfffe)==0xfffe) && \
245  (uint32_t)(c)<=0x10ffff)
246 
262 #define UTF_IS_UNICODE_CHAR(c) \
263  ((uint32_t)(c)<0xd800 || \
264  ((uint32_t)(c)>0xdfff && \
265  (uint32_t)(c)<=0x10ffff && \
266  !UTF_IS_UNICODE_NONCHAR(c)))
267 
268 /* Formerly utf8.h ---------------------------------------------------------- */
269 
274 #define UTF8_COUNT_TRAIL_BYTES(leadByte) (utf8_countTrailBytes[(uint8_t)leadByte])
275 
280 #define UTF8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1)
281 
283 #define UTF8_IS_SINGLE(uchar) (((uchar)&0x80)==0)
284 
285 #define UTF8_IS_LEAD(uchar) ((uint8_t)((uchar)-0xc0)<0x3e)
286 
287 #define UTF8_IS_TRAIL(uchar) (((uchar)&0xc0)==0x80)
288 
290 #define UTF8_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0x7f)
291 
305 #if 1
306 # define UTF8_CHAR_LENGTH(c) \
307  ((uint32_t)(c)<=0x7f ? 1 : \
308  ((uint32_t)(c)<=0x7ff ? 2 : \
309  ((uint32_t)((c)-0x10000)>0xfffff ? 3 : 4) \
310  ) \
311  )
312 #else
313 # define UTF8_CHAR_LENGTH(c) \
314  ((uint32_t)(c)<=0x7f ? 1 : \
315  ((uint32_t)(c)<=0x7ff ? 2 : \
316  ((uint32_t)(c)<=0xffff ? 3 : \
317  ((uint32_t)(c)<=0x10ffff ? 4 : \
318  ((uint32_t)(c)<=0x3ffffff ? 5 : \
319  ((uint32_t)(c)<=0x7fffffff ? 6 : 3) \
320  ) \
321  ) \
322  ) \
323  ) \
324  )
325 #endif
326 
328 #define UTF8_MAX_CHAR_LENGTH 4
329 
331 #define UTF8_ARRAY_SIZE(size) ((5*(size))/2)
332 
334 #define UTF8_GET_CHAR_UNSAFE(s, i, c) { \
335  int32_t _utf8_get_char_unsafe_index=(int32_t)(i); \
336  UTF8_SET_CHAR_START_UNSAFE(s, _utf8_get_char_unsafe_index); \
337  UTF8_NEXT_CHAR_UNSAFE(s, _utf8_get_char_unsafe_index, c); \
338 }
339 
341 #define UTF8_GET_CHAR_SAFE(s, start, i, length, c, strict) { \
342  int32_t _utf8_get_char_safe_index=(int32_t)(i); \
343  UTF8_SET_CHAR_START_SAFE(s, start, _utf8_get_char_safe_index); \
344  UTF8_NEXT_CHAR_SAFE(s, _utf8_get_char_safe_index, length, c, strict); \
345 }
346 
348 #define UTF8_NEXT_CHAR_UNSAFE(s, i, c) { \
349  (c)=(s)[(i)++]; \
350  if((uint8_t)((c)-0xc0)<0x35) { \
351  uint8_t __count=UTF8_COUNT_TRAIL_BYTES(c); \
352  UTF8_MASK_LEAD_BYTE(c, __count); \
353  switch(__count) { \
354  /* each following branch falls through to the next one */ \
355  case 3: \
356  (c)=((c)<<6)|((s)[(i)++]&0x3f); \
357  case 2: \
358  (c)=((c)<<6)|((s)[(i)++]&0x3f); \
359  case 1: \
360  (c)=((c)<<6)|((s)[(i)++]&0x3f); \
361  /* no other branches to optimize switch() */ \
362  break; \
363  } \
364  } \
365 }
366 
368 #define UTF8_APPEND_CHAR_UNSAFE(s, i, c) { \
369  if((uint32_t)(c)<=0x7f) { \
370  (s)[(i)++]=(uint8_t)(c); \
371  } else { \
372  if((uint32_t)(c)<=0x7ff) { \
373  (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
374  } else { \
375  if((uint32_t)(c)<=0xffff) { \
376  (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
377  } else { \
378  (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \
379  (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \
380  } \
381  (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
382  } \
383  (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
384  } \
385 }
386 
388 #define UTF8_FWD_1_UNSAFE(s, i) { \
389  (i)+=1+UTF8_COUNT_TRAIL_BYTES((s)[i]); \
390 }
391 
393 #define UTF8_FWD_N_UNSAFE(s, i, n) { \
394  int32_t __N=(n); \
395  while(__N>0) { \
396  UTF8_FWD_1_UNSAFE(s, i); \
397  --__N; \
398  } \
399 }
400 
402 #define UTF8_SET_CHAR_START_UNSAFE(s, i) { \
403  while(UTF8_IS_TRAIL((s)[i])) { --(i); } \
404 }
405 
407 #define UTF8_NEXT_CHAR_SAFE(s, i, length, c, strict) { \
408  (c)=(s)[(i)++]; \
409  if((c)>=0x80) { \
410  if(UTF8_IS_LEAD(c)) { \
411  (c)=utf8_nextCharSafeBody(s, &(i), (int32_t)(length), c, strict); \
412  } else { \
413  (c)=UTF8_ERROR_VALUE_1; \
414  } \
415  } \
416 }
417 
419 #define UTF8_APPEND_CHAR_SAFE(s, i, length, c) { \
420  if((uint32_t)(c)<=0x7f) { \
421  (s)[(i)++]=(uint8_t)(c); \
422  } else { \
423  (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(length), c, NULL); \
424  } \
425 }
426 
428 #define UTF8_FWD_1_SAFE(s, i, length) U8_FWD_1(s, i, length)
429 
431 #define UTF8_FWD_N_SAFE(s, i, length, n) U8_FWD_N(s, i, length, n)
432 
434 #define UTF8_SET_CHAR_START_SAFE(s, start, i) U8_SET_CP_START(s, start, i)
435 
437 #define UTF8_PREV_CHAR_UNSAFE(s, i, c) { \
438  (c)=(s)[--(i)]; \
439  if(UTF8_IS_TRAIL(c)) { \
440  uint8_t __b, __count=1, __shift=6; \
441 \
442  /* c is a trail byte */ \
443  (c)&=0x3f; \
444  for(;;) { \
445  __b=(s)[--(i)]; \
446  if(__b>=0xc0) { \
447  UTF8_MASK_LEAD_BYTE(__b, __count); \
448  (c)|=(UChar32)__b<<__shift; \
449  break; \
450  } else { \
451  (c)|=(UChar32)(__b&0x3f)<<__shift; \
452  ++__count; \
453  __shift+=6; \
454  } \
455  } \
456  } \
457 }
458 
460 #define UTF8_BACK_1_UNSAFE(s, i) { \
461  while(UTF8_IS_TRAIL((s)[--(i)])) {} \
462 }
463 
465 #define UTF8_BACK_N_UNSAFE(s, i, n) { \
466  int32_t __N=(n); \
467  while(__N>0) { \
468  UTF8_BACK_1_UNSAFE(s, i); \
469  --__N; \
470  } \
471 }
472 
474 #define UTF8_SET_CHAR_LIMIT_UNSAFE(s, i) { \
475  UTF8_BACK_1_UNSAFE(s, i); \
476  UTF8_FWD_1_UNSAFE(s, i); \
477 }
478 
480 #define UTF8_PREV_CHAR_SAFE(s, start, i, c, strict) { \
481  (c)=(s)[--(i)]; \
482  if((c)>=0x80) { \
483  if((c)<=0xbf) { \
484  (c)=utf8_prevCharSafeBody(s, start, &(i), c, strict); \
485  } else { \
486  (c)=UTF8_ERROR_VALUE_1; \
487  } \
488  } \
489 }
490 
492 #define UTF8_BACK_1_SAFE(s, start, i) U8_BACK_1(s, start, i)
493 
495 #define UTF8_BACK_N_SAFE(s, start, i, n) U8_BACK_N(s, start, i, n)
496 
498 #define UTF8_SET_CHAR_LIMIT_SAFE(s, start, i, length) U8_SET_CP_LIMIT(s, start, i, length)
499 
500 /* Formerly utf16.h --------------------------------------------------------- */
501 
503 #define UTF_IS_FIRST_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xd800)
504 
506 #define UTF_IS_SECOND_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xdc00)
507 
509 #define UTF_IS_SURROGATE_FIRST(c) (((c)&0x400)==0)
510 
512 #define UTF_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
513 
515 #define UTF16_GET_PAIR_VALUE(first, second) \
516  (((first)<<10UL)+(second)-UTF_SURROGATE_OFFSET)
517 
519 #define UTF_FIRST_SURROGATE(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
520 
522 #define UTF_SECOND_SURROGATE(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
523 
525 #define UTF16_LEAD(supplementary) UTF_FIRST_SURROGATE(supplementary)
526 
528 #define UTF16_TRAIL(supplementary) UTF_SECOND_SURROGATE(supplementary)
529 
531 #define UTF16_IS_SINGLE(uchar) !UTF_IS_SURROGATE(uchar)
532 
534 #define UTF16_IS_LEAD(uchar) UTF_IS_FIRST_SURROGATE(uchar)
535 
537 #define UTF16_IS_TRAIL(uchar) UTF_IS_SECOND_SURROGATE(uchar)
538 
540 #define UTF16_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0xffff)
541 
543 #define UTF16_CHAR_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
544 
546 #define UTF16_MAX_CHAR_LENGTH 2
547 
549 #define UTF16_ARRAY_SIZE(size) (size)
550 
562 #define UTF16_GET_CHAR_UNSAFE(s, i, c) { \
563  (c)=(s)[i]; \
564  if(UTF_IS_SURROGATE(c)) { \
565  if(UTF_IS_SURROGATE_FIRST(c)) { \
566  (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)+1]); \
567  } else { \
568  (c)=UTF16_GET_PAIR_VALUE((s)[(i)-1], (c)); \
569  } \
570  } \
571 }
572 
574 #define UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict) { \
575  (c)=(s)[i]; \
576  if(UTF_IS_SURROGATE(c)) { \
577  uint16_t __c2; \
578  if(UTF_IS_SURROGATE_FIRST(c)) { \
579  if((i)+1<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)+1])) { \
580  (c)=UTF16_GET_PAIR_VALUE((c), __c2); \
581  /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
582  } else if(strict) {\
583  /* unmatched first surrogate */ \
584  (c)=UTF_ERROR_VALUE; \
585  } \
586  } else { \
587  if((i)-1>=(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \
588  (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \
589  /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
590  } else if(strict) {\
591  /* unmatched second surrogate */ \
592  (c)=UTF_ERROR_VALUE; \
593  } \
594  } \
595  } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
596  (c)=UTF_ERROR_VALUE; \
597  } \
598 }
599 
601 #define UTF16_NEXT_CHAR_UNSAFE(s, i, c) { \
602  (c)=(s)[(i)++]; \
603  if(UTF_IS_FIRST_SURROGATE(c)) { \
604  (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)++]); \
605  } \
606 }
607 
609 #define UTF16_APPEND_CHAR_UNSAFE(s, i, c) { \
610  if((uint32_t)(c)<=0xffff) { \
611  (s)[(i)++]=(uint16_t)(c); \
612  } else { \
613  (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
614  (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
615  } \
616 }
617 
619 #define UTF16_FWD_1_UNSAFE(s, i) { \
620  if(UTF_IS_FIRST_SURROGATE((s)[(i)++])) { \
621  ++(i); \
622  } \
623 }
624 
626 #define UTF16_FWD_N_UNSAFE(s, i, n) { \
627  int32_t __N=(n); \
628  while(__N>0) { \
629  UTF16_FWD_1_UNSAFE(s, i); \
630  --__N; \
631  } \
632 }
633 
635 #define UTF16_SET_CHAR_START_UNSAFE(s, i) { \
636  if(UTF_IS_SECOND_SURROGATE((s)[i])) { \
637  --(i); \
638  } \
639 }
640 
642 #define UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) { \
643  (c)=(s)[(i)++]; \
644  if(UTF_IS_FIRST_SURROGATE(c)) { \
645  uint16_t __c2; \
646  if((i)<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)])) { \
647  ++(i); \
648  (c)=UTF16_GET_PAIR_VALUE((c), __c2); \
649  /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
650  } else if(strict) {\
651  /* unmatched first surrogate */ \
652  (c)=UTF_ERROR_VALUE; \
653  } \
654  } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
655  /* unmatched second surrogate or other non-character */ \
656  (c)=UTF_ERROR_VALUE; \
657  } \
658 }
659 
661 #define UTF16_APPEND_CHAR_SAFE(s, i, length, c) { \
662  if((uint32_t)(c)<=0xffff) { \
663  (s)[(i)++]=(uint16_t)(c); \
664  } else if((uint32_t)(c)<=0x10ffff) { \
665  if((i)+1<(length)) { \
666  (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
667  (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
668  } else /* not enough space */ { \
669  (s)[(i)++]=UTF_ERROR_VALUE; \
670  } \
671  } else /* c>0x10ffff, write error value */ { \
672  (s)[(i)++]=UTF_ERROR_VALUE; \
673  } \
674 }
675 
677 #define UTF16_FWD_1_SAFE(s, i, length) U16_FWD_1(s, i, length)
678 
680 #define UTF16_FWD_N_SAFE(s, i, length, n) U16_FWD_N(s, i, length, n)
681 
683 #define UTF16_SET_CHAR_START_SAFE(s, start, i) U16_SET_CP_START(s, start, i)
684 
686 #define UTF16_PREV_CHAR_UNSAFE(s, i, c) { \
687  (c)=(s)[--(i)]; \
688  if(UTF_IS_SECOND_SURROGATE(c)) { \
689  (c)=UTF16_GET_PAIR_VALUE((s)[--(i)], (c)); \
690  } \
691 }
692 
694 #define UTF16_BACK_1_UNSAFE(s, i) { \
695  if(UTF_IS_SECOND_SURROGATE((s)[--(i)])) { \
696  --(i); \
697  } \
698 }
699 
701 #define UTF16_BACK_N_UNSAFE(s, i, n) { \
702  int32_t __N=(n); \
703  while(__N>0) { \
704  UTF16_BACK_1_UNSAFE(s, i); \
705  --__N; \
706  } \
707 }
708 
710 #define UTF16_SET_CHAR_LIMIT_UNSAFE(s, i) { \
711  if(UTF_IS_FIRST_SURROGATE((s)[(i)-1])) { \
712  ++(i); \
713  } \
714 }
715 
717 #define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) { \
718  (c)=(s)[--(i)]; \
719  if(UTF_IS_SECOND_SURROGATE(c)) { \
720  uint16_t __c2; \
721  if((i)>(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \
722  --(i); \
723  (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \
724  /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
725  } else if(strict) {\
726  /* unmatched second surrogate */ \
727  (c)=UTF_ERROR_VALUE; \
728  } \
729  } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
730  /* unmatched first surrogate or other non-character */ \
731  (c)=UTF_ERROR_VALUE; \
732  } \
733 }
734 
736 #define UTF16_BACK_1_SAFE(s, start, i) U16_BACK_1(s, start, i)
737 
739 #define UTF16_BACK_N_SAFE(s, start, i, n) U16_BACK_N(s, start, i, n)
740 
742 #define UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length)
743 
744 /* Formerly utf32.h --------------------------------------------------------- */
745 
746 /*
747 * Old documentation:
748 *
749 * This file defines macros to deal with UTF-32 code units and code points.
750 * Signatures and semantics are the same as for the similarly named macros
751 * in utf16.h.
752 * utf32.h is included by utf.h after unicode/umachine.h</p>
753 * and some common definitions.
754 * <p><b>Usage:</b> ICU coding guidelines for if() statements should be followed when using these macros.
755 * Compound statements (curly braces {}) must be used for if-else-while...
756 * bodies and all macro statements should be terminated with semicolon.</p>
757 */
758 
759 /* internal definitions ----------------------------------------------------- */
760 
762 #define UTF32_IS_SAFE(c, strict) \
763  (!(strict) ? \
764  (uint32_t)(c)<=0x10ffff : \
765  UTF_IS_UNICODE_CHAR(c))
766 
767 /*
768  * For the semantics of all of these macros, see utf16.h.
769  * The UTF-32 versions are trivial because any code point is
770  * encoded using exactly one code unit.
771  */
772 
773 /* single-code point definitions -------------------------------------------- */
774 
775 /* classes of code unit values */
776 
778 #define UTF32_IS_SINGLE(uchar) 1
779 
780 #define UTF32_IS_LEAD(uchar) 0
781 
782 #define UTF32_IS_TRAIL(uchar) 0
783 
784 /* number of code units per code point */
785 
787 #define UTF32_NEED_MULTIPLE_UCHAR(c) 0
788 
789 #define UTF32_CHAR_LENGTH(c) 1
790 
791 #define UTF32_MAX_CHAR_LENGTH 1
792 
793 /* average number of code units compared to UTF-16 */
794 
796 #define UTF32_ARRAY_SIZE(size) (size)
797 
799 #define UTF32_GET_CHAR_UNSAFE(s, i, c) { \
800  (c)=(s)[i]; \
801 }
802 
804 #define UTF32_GET_CHAR_SAFE(s, start, i, length, c, strict) { \
805  (c)=(s)[i]; \
806  if(!UTF32_IS_SAFE(c, strict)) { \
807  (c)=UTF_ERROR_VALUE; \
808  } \
809 }
810 
811 /* definitions with forward iteration --------------------------------------- */
812 
814 #define UTF32_NEXT_CHAR_UNSAFE(s, i, c) { \
815  (c)=(s)[(i)++]; \
816 }
817 
819 #define UTF32_APPEND_CHAR_UNSAFE(s, i, c) { \
820  (s)[(i)++]=(c); \
821 }
822 
824 #define UTF32_FWD_1_UNSAFE(s, i) { \
825  ++(i); \
826 }
827 
829 #define UTF32_FWD_N_UNSAFE(s, i, n) { \
830  (i)+=(n); \
831 }
832 
834 #define UTF32_SET_CHAR_START_UNSAFE(s, i) { \
835 }
836 
838 #define UTF32_NEXT_CHAR_SAFE(s, i, length, c, strict) { \
839  (c)=(s)[(i)++]; \
840  if(!UTF32_IS_SAFE(c, strict)) { \
841  (c)=UTF_ERROR_VALUE; \
842  } \
843 }
844 
846 #define UTF32_APPEND_CHAR_SAFE(s, i, length, c) { \
847  if((uint32_t)(c)<=0x10ffff) { \
848  (s)[(i)++]=(c); \
849  } else /* c>0x10ffff, write 0xfffd */ { \
850  (s)[(i)++]=0xfffd; \
851  } \
852 }
853 
855 #define UTF32_FWD_1_SAFE(s, i, length) { \
856  ++(i); \
857 }
858 
860 #define UTF32_FWD_N_SAFE(s, i, length, n) { \
861  if(((i)+=(n))>(length)) { \
862  (i)=(length); \
863  } \
864 }
865 
867 #define UTF32_SET_CHAR_START_SAFE(s, start, i) { \
868 }
869 
870 /* definitions with backward iteration -------------------------------------- */
871 
873 #define UTF32_PREV_CHAR_UNSAFE(s, i, c) { \
874  (c)=(s)[--(i)]; \
875 }
876 
878 #define UTF32_BACK_1_UNSAFE(s, i) { \
879  --(i); \
880 }
881 
883 #define UTF32_BACK_N_UNSAFE(s, i, n) { \
884  (i)-=(n); \
885 }
886 
888 #define UTF32_SET_CHAR_LIMIT_UNSAFE(s, i) { \
889 }
890 
892 #define UTF32_PREV_CHAR_SAFE(s, start, i, c, strict) { \
893  (c)=(s)[--(i)]; \
894  if(!UTF32_IS_SAFE(c, strict)) { \
895  (c)=UTF_ERROR_VALUE; \
896  } \
897 }
898 
900 #define UTF32_BACK_1_SAFE(s, start, i) { \
901  --(i); \
902 }
903 
905 #define UTF32_BACK_N_SAFE(s, start, i, n) { \
906  (i)-=(n); \
907  if((i)<(start)) { \
908  (i)=(start); \
909  } \
910 }
911 
913 #define UTF32_SET_CHAR_LIMIT_SAFE(s, i, length) { \
914 }
915 
916 /* Formerly utf.h, part 2 --------------------------------------------------- */
917 
923 #define UTF_ARRAY_SIZE(size) UTF16_ARRAY_SIZE(size)
924 
926 #define UTF_GET_CHAR_UNSAFE(s, i, c) UTF16_GET_CHAR_UNSAFE(s, i, c)
927 
929 #define UTF_GET_CHAR_SAFE(s, start, i, length, c, strict) UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict)
930 
931 
933 #define UTF_NEXT_CHAR_UNSAFE(s, i, c) UTF16_NEXT_CHAR_UNSAFE(s, i, c)
934 
936 #define UTF_NEXT_CHAR_SAFE(s, i, length, c, strict) UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict)
937 
938 
940 #define UTF_APPEND_CHAR_UNSAFE(s, i, c) UTF16_APPEND_CHAR_UNSAFE(s, i, c)
941 
943 #define UTF_APPEND_CHAR_SAFE(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c)
944 
945 
947 #define UTF_FWD_1_UNSAFE(s, i) UTF16_FWD_1_UNSAFE(s, i)
948 
950 #define UTF_FWD_1_SAFE(s, i, length) UTF16_FWD_1_SAFE(s, i, length)
951 
952 
954 #define UTF_FWD_N_UNSAFE(s, i, n) UTF16_FWD_N_UNSAFE(s, i, n)
955 
957 #define UTF_FWD_N_SAFE(s, i, length, n) UTF16_FWD_N_SAFE(s, i, length, n)
958 
959 
961 #define UTF_SET_CHAR_START_UNSAFE(s, i) UTF16_SET_CHAR_START_UNSAFE(s, i)
962 
964 #define UTF_SET_CHAR_START_SAFE(s, start, i) UTF16_SET_CHAR_START_SAFE(s, start, i)
965 
966 
968 #define UTF_PREV_CHAR_UNSAFE(s, i, c) UTF16_PREV_CHAR_UNSAFE(s, i, c)
969 
971 #define UTF_PREV_CHAR_SAFE(s, start, i, c, strict) UTF16_PREV_CHAR_SAFE(s, start, i, c, strict)
972 
973 
975 #define UTF_BACK_1_UNSAFE(s, i) UTF16_BACK_1_UNSAFE(s, i)
976 
978 #define UTF_BACK_1_SAFE(s, start, i) UTF16_BACK_1_SAFE(s, start, i)
979 
980 
982 #define UTF_BACK_N_UNSAFE(s, i, n) UTF16_BACK_N_UNSAFE(s, i, n)
983 
985 #define UTF_BACK_N_SAFE(s, start, i, n) UTF16_BACK_N_SAFE(s, start, i, n)
986 
987 
989 #define UTF_SET_CHAR_LIMIT_UNSAFE(s, i) UTF16_SET_CHAR_LIMIT_UNSAFE(s, i)
990 
992 #define UTF_SET_CHAR_LIMIT_SAFE(s, start, i, length) UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length)
993 
994 /* Define default macros (UTF-16 "safe") ------------------------------------ */
995 
1001 #define UTF_IS_SINGLE(uchar) U16_IS_SINGLE(uchar)
1002 
1008 #define UTF_IS_LEAD(uchar) U16_IS_LEAD(uchar)
1009 
1015 #define UTF_IS_TRAIL(uchar) U16_IS_TRAIL(uchar)
1016 
1022 #define UTF_NEED_MULTIPLE_UCHAR(c) UTF16_NEED_MULTIPLE_UCHAR(c)
1023 
1029 #define UTF_CHAR_LENGTH(c) U16_LENGTH(c)
1030 
1036 #define UTF_MAX_CHAR_LENGTH U16_MAX_LENGTH
1037 
1047 #define UTF_GET_CHAR(s, start, i, length, c) U16_GET(s, start, i, length, c)
1048 
1060 #define UTF_NEXT_CHAR(s, i, length, c) U16_NEXT(s, i, length, c)
1061 
1073 #define UTF_APPEND_CHAR(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c)
1074 
1084 #define UTF_FWD_1(s, i, length) U16_FWD_1(s, i, length)
1085 
1095 #define UTF_FWD_N(s, i, length, n) U16_FWD_N(s, i, length, n)
1096 
1111 #define UTF_SET_CHAR_START(s, start, i) U16_SET_CP_START(s, start, i)
1112 
1124 #define UTF_PREV_CHAR(s, start, i, c) U16_PREV(s, start, i, c)
1125 
1137 #define UTF_BACK_1(s, start, i) U16_BACK_1(s, start, i)
1138 
1150 #define UTF_BACK_N(s, start, i, n) U16_BACK_N(s, start, i, n)
1151 
1166 #define UTF_SET_CHAR_LIMIT(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length)
1167 
1168 #endif /* U_HIDE_DEPRECATED_API */
1169 
1170 #endif
1171 
C API: 8-bit Unicode handling macros.
C API: Code point macros.
C API: 16-bit Unicode handling macros.