ICU 59.1  59.1
utf_old.h
Go to the documentation of this file.
1 // © 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: UTF-8
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 
281 #ifdef U_UTF8_IMPL
282 // No forward declaration if compiling utf_impl.cpp, which defines utf8_countTrailBytes.
283 #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION)
284 U_CFUNC const uint8_t utf8_countTrailBytes[];
285 #else
286 U_CFUNC U_IMPORT const uint8_t utf8_countTrailBytes[]; /* U_IMPORT2? */ /*U_IMPORT*/
287 #endif
288 
293 #define UTF8_COUNT_TRAIL_BYTES(leadByte) (utf8_countTrailBytes[(uint8_t)leadByte])
294 
299 #define UTF8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1)
300 
302 #define UTF8_IS_SINGLE(uchar) (((uchar)&0x80)==0)
303 
304 #define UTF8_IS_LEAD(uchar) ((uint8_t)((uchar)-0xc0)<0x3e)
305 
306 #define UTF8_IS_TRAIL(uchar) (((uchar)&0xc0)==0x80)
307 
309 #define UTF8_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0x7f)
310 
324 #if 1
325 # define UTF8_CHAR_LENGTH(c) \
326  ((uint32_t)(c)<=0x7f ? 1 : \
327  ((uint32_t)(c)<=0x7ff ? 2 : \
328  ((uint32_t)((c)-0x10000)>0xfffff ? 3 : 4) \
329  ) \
330  )
331 #else
332 # define UTF8_CHAR_LENGTH(c) \
333  ((uint32_t)(c)<=0x7f ? 1 : \
334  ((uint32_t)(c)<=0x7ff ? 2 : \
335  ((uint32_t)(c)<=0xffff ? 3 : \
336  ((uint32_t)(c)<=0x10ffff ? 4 : \
337  ((uint32_t)(c)<=0x3ffffff ? 5 : \
338  ((uint32_t)(c)<=0x7fffffff ? 6 : 3) \
339  ) \
340  ) \
341  ) \
342  ) \
343  )
344 #endif
345 
347 #define UTF8_MAX_CHAR_LENGTH 4
348 
350 #define UTF8_ARRAY_SIZE(size) ((5*(size))/2)
351 
353 #define UTF8_GET_CHAR_UNSAFE(s, i, c) { \
354  int32_t _utf8_get_char_unsafe_index=(int32_t)(i); \
355  UTF8_SET_CHAR_START_UNSAFE(s, _utf8_get_char_unsafe_index); \
356  UTF8_NEXT_CHAR_UNSAFE(s, _utf8_get_char_unsafe_index, c); \
357 }
358 
360 #define UTF8_GET_CHAR_SAFE(s, start, i, length, c, strict) { \
361  int32_t _utf8_get_char_safe_index=(int32_t)(i); \
362  UTF8_SET_CHAR_START_SAFE(s, start, _utf8_get_char_safe_index); \
363  UTF8_NEXT_CHAR_SAFE(s, _utf8_get_char_safe_index, length, c, strict); \
364 }
365 
367 #define UTF8_NEXT_CHAR_UNSAFE(s, i, c) { \
368  (c)=(s)[(i)++]; \
369  if((uint8_t)((c)-0xc0)<0x35) { \
370  uint8_t __count=UTF8_COUNT_TRAIL_BYTES(c); \
371  UTF8_MASK_LEAD_BYTE(c, __count); \
372  switch(__count) { \
373  /* each following branch falls through to the next one */ \
374  case 3: \
375  (c)=((c)<<6)|((s)[(i)++]&0x3f); \
376  case 2: \
377  (c)=((c)<<6)|((s)[(i)++]&0x3f); \
378  case 1: \
379  (c)=((c)<<6)|((s)[(i)++]&0x3f); \
380  /* no other branches to optimize switch() */ \
381  break; \
382  } \
383  } \
384 }
385 
387 #define UTF8_APPEND_CHAR_UNSAFE(s, i, c) { \
388  if((uint32_t)(c)<=0x7f) { \
389  (s)[(i)++]=(uint8_t)(c); \
390  } else { \
391  if((uint32_t)(c)<=0x7ff) { \
392  (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \
393  } else { \
394  if((uint32_t)(c)<=0xffff) { \
395  (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \
396  } else { \
397  (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \
398  (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \
399  } \
400  (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \
401  } \
402  (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \
403  } \
404 }
405 
407 #define UTF8_FWD_1_UNSAFE(s, i) { \
408  (i)+=1+UTF8_COUNT_TRAIL_BYTES((s)[i]); \
409 }
410 
412 #define UTF8_FWD_N_UNSAFE(s, i, n) { \
413  int32_t __N=(n); \
414  while(__N>0) { \
415  UTF8_FWD_1_UNSAFE(s, i); \
416  --__N; \
417  } \
418 }
419 
421 #define UTF8_SET_CHAR_START_UNSAFE(s, i) { \
422  while(UTF8_IS_TRAIL((s)[i])) { --(i); } \
423 }
424 
426 #define UTF8_NEXT_CHAR_SAFE(s, i, length, c, strict) { \
427  (c)=(s)[(i)++]; \
428  if((c)>=0x80) { \
429  if(UTF8_IS_LEAD(c)) { \
430  (c)=utf8_nextCharSafeBody(s, &(i), (int32_t)(length), c, strict); \
431  } else { \
432  (c)=UTF8_ERROR_VALUE_1; \
433  } \
434  } \
435 }
436 
438 #define UTF8_APPEND_CHAR_SAFE(s, i, length, c) { \
439  if((uint32_t)(c)<=0x7f) { \
440  (s)[(i)++]=(uint8_t)(c); \
441  } else { \
442  (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(length), c, NULL); \
443  } \
444 }
445 
447 #define UTF8_FWD_1_SAFE(s, i, length) U8_FWD_1(s, i, length)
448 
450 #define UTF8_FWD_N_SAFE(s, i, length, n) U8_FWD_N(s, i, length, n)
451 
453 #define UTF8_SET_CHAR_START_SAFE(s, start, i) U8_SET_CP_START(s, start, i)
454 
456 #define UTF8_PREV_CHAR_UNSAFE(s, i, c) { \
457  (c)=(s)[--(i)]; \
458  if(UTF8_IS_TRAIL(c)) { \
459  uint8_t __b, __count=1, __shift=6; \
460 \
461  /* c is a trail byte */ \
462  (c)&=0x3f; \
463  for(;;) { \
464  __b=(s)[--(i)]; \
465  if(__b>=0xc0) { \
466  UTF8_MASK_LEAD_BYTE(__b, __count); \
467  (c)|=(UChar32)__b<<__shift; \
468  break; \
469  } else { \
470  (c)|=(UChar32)(__b&0x3f)<<__shift; \
471  ++__count; \
472  __shift+=6; \
473  } \
474  } \
475  } \
476 }
477 
479 #define UTF8_BACK_1_UNSAFE(s, i) { \
480  while(UTF8_IS_TRAIL((s)[--(i)])) {} \
481 }
482 
484 #define UTF8_BACK_N_UNSAFE(s, i, n) { \
485  int32_t __N=(n); \
486  while(__N>0) { \
487  UTF8_BACK_1_UNSAFE(s, i); \
488  --__N; \
489  } \
490 }
491 
493 #define UTF8_SET_CHAR_LIMIT_UNSAFE(s, i) { \
494  UTF8_BACK_1_UNSAFE(s, i); \
495  UTF8_FWD_1_UNSAFE(s, i); \
496 }
497 
499 #define UTF8_PREV_CHAR_SAFE(s, start, i, c, strict) { \
500  (c)=(s)[--(i)]; \
501  if((c)>=0x80) { \
502  if((c)<=0xbf) { \
503  (c)=utf8_prevCharSafeBody(s, start, &(i), c, strict); \
504  } else { \
505  (c)=UTF8_ERROR_VALUE_1; \
506  } \
507  } \
508 }
509 
511 #define UTF8_BACK_1_SAFE(s, start, i) U8_BACK_1(s, start, i)
512 
514 #define UTF8_BACK_N_SAFE(s, start, i, n) U8_BACK_N(s, start, i, n)
515 
517 #define UTF8_SET_CHAR_LIMIT_SAFE(s, start, i, length) U8_SET_CP_LIMIT(s, start, i, length)
518 
519 /* Formerly utf16.h --------------------------------------------------------- */
520 
522 #define UTF_IS_FIRST_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xd800)
523 
525 #define UTF_IS_SECOND_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xdc00)
526 
528 #define UTF_IS_SURROGATE_FIRST(c) (((c)&0x400)==0)
529 
531 #define UTF_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000)
532 
534 #define UTF16_GET_PAIR_VALUE(first, second) \
535  (((first)<<10UL)+(second)-UTF_SURROGATE_OFFSET)
536 
538 #define UTF_FIRST_SURROGATE(supplementary) (UChar)(((supplementary)>>10)+0xd7c0)
539 
541 #define UTF_SECOND_SURROGATE(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00)
542 
544 #define UTF16_LEAD(supplementary) UTF_FIRST_SURROGATE(supplementary)
545 
547 #define UTF16_TRAIL(supplementary) UTF_SECOND_SURROGATE(supplementary)
548 
550 #define UTF16_IS_SINGLE(uchar) !UTF_IS_SURROGATE(uchar)
551 
553 #define UTF16_IS_LEAD(uchar) UTF_IS_FIRST_SURROGATE(uchar)
554 
556 #define UTF16_IS_TRAIL(uchar) UTF_IS_SECOND_SURROGATE(uchar)
557 
559 #define UTF16_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0xffff)
560 
562 #define UTF16_CHAR_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2)
563 
565 #define UTF16_MAX_CHAR_LENGTH 2
566 
568 #define UTF16_ARRAY_SIZE(size) (size)
569 
581 #define UTF16_GET_CHAR_UNSAFE(s, i, c) { \
582  (c)=(s)[i]; \
583  if(UTF_IS_SURROGATE(c)) { \
584  if(UTF_IS_SURROGATE_FIRST(c)) { \
585  (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)+1]); \
586  } else { \
587  (c)=UTF16_GET_PAIR_VALUE((s)[(i)-1], (c)); \
588  } \
589  } \
590 }
591 
593 #define UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict) { \
594  (c)=(s)[i]; \
595  if(UTF_IS_SURROGATE(c)) { \
596  uint16_t __c2; \
597  if(UTF_IS_SURROGATE_FIRST(c)) { \
598  if((i)+1<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)+1])) { \
599  (c)=UTF16_GET_PAIR_VALUE((c), __c2); \
600  /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
601  } else if(strict) {\
602  /* unmatched first surrogate */ \
603  (c)=UTF_ERROR_VALUE; \
604  } \
605  } else { \
606  if((i)-1>=(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \
607  (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \
608  /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
609  } else if(strict) {\
610  /* unmatched second surrogate */ \
611  (c)=UTF_ERROR_VALUE; \
612  } \
613  } \
614  } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
615  (c)=UTF_ERROR_VALUE; \
616  } \
617 }
618 
620 #define UTF16_NEXT_CHAR_UNSAFE(s, i, c) { \
621  (c)=(s)[(i)++]; \
622  if(UTF_IS_FIRST_SURROGATE(c)) { \
623  (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)++]); \
624  } \
625 }
626 
628 #define UTF16_APPEND_CHAR_UNSAFE(s, i, c) { \
629  if((uint32_t)(c)<=0xffff) { \
630  (s)[(i)++]=(uint16_t)(c); \
631  } else { \
632  (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
633  (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
634  } \
635 }
636 
638 #define UTF16_FWD_1_UNSAFE(s, i) { \
639  if(UTF_IS_FIRST_SURROGATE((s)[(i)++])) { \
640  ++(i); \
641  } \
642 }
643 
645 #define UTF16_FWD_N_UNSAFE(s, i, n) { \
646  int32_t __N=(n); \
647  while(__N>0) { \
648  UTF16_FWD_1_UNSAFE(s, i); \
649  --__N; \
650  } \
651 }
652 
654 #define UTF16_SET_CHAR_START_UNSAFE(s, i) { \
655  if(UTF_IS_SECOND_SURROGATE((s)[i])) { \
656  --(i); \
657  } \
658 }
659 
661 #define UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) { \
662  (c)=(s)[(i)++]; \
663  if(UTF_IS_FIRST_SURROGATE(c)) { \
664  uint16_t __c2; \
665  if((i)<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)])) { \
666  ++(i); \
667  (c)=UTF16_GET_PAIR_VALUE((c), __c2); \
668  /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
669  } else if(strict) {\
670  /* unmatched first surrogate */ \
671  (c)=UTF_ERROR_VALUE; \
672  } \
673  } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
674  /* unmatched second surrogate or other non-character */ \
675  (c)=UTF_ERROR_VALUE; \
676  } \
677 }
678 
680 #define UTF16_APPEND_CHAR_SAFE(s, i, length, c) { \
681  if((uint32_t)(c)<=0xffff) { \
682  (s)[(i)++]=(uint16_t)(c); \
683  } else if((uint32_t)(c)<=0x10ffff) { \
684  if((i)+1<(length)) { \
685  (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \
686  (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \
687  } else /* not enough space */ { \
688  (s)[(i)++]=UTF_ERROR_VALUE; \
689  } \
690  } else /* c>0x10ffff, write error value */ { \
691  (s)[(i)++]=UTF_ERROR_VALUE; \
692  } \
693 }
694 
696 #define UTF16_FWD_1_SAFE(s, i, length) U16_FWD_1(s, i, length)
697 
699 #define UTF16_FWD_N_SAFE(s, i, length, n) U16_FWD_N(s, i, length, n)
700 
702 #define UTF16_SET_CHAR_START_SAFE(s, start, i) U16_SET_CP_START(s, start, i)
703 
705 #define UTF16_PREV_CHAR_UNSAFE(s, i, c) { \
706  (c)=(s)[--(i)]; \
707  if(UTF_IS_SECOND_SURROGATE(c)) { \
708  (c)=UTF16_GET_PAIR_VALUE((s)[--(i)], (c)); \
709  } \
710 }
711 
713 #define UTF16_BACK_1_UNSAFE(s, i) { \
714  if(UTF_IS_SECOND_SURROGATE((s)[--(i)])) { \
715  --(i); \
716  } \
717 }
718 
720 #define UTF16_BACK_N_UNSAFE(s, i, n) { \
721  int32_t __N=(n); \
722  while(__N>0) { \
723  UTF16_BACK_1_UNSAFE(s, i); \
724  --__N; \
725  } \
726 }
727 
729 #define UTF16_SET_CHAR_LIMIT_UNSAFE(s, i) { \
730  if(UTF_IS_FIRST_SURROGATE((s)[(i)-1])) { \
731  ++(i); \
732  } \
733 }
734 
736 #define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) { \
737  (c)=(s)[--(i)]; \
738  if(UTF_IS_SECOND_SURROGATE(c)) { \
739  uint16_t __c2; \
740  if((i)>(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \
741  --(i); \
742  (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \
743  /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \
744  } else if(strict) {\
745  /* unmatched second surrogate */ \
746  (c)=UTF_ERROR_VALUE; \
747  } \
748  } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \
749  /* unmatched first surrogate or other non-character */ \
750  (c)=UTF_ERROR_VALUE; \
751  } \
752 }
753 
755 #define UTF16_BACK_1_SAFE(s, start, i) U16_BACK_1(s, start, i)
756 
758 #define UTF16_BACK_N_SAFE(s, start, i, n) U16_BACK_N(s, start, i, n)
759 
761 #define UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length)
762 
763 /* Formerly utf32.h --------------------------------------------------------- */
764 
765 /*
766 * Old documentation:
767 *
768 * This file defines macros to deal with UTF-32 code units and code points.
769 * Signatures and semantics are the same as for the similarly named macros
770 * in utf16.h.
771 * utf32.h is included by utf.h after unicode/umachine.h</p>
772 * and some common definitions.
773 * <p><b>Usage:</b> ICU coding guidelines for if() statements should be followed when using these macros.
774 * Compound statements (curly braces {}) must be used for if-else-while...
775 * bodies and all macro statements should be terminated with semicolon.</p>
776 */
777 
778 /* internal definitions ----------------------------------------------------- */
779 
781 #define UTF32_IS_SAFE(c, strict) \
782  (!(strict) ? \
783  (uint32_t)(c)<=0x10ffff : \
784  UTF_IS_UNICODE_CHAR(c))
785 
786 /*
787  * For the semantics of all of these macros, see utf16.h.
788  * The UTF-32 versions are trivial because any code point is
789  * encoded using exactly one code unit.
790  */
791 
792 /* single-code point definitions -------------------------------------------- */
793 
794 /* classes of code unit values */
795 
797 #define UTF32_IS_SINGLE(uchar) 1
798 
799 #define UTF32_IS_LEAD(uchar) 0
800 
801 #define UTF32_IS_TRAIL(uchar) 0
802 
803 /* number of code units per code point */
804 
806 #define UTF32_NEED_MULTIPLE_UCHAR(c) 0
807 
808 #define UTF32_CHAR_LENGTH(c) 1
809 
810 #define UTF32_MAX_CHAR_LENGTH 1
811 
812 /* average number of code units compared to UTF-16 */
813 
815 #define UTF32_ARRAY_SIZE(size) (size)
816 
818 #define UTF32_GET_CHAR_UNSAFE(s, i, c) { \
819  (c)=(s)[i]; \
820 }
821 
823 #define UTF32_GET_CHAR_SAFE(s, start, i, length, c, strict) { \
824  (c)=(s)[i]; \
825  if(!UTF32_IS_SAFE(c, strict)) { \
826  (c)=UTF_ERROR_VALUE; \
827  } \
828 }
829 
830 /* definitions with forward iteration --------------------------------------- */
831 
833 #define UTF32_NEXT_CHAR_UNSAFE(s, i, c) { \
834  (c)=(s)[(i)++]; \
835 }
836 
838 #define UTF32_APPEND_CHAR_UNSAFE(s, i, c) { \
839  (s)[(i)++]=(c); \
840 }
841 
843 #define UTF32_FWD_1_UNSAFE(s, i) { \
844  ++(i); \
845 }
846 
848 #define UTF32_FWD_N_UNSAFE(s, i, n) { \
849  (i)+=(n); \
850 }
851 
853 #define UTF32_SET_CHAR_START_UNSAFE(s, i) { \
854 }
855 
857 #define UTF32_NEXT_CHAR_SAFE(s, i, length, c, strict) { \
858  (c)=(s)[(i)++]; \
859  if(!UTF32_IS_SAFE(c, strict)) { \
860  (c)=UTF_ERROR_VALUE; \
861  } \
862 }
863 
865 #define UTF32_APPEND_CHAR_SAFE(s, i, length, c) { \
866  if((uint32_t)(c)<=0x10ffff) { \
867  (s)[(i)++]=(c); \
868  } else /* c>0x10ffff, write 0xfffd */ { \
869  (s)[(i)++]=0xfffd; \
870  } \
871 }
872 
874 #define UTF32_FWD_1_SAFE(s, i, length) { \
875  ++(i); \
876 }
877 
879 #define UTF32_FWD_N_SAFE(s, i, length, n) { \
880  if(((i)+=(n))>(length)) { \
881  (i)=(length); \
882  } \
883 }
884 
886 #define UTF32_SET_CHAR_START_SAFE(s, start, i) { \
887 }
888 
889 /* definitions with backward iteration -------------------------------------- */
890 
892 #define UTF32_PREV_CHAR_UNSAFE(s, i, c) { \
893  (c)=(s)[--(i)]; \
894 }
895 
897 #define UTF32_BACK_1_UNSAFE(s, i) { \
898  --(i); \
899 }
900 
902 #define UTF32_BACK_N_UNSAFE(s, i, n) { \
903  (i)-=(n); \
904 }
905 
907 #define UTF32_SET_CHAR_LIMIT_UNSAFE(s, i) { \
908 }
909 
911 #define UTF32_PREV_CHAR_SAFE(s, start, i, c, strict) { \
912  (c)=(s)[--(i)]; \
913  if(!UTF32_IS_SAFE(c, strict)) { \
914  (c)=UTF_ERROR_VALUE; \
915  } \
916 }
917 
919 #define UTF32_BACK_1_SAFE(s, start, i) { \
920  --(i); \
921 }
922 
924 #define UTF32_BACK_N_SAFE(s, start, i, n) { \
925  (i)-=(n); \
926  if((i)<(start)) { \
927  (i)=(start); \
928  } \
929 }
930 
932 #define UTF32_SET_CHAR_LIMIT_SAFE(s, i, length) { \
933 }
934 
935 /* Formerly utf.h, part 2 --------------------------------------------------- */
936 
942 #define UTF_ARRAY_SIZE(size) UTF16_ARRAY_SIZE(size)
943 
945 #define UTF_GET_CHAR_UNSAFE(s, i, c) UTF16_GET_CHAR_UNSAFE(s, i, c)
946 
948 #define UTF_GET_CHAR_SAFE(s, start, i, length, c, strict) UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict)
949 
950 
952 #define UTF_NEXT_CHAR_UNSAFE(s, i, c) UTF16_NEXT_CHAR_UNSAFE(s, i, c)
953 
955 #define UTF_NEXT_CHAR_SAFE(s, i, length, c, strict) UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict)
956 
957 
959 #define UTF_APPEND_CHAR_UNSAFE(s, i, c) UTF16_APPEND_CHAR_UNSAFE(s, i, c)
960 
962 #define UTF_APPEND_CHAR_SAFE(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c)
963 
964 
966 #define UTF_FWD_1_UNSAFE(s, i) UTF16_FWD_1_UNSAFE(s, i)
967 
969 #define UTF_FWD_1_SAFE(s, i, length) UTF16_FWD_1_SAFE(s, i, length)
970 
971 
973 #define UTF_FWD_N_UNSAFE(s, i, n) UTF16_FWD_N_UNSAFE(s, i, n)
974 
976 #define UTF_FWD_N_SAFE(s, i, length, n) UTF16_FWD_N_SAFE(s, i, length, n)
977 
978 
980 #define UTF_SET_CHAR_START_UNSAFE(s, i) UTF16_SET_CHAR_START_UNSAFE(s, i)
981 
983 #define UTF_SET_CHAR_START_SAFE(s, start, i) UTF16_SET_CHAR_START_SAFE(s, start, i)
984 
985 
987 #define UTF_PREV_CHAR_UNSAFE(s, i, c) UTF16_PREV_CHAR_UNSAFE(s, i, c)
988 
990 #define UTF_PREV_CHAR_SAFE(s, start, i, c, strict) UTF16_PREV_CHAR_SAFE(s, start, i, c, strict)
991 
992 
994 #define UTF_BACK_1_UNSAFE(s, i) UTF16_BACK_1_UNSAFE(s, i)
995 
997 #define UTF_BACK_1_SAFE(s, start, i) UTF16_BACK_1_SAFE(s, start, i)
998 
999 
1001 #define UTF_BACK_N_UNSAFE(s, i, n) UTF16_BACK_N_UNSAFE(s, i, n)
1002 
1004 #define UTF_BACK_N_SAFE(s, start, i, n) UTF16_BACK_N_SAFE(s, start, i, n)
1005 
1006 
1008 #define UTF_SET_CHAR_LIMIT_UNSAFE(s, i) UTF16_SET_CHAR_LIMIT_UNSAFE(s, i)
1009 
1011 #define UTF_SET_CHAR_LIMIT_SAFE(s, start, i, length) UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length)
1012 
1013 /* Define default macros (UTF-16 "safe") ------------------------------------ */
1014 
1020 #define UTF_IS_SINGLE(uchar) U16_IS_SINGLE(uchar)
1021 
1027 #define UTF_IS_LEAD(uchar) U16_IS_LEAD(uchar)
1028 
1034 #define UTF_IS_TRAIL(uchar) U16_IS_TRAIL(uchar)
1035 
1041 #define UTF_NEED_MULTIPLE_UCHAR(c) UTF16_NEED_MULTIPLE_UCHAR(c)
1042 
1048 #define UTF_CHAR_LENGTH(c) U16_LENGTH(c)
1049 
1055 #define UTF_MAX_CHAR_LENGTH U16_MAX_LENGTH
1056 
1066 #define UTF_GET_CHAR(s, start, i, length, c) U16_GET(s, start, i, length, c)
1067 
1079 #define UTF_NEXT_CHAR(s, i, length, c) U16_NEXT(s, i, length, c)
1080 
1092 #define UTF_APPEND_CHAR(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c)
1093 
1103 #define UTF_FWD_1(s, i, length) U16_FWD_1(s, i, length)
1104 
1114 #define UTF_FWD_N(s, i, length, n) U16_FWD_N(s, i, length, n)
1115 
1130 #define UTF_SET_CHAR_START(s, start, i) U16_SET_CP_START(s, start, i)
1131 
1143 #define UTF_PREV_CHAR(s, start, i, c) U16_PREV(s, start, i, c)
1144 
1156 #define UTF_BACK_1(s, start, i) U16_BACK_1(s, start, i)
1157 
1169 #define UTF_BACK_N(s, start, i, n) U16_BACK_N(s, start, i, n)
1170 
1185 #define UTF_SET_CHAR_LIMIT(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length)
1186 
1187 #endif /* U_HIDE_DEPRECATED_API */
1188 
1189 #endif
1190 
#define U_IMPORT
Definition: platform.h:848
C API: 8-bit Unicode handling macros.
U_CFUNC U_IMPORT const uint8_t utf8_countTrailBytes[]
Internal array with numbers of trail bytes for any given byte used in lead byte position.
Definition: utf_old.h:286
C API: Code point macros.
#define U_CFUNC
This is used in a declaration of a library private ICU C function.
Definition: umachine.h:83
C API: 16-bit Unicode handling macros.