|
ICU 73.2
73.2
|
00001 // © 2016 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 /* 00004 ******************************************************************************* 00005 * 00006 * Copyright (C) 2002-2012, International Business Machines 00007 * Corporation and others. All Rights Reserved. 00008 * 00009 ******************************************************************************* 00010 * file name: utf_old.h 00011 * encoding: UTF-8 00012 * tab size: 8 (not used) 00013 * indentation:4 00014 * 00015 * created on: 2002sep21 00016 * created by: Markus W. Scherer 00017 */ 00018 00142 #ifndef __UTF_OLD_H__ 00143 #define __UTF_OLD_H__ 00144 00145 #include "unicode/utf.h" 00146 #include "unicode/utf8.h" 00147 #include "unicode/utf16.h" 00148 00160 #ifndef U_HIDE_OBSOLETE_UTF_OLD_H 00161 # define U_HIDE_OBSOLETE_UTF_OLD_H 0 00162 #endif 00163 00164 #if !defined(U_HIDE_DEPRECATED_API) && !U_HIDE_OBSOLETE_UTF_OLD_H 00165 00166 /* Formerly utf.h, part 1 --------------------------------------------------- */ 00167 00168 #ifdef U_USE_UTF_DEPRECATES 00169 00176 typedef int32_t UTextOffset; 00177 #endif 00178 00180 #define UTF_SIZE 16 00181 00188 #define UTF_SAFE 00189 00190 #undef UTF_UNSAFE 00191 00192 #undef UTF_STRICT 00193 00208 #define UTF8_ERROR_VALUE_1 0x15 00209 00215 #define UTF8_ERROR_VALUE_2 0x9f 00216 00223 #define UTF_ERROR_VALUE 0xffff 00224 00231 #define UTF_IS_ERROR(c) \ 00232 (((c)&0xfffe)==0xfffe || (c)==UTF8_ERROR_VALUE_1 || (c)==UTF8_ERROR_VALUE_2) 00233 00239 #define UTF_IS_VALID(c) \ 00240 (UTF_IS_UNICODE_CHAR(c) && \ 00241 (c)!=UTF8_ERROR_VALUE_1 && (c)!=UTF8_ERROR_VALUE_2) 00242 00247 #define UTF_IS_SURROGATE(uchar) (((uchar)&0xfffff800)==0xd800) 00248 00254 #define UTF_IS_UNICODE_NONCHAR(c) \ 00255 ((c)>=0xfdd0 && \ 00256 ((uint32_t)(c)<=0xfdef || ((c)&0xfffe)==0xfffe) && \ 00257 (uint32_t)(c)<=0x10ffff) 00258 00274 #define UTF_IS_UNICODE_CHAR(c) \ 00275 ((uint32_t)(c)<0xd800 || \ 00276 ((uint32_t)(c)>0xdfff && \ 00277 (uint32_t)(c)<=0x10ffff && \ 00278 !UTF_IS_UNICODE_NONCHAR(c))) 00279 00280 /* Formerly utf8.h ---------------------------------------------------------- */ 00281 00293 #ifdef U_UTF8_IMPL 00294 // No forward declaration if compiling utf_impl.cpp, which defines utf8_countTrailBytes. 00295 #elif defined(U_STATIC_IMPLEMENTATION) || defined(U_COMMON_IMPLEMENTATION) 00296 U_CAPI const uint8_t utf8_countTrailBytes[]; 00297 #else 00298 U_CFUNC U_IMPORT const uint8_t utf8_countTrailBytes[]; 00299 #endif 00300 00305 #define UTF8_COUNT_TRAIL_BYTES(leadByte) (utf8_countTrailBytes[(uint8_t)leadByte]) 00306 00311 #define UTF8_MASK_LEAD_BYTE(leadByte, countTrailBytes) ((leadByte)&=(1<<(6-(countTrailBytes)))-1) 00312 00314 #define UTF8_IS_SINGLE(uchar) (((uchar)&0x80)==0) 00315 00316 #define UTF8_IS_LEAD(uchar) ((uint8_t)((uchar)-0xc0)<0x3e) 00317 00318 #define UTF8_IS_TRAIL(uchar) (((uchar)&0xc0)==0x80) 00319 00321 #define UTF8_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0x7f) 00322 00336 #if 1 00337 # define UTF8_CHAR_LENGTH(c) \ 00338 ((uint32_t)(c)<=0x7f ? 1 : \ 00339 ((uint32_t)(c)<=0x7ff ? 2 : \ 00340 ((uint32_t)((c)-0x10000)>0xfffff ? 3 : 4) \ 00341 ) \ 00342 ) 00343 #else 00344 # define UTF8_CHAR_LENGTH(c) \ 00345 ((uint32_t)(c)<=0x7f ? 1 : \ 00346 ((uint32_t)(c)<=0x7ff ? 2 : \ 00347 ((uint32_t)(c)<=0xffff ? 3 : \ 00348 ((uint32_t)(c)<=0x10ffff ? 4 : \ 00349 ((uint32_t)(c)<=0x3ffffff ? 5 : \ 00350 ((uint32_t)(c)<=0x7fffffff ? 6 : 3) \ 00351 ) \ 00352 ) \ 00353 ) \ 00354 ) \ 00355 ) 00356 #endif 00357 00359 #define UTF8_MAX_CHAR_LENGTH 4 00360 00362 #define UTF8_ARRAY_SIZE(size) ((5*(size))/2) 00363 00365 #define UTF8_GET_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00366 int32_t _utf8_get_char_unsafe_index=(int32_t)(i); \ 00367 UTF8_SET_CHAR_START_UNSAFE(s, _utf8_get_char_unsafe_index); \ 00368 UTF8_NEXT_CHAR_UNSAFE(s, _utf8_get_char_unsafe_index, c); \ 00369 } UPRV_BLOCK_MACRO_END 00370 00372 #define UTF8_GET_CHAR_SAFE(s, start, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00373 int32_t _utf8_get_char_safe_index=(int32_t)(i); \ 00374 UTF8_SET_CHAR_START_SAFE(s, start, _utf8_get_char_safe_index); \ 00375 UTF8_NEXT_CHAR_SAFE(s, _utf8_get_char_safe_index, length, c, strict); \ 00376 } UPRV_BLOCK_MACRO_END 00377 00379 #define UTF8_NEXT_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00380 (c)=(s)[(i)++]; \ 00381 if((uint8_t)((c)-0xc0)<0x35) { \ 00382 uint8_t __count=UTF8_COUNT_TRAIL_BYTES(c); \ 00383 UTF8_MASK_LEAD_BYTE(c, __count); \ 00384 switch(__count) { \ 00385 /* each following branch falls through to the next one */ \ 00386 case 3: \ 00387 (c)=((c)<<6)|((s)[(i)++]&0x3f); \ 00388 case 2: \ 00389 (c)=((c)<<6)|((s)[(i)++]&0x3f); \ 00390 case 1: \ 00391 (c)=((c)<<6)|((s)[(i)++]&0x3f); \ 00392 /* no other branches to optimize switch() */ \ 00393 break; \ 00394 } \ 00395 } \ 00396 } UPRV_BLOCK_MACRO_END 00397 00399 #define UTF8_APPEND_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00400 if((uint32_t)(c)<=0x7f) { \ 00401 (s)[(i)++]=(uint8_t)(c); \ 00402 } else { \ 00403 if((uint32_t)(c)<=0x7ff) { \ 00404 (s)[(i)++]=(uint8_t)(((c)>>6)|0xc0); \ 00405 } else { \ 00406 if((uint32_t)(c)<=0xffff) { \ 00407 (s)[(i)++]=(uint8_t)(((c)>>12)|0xe0); \ 00408 } else { \ 00409 (s)[(i)++]=(uint8_t)(((c)>>18)|0xf0); \ 00410 (s)[(i)++]=(uint8_t)((((c)>>12)&0x3f)|0x80); \ 00411 } \ 00412 (s)[(i)++]=(uint8_t)((((c)>>6)&0x3f)|0x80); \ 00413 } \ 00414 (s)[(i)++]=(uint8_t)(((c)&0x3f)|0x80); \ 00415 } \ 00416 } UPRV_BLOCK_MACRO_END 00417 00419 #define UTF8_FWD_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00420 (i)+=1+UTF8_COUNT_TRAIL_BYTES((s)[i]); \ 00421 } UPRV_BLOCK_MACRO_END 00422 00424 #define UTF8_FWD_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \ 00425 int32_t __N=(n); \ 00426 while(__N>0) { \ 00427 UTF8_FWD_1_UNSAFE(s, i); \ 00428 --__N; \ 00429 } \ 00430 } UPRV_BLOCK_MACRO_END 00431 00433 #define UTF8_SET_CHAR_START_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00434 while(UTF8_IS_TRAIL((s)[i])) { --(i); } \ 00435 } UPRV_BLOCK_MACRO_END 00436 00438 #define UTF8_NEXT_CHAR_SAFE(s, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00439 (c)=(s)[(i)++]; \ 00440 if((c)>=0x80) { \ 00441 if(UTF8_IS_LEAD(c)) { \ 00442 (c)=utf8_nextCharSafeBody(s, &(i), (int32_t)(length), c, strict); \ 00443 } else { \ 00444 (c)=UTF8_ERROR_VALUE_1; \ 00445 } \ 00446 } \ 00447 } UPRV_BLOCK_MACRO_END 00448 00450 #define UTF8_APPEND_CHAR_SAFE(s, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \ 00451 if((uint32_t)(c)<=0x7f) { \ 00452 (s)[(i)++]=(uint8_t)(c); \ 00453 } else { \ 00454 (i)=utf8_appendCharSafeBody(s, (int32_t)(i), (int32_t)(length), c, NULL); \ 00455 } \ 00456 } UPRV_BLOCK_MACRO_END 00457 00459 #define UTF8_FWD_1_SAFE(s, i, length) U8_FWD_1(s, i, length) 00460 00462 #define UTF8_FWD_N_SAFE(s, i, length, n) U8_FWD_N(s, i, length, n) 00463 00465 #define UTF8_SET_CHAR_START_SAFE(s, start, i) U8_SET_CP_START(s, start, i) 00466 00468 #define UTF8_PREV_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00469 (c)=(s)[--(i)]; \ 00470 if(UTF8_IS_TRAIL(c)) { \ 00471 uint8_t __b, __count=1, __shift=6; \ 00472 \ 00473 /* c is a trail byte */ \ 00474 (c)&=0x3f; \ 00475 for(;;) { \ 00476 __b=(s)[--(i)]; \ 00477 if(__b>=0xc0) { \ 00478 UTF8_MASK_LEAD_BYTE(__b, __count); \ 00479 (c)|=(UChar32)__b<<__shift; \ 00480 break; \ 00481 } else { \ 00482 (c)|=(UChar32)(__b&0x3f)<<__shift; \ 00483 ++__count; \ 00484 __shift+=6; \ 00485 } \ 00486 } \ 00487 } \ 00488 } UPRV_BLOCK_MACRO_END 00489 00491 #define UTF8_BACK_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00492 while(UTF8_IS_TRAIL((s)[--(i)])) {} \ 00493 } UPRV_BLOCK_MACRO_END 00494 00496 #define UTF8_BACK_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \ 00497 int32_t __N=(n); \ 00498 while(__N>0) { \ 00499 UTF8_BACK_1_UNSAFE(s, i); \ 00500 --__N; \ 00501 } \ 00502 } UPRV_BLOCK_MACRO_END 00503 00505 #define UTF8_SET_CHAR_LIMIT_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00506 UTF8_BACK_1_UNSAFE(s, i); \ 00507 UTF8_FWD_1_UNSAFE(s, i); \ 00508 } UPRV_BLOCK_MACRO_END 00509 00511 #define UTF8_PREV_CHAR_SAFE(s, start, i, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00512 (c)=(s)[--(i)]; \ 00513 if((c)>=0x80) { \ 00514 if((c)<=0xbf) { \ 00515 (c)=utf8_prevCharSafeBody(s, start, &(i), c, strict); \ 00516 } else { \ 00517 (c)=UTF8_ERROR_VALUE_1; \ 00518 } \ 00519 } \ 00520 } UPRV_BLOCK_MACRO_END 00521 00523 #define UTF8_BACK_1_SAFE(s, start, i) U8_BACK_1(s, start, i) 00524 00526 #define UTF8_BACK_N_SAFE(s, start, i, n) U8_BACK_N(s, start, i, n) 00527 00529 #define UTF8_SET_CHAR_LIMIT_SAFE(s, start, i, length) U8_SET_CP_LIMIT(s, start, i, length) 00530 00531 /* Formerly utf16.h --------------------------------------------------------- */ 00532 00534 #define UTF_IS_FIRST_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xd800) 00535 00537 #define UTF_IS_SECOND_SURROGATE(uchar) (((uchar)&0xfffffc00)==0xdc00) 00538 00540 #define UTF_IS_SURROGATE_FIRST(c) (((c)&0x400)==0) 00541 00543 #define UTF_SURROGATE_OFFSET ((0xd800<<10UL)+0xdc00-0x10000) 00544 00546 #define UTF16_GET_PAIR_VALUE(first, second) \ 00547 (((first)<<10UL)+(second)-UTF_SURROGATE_OFFSET) 00548 00550 #define UTF_FIRST_SURROGATE(supplementary) (UChar)(((supplementary)>>10)+0xd7c0) 00551 00553 #define UTF_SECOND_SURROGATE(supplementary) (UChar)(((supplementary)&0x3ff)|0xdc00) 00554 00556 #define UTF16_LEAD(supplementary) UTF_FIRST_SURROGATE(supplementary) 00557 00559 #define UTF16_TRAIL(supplementary) UTF_SECOND_SURROGATE(supplementary) 00560 00562 #define UTF16_IS_SINGLE(uchar) !UTF_IS_SURROGATE(uchar) 00563 00565 #define UTF16_IS_LEAD(uchar) UTF_IS_FIRST_SURROGATE(uchar) 00566 00568 #define UTF16_IS_TRAIL(uchar) UTF_IS_SECOND_SURROGATE(uchar) 00569 00571 #define UTF16_NEED_MULTIPLE_UCHAR(c) ((uint32_t)(c)>0xffff) 00572 00574 #define UTF16_CHAR_LENGTH(c) ((uint32_t)(c)<=0xffff ? 1 : 2) 00575 00577 #define UTF16_MAX_CHAR_LENGTH 2 00578 00580 #define UTF16_ARRAY_SIZE(size) (size) 00581 00593 #define UTF16_GET_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00594 (c)=(s)[i]; \ 00595 if(UTF_IS_SURROGATE(c)) { \ 00596 if(UTF_IS_SURROGATE_FIRST(c)) { \ 00597 (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)+1]); \ 00598 } else { \ 00599 (c)=UTF16_GET_PAIR_VALUE((s)[(i)-1], (c)); \ 00600 } \ 00601 } \ 00602 } UPRV_BLOCK_MACRO_END 00603 00605 #define UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00606 (c)=(s)[i]; \ 00607 if(UTF_IS_SURROGATE(c)) { \ 00608 uint16_t __c2; \ 00609 if(UTF_IS_SURROGATE_FIRST(c)) { \ 00610 if((i)+1<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)+1])) { \ 00611 (c)=UTF16_GET_PAIR_VALUE((c), __c2); \ 00612 /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \ 00613 } else if(strict) {\ 00614 /* unmatched first surrogate */ \ 00615 (c)=UTF_ERROR_VALUE; \ 00616 } \ 00617 } else { \ 00618 if((i)-1>=(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \ 00619 (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \ 00620 /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \ 00621 } else if(strict) {\ 00622 /* unmatched second surrogate */ \ 00623 (c)=UTF_ERROR_VALUE; \ 00624 } \ 00625 } \ 00626 } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \ 00627 (c)=UTF_ERROR_VALUE; \ 00628 } \ 00629 } UPRV_BLOCK_MACRO_END 00630 00632 #define UTF16_NEXT_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00633 (c)=(s)[(i)++]; \ 00634 if(UTF_IS_FIRST_SURROGATE(c)) { \ 00635 (c)=UTF16_GET_PAIR_VALUE((c), (s)[(i)++]); \ 00636 } \ 00637 } UPRV_BLOCK_MACRO_END 00638 00640 #define UTF16_APPEND_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00641 if((uint32_t)(c)<=0xffff) { \ 00642 (s)[(i)++]=(uint16_t)(c); \ 00643 } else { \ 00644 (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \ 00645 (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ 00646 } \ 00647 } UPRV_BLOCK_MACRO_END 00648 00650 #define UTF16_FWD_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00651 if(UTF_IS_FIRST_SURROGATE((s)[(i)++])) { \ 00652 ++(i); \ 00653 } \ 00654 } UPRV_BLOCK_MACRO_END 00655 00657 #define UTF16_FWD_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \ 00658 int32_t __N=(n); \ 00659 while(__N>0) { \ 00660 UTF16_FWD_1_UNSAFE(s, i); \ 00661 --__N; \ 00662 } \ 00663 } UPRV_BLOCK_MACRO_END 00664 00666 #define UTF16_SET_CHAR_START_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00667 if(UTF_IS_SECOND_SURROGATE((s)[i])) { \ 00668 --(i); \ 00669 } \ 00670 } UPRV_BLOCK_MACRO_END 00671 00673 #define UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00674 (c)=(s)[(i)++]; \ 00675 if(UTF_IS_FIRST_SURROGATE(c)) { \ 00676 uint16_t __c2; \ 00677 if((i)<(length) && UTF_IS_SECOND_SURROGATE(__c2=(s)[(i)])) { \ 00678 ++(i); \ 00679 (c)=UTF16_GET_PAIR_VALUE((c), __c2); \ 00680 /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \ 00681 } else if(strict) {\ 00682 /* unmatched first surrogate */ \ 00683 (c)=UTF_ERROR_VALUE; \ 00684 } \ 00685 } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \ 00686 /* unmatched second surrogate or other non-character */ \ 00687 (c)=UTF_ERROR_VALUE; \ 00688 } \ 00689 } UPRV_BLOCK_MACRO_END 00690 00692 #define UTF16_APPEND_CHAR_SAFE(s, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \ 00693 if((uint32_t)(c)<=0xffff) { \ 00694 (s)[(i)++]=(uint16_t)(c); \ 00695 } else if((uint32_t)(c)<=0x10ffff) { \ 00696 if((i)+1<(length)) { \ 00697 (s)[(i)++]=(uint16_t)(((c)>>10)+0xd7c0); \ 00698 (s)[(i)++]=(uint16_t)(((c)&0x3ff)|0xdc00); \ 00699 } else /* not enough space */ { \ 00700 (s)[(i)++]=UTF_ERROR_VALUE; \ 00701 } \ 00702 } else /* c>0x10ffff, write error value */ { \ 00703 (s)[(i)++]=UTF_ERROR_VALUE; \ 00704 } \ 00705 } UPRV_BLOCK_MACRO_END 00706 00708 #define UTF16_FWD_1_SAFE(s, i, length) U16_FWD_1(s, i, length) 00709 00711 #define UTF16_FWD_N_SAFE(s, i, length, n) U16_FWD_N(s, i, length, n) 00712 00714 #define UTF16_SET_CHAR_START_SAFE(s, start, i) U16_SET_CP_START(s, start, i) 00715 00717 #define UTF16_PREV_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00718 (c)=(s)[--(i)]; \ 00719 if(UTF_IS_SECOND_SURROGATE(c)) { \ 00720 (c)=UTF16_GET_PAIR_VALUE((s)[--(i)], (c)); \ 00721 } \ 00722 } UPRV_BLOCK_MACRO_END 00723 00725 #define UTF16_BACK_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00726 if(UTF_IS_SECOND_SURROGATE((s)[--(i)])) { \ 00727 --(i); \ 00728 } \ 00729 } UPRV_BLOCK_MACRO_END 00730 00732 #define UTF16_BACK_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \ 00733 int32_t __N=(n); \ 00734 while(__N>0) { \ 00735 UTF16_BACK_1_UNSAFE(s, i); \ 00736 --__N; \ 00737 } \ 00738 } UPRV_BLOCK_MACRO_END 00739 00741 #define UTF16_SET_CHAR_LIMIT_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00742 if(UTF_IS_FIRST_SURROGATE((s)[(i)-1])) { \ 00743 ++(i); \ 00744 } \ 00745 } UPRV_BLOCK_MACRO_END 00746 00748 #define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00749 (c)=(s)[--(i)]; \ 00750 if(UTF_IS_SECOND_SURROGATE(c)) { \ 00751 uint16_t __c2; \ 00752 if((i)>(start) && UTF_IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \ 00753 --(i); \ 00754 (c)=UTF16_GET_PAIR_VALUE(__c2, (c)); \ 00755 /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() and UTF_IS_UNICODE_CHAR() */ \ 00756 } else if(strict) {\ 00757 /* unmatched second surrogate */ \ 00758 (c)=UTF_ERROR_VALUE; \ 00759 } \ 00760 } else if((strict) && !UTF_IS_UNICODE_CHAR(c)) { \ 00761 /* unmatched first surrogate or other non-character */ \ 00762 (c)=UTF_ERROR_VALUE; \ 00763 } \ 00764 } UPRV_BLOCK_MACRO_END 00765 00767 #define UTF16_BACK_1_SAFE(s, start, i) U16_BACK_1(s, start, i) 00768 00770 #define UTF16_BACK_N_SAFE(s, start, i, n) U16_BACK_N(s, start, i, n) 00771 00773 #define UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length) 00774 00775 /* Formerly utf32.h --------------------------------------------------------- */ 00776 00777 /* 00778 * Old documentation: 00779 * 00780 * This file defines macros to deal with UTF-32 code units and code points. 00781 * Signatures and semantics are the same as for the similarly named macros 00782 * in utf16.h. 00783 * utf32.h is included by utf.h after unicode/umachine.h</p> 00784 * and some common definitions. 00785 * <p><b>Usage:</b> ICU coding guidelines for if() statements should be followed when using these macros. 00786 * Compound statements (curly braces {}) must be used for if-else-while... 00787 * bodies and all macro statements should be terminated with semicolon.</p> 00788 */ 00789 00790 /* internal definitions ----------------------------------------------------- */ 00791 00793 #define UTF32_IS_SAFE(c, strict) \ 00794 (!(strict) ? \ 00795 (uint32_t)(c)<=0x10ffff : \ 00796 UTF_IS_UNICODE_CHAR(c)) 00797 00798 /* 00799 * For the semantics of all of these macros, see utf16.h. 00800 * The UTF-32 versions are trivial because any code point is 00801 * encoded using exactly one code unit. 00802 */ 00803 00804 /* single-code point definitions -------------------------------------------- */ 00805 00806 /* classes of code unit values */ 00807 00809 #define UTF32_IS_SINGLE(uchar) 1 00810 00811 #define UTF32_IS_LEAD(uchar) 0 00812 00813 #define UTF32_IS_TRAIL(uchar) 0 00814 00815 /* number of code units per code point */ 00816 00818 #define UTF32_NEED_MULTIPLE_UCHAR(c) 0 00819 00820 #define UTF32_CHAR_LENGTH(c) 1 00821 00822 #define UTF32_MAX_CHAR_LENGTH 1 00823 00824 /* average number of code units compared to UTF-16 */ 00825 00827 #define UTF32_ARRAY_SIZE(size) (size) 00828 00830 #define UTF32_GET_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00831 (c)=(s)[i]; \ 00832 } UPRV_BLOCK_MACRO_END 00833 00835 #define UTF32_GET_CHAR_SAFE(s, start, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00836 (c)=(s)[i]; \ 00837 if(!UTF32_IS_SAFE(c, strict)) { \ 00838 (c)=UTF_ERROR_VALUE; \ 00839 } \ 00840 } UPRV_BLOCK_MACRO_END 00841 00842 /* definitions with forward iteration --------------------------------------- */ 00843 00845 #define UTF32_NEXT_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00846 (c)=(s)[(i)++]; \ 00847 } UPRV_BLOCK_MACRO_END 00848 00850 #define UTF32_APPEND_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00851 (s)[(i)++]=(c); \ 00852 } UPRV_BLOCK_MACRO_END 00853 00855 #define UTF32_FWD_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00856 ++(i); \ 00857 } UPRV_BLOCK_MACRO_END 00858 00860 #define UTF32_FWD_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \ 00861 (i)+=(n); \ 00862 } UPRV_BLOCK_MACRO_END 00863 00865 #define UTF32_SET_CHAR_START_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00866 } UPRV_BLOCK_MACRO_END 00867 00869 #define UTF32_NEXT_CHAR_SAFE(s, i, length, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00870 (c)=(s)[(i)++]; \ 00871 if(!UTF32_IS_SAFE(c, strict)) { \ 00872 (c)=UTF_ERROR_VALUE; \ 00873 } \ 00874 } UPRV_BLOCK_MACRO_END 00875 00877 #define UTF32_APPEND_CHAR_SAFE(s, i, length, c) UPRV_BLOCK_MACRO_BEGIN { \ 00878 if((uint32_t)(c)<=0x10ffff) { \ 00879 (s)[(i)++]=(c); \ 00880 } else /* c>0x10ffff, write 0xfffd */ { \ 00881 (s)[(i)++]=0xfffd; \ 00882 } \ 00883 } UPRV_BLOCK_MACRO_END 00884 00886 #define UTF32_FWD_1_SAFE(s, i, length) UPRV_BLOCK_MACRO_BEGIN { \ 00887 ++(i); \ 00888 } UPRV_BLOCK_MACRO_END 00889 00891 #define UTF32_FWD_N_SAFE(s, i, length, n) UPRV_BLOCK_MACRO_BEGIN { \ 00892 if(((i)+=(n))>(length)) { \ 00893 (i)=(length); \ 00894 } \ 00895 } UPRV_BLOCK_MACRO_END 00896 00898 #define UTF32_SET_CHAR_START_SAFE(s, start, i) UPRV_BLOCK_MACRO_BEGIN { \ 00899 } UPRV_BLOCK_MACRO_END 00900 00901 /* definitions with backward iteration -------------------------------------- */ 00902 00904 #define UTF32_PREV_CHAR_UNSAFE(s, i, c) UPRV_BLOCK_MACRO_BEGIN { \ 00905 (c)=(s)[--(i)]; \ 00906 } UPRV_BLOCK_MACRO_END 00907 00909 #define UTF32_BACK_1_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00910 --(i); \ 00911 } UPRV_BLOCK_MACRO_END 00912 00914 #define UTF32_BACK_N_UNSAFE(s, i, n) UPRV_BLOCK_MACRO_BEGIN { \ 00915 (i)-=(n); \ 00916 } UPRV_BLOCK_MACRO_END 00917 00919 #define UTF32_SET_CHAR_LIMIT_UNSAFE(s, i) UPRV_BLOCK_MACRO_BEGIN { \ 00920 } UPRV_BLOCK_MACRO_END 00921 00923 #define UTF32_PREV_CHAR_SAFE(s, start, i, c, strict) UPRV_BLOCK_MACRO_BEGIN { \ 00924 (c)=(s)[--(i)]; \ 00925 if(!UTF32_IS_SAFE(c, strict)) { \ 00926 (c)=UTF_ERROR_VALUE; \ 00927 } \ 00928 } UPRV_BLOCK_MACRO_END 00929 00931 #define UTF32_BACK_1_SAFE(s, start, i) UPRV_BLOCK_MACRO_BEGIN { \ 00932 --(i); \ 00933 } UPRV_BLOCK_MACRO_END 00934 00936 #define UTF32_BACK_N_SAFE(s, start, i, n) UPRV_BLOCK_MACRO_BEGIN { \ 00937 (i)-=(n); \ 00938 if((i)<(start)) { \ 00939 (i)=(start); \ 00940 } \ 00941 } UPRV_BLOCK_MACRO_END 00942 00944 #define UTF32_SET_CHAR_LIMIT_SAFE(s, i, length) UPRV_BLOCK_MACRO_BEGIN { \ 00945 } UPRV_BLOCK_MACRO_END 00946 00947 /* Formerly utf.h, part 2 --------------------------------------------------- */ 00948 00954 #define UTF_ARRAY_SIZE(size) UTF16_ARRAY_SIZE(size) 00955 00957 #define UTF_GET_CHAR_UNSAFE(s, i, c) UTF16_GET_CHAR_UNSAFE(s, i, c) 00958 00960 #define UTF_GET_CHAR_SAFE(s, start, i, length, c, strict) UTF16_GET_CHAR_SAFE(s, start, i, length, c, strict) 00961 00962 00964 #define UTF_NEXT_CHAR_UNSAFE(s, i, c) UTF16_NEXT_CHAR_UNSAFE(s, i, c) 00965 00967 #define UTF_NEXT_CHAR_SAFE(s, i, length, c, strict) UTF16_NEXT_CHAR_SAFE(s, i, length, c, strict) 00968 00969 00971 #define UTF_APPEND_CHAR_UNSAFE(s, i, c) UTF16_APPEND_CHAR_UNSAFE(s, i, c) 00972 00974 #define UTF_APPEND_CHAR_SAFE(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c) 00975 00976 00978 #define UTF_FWD_1_UNSAFE(s, i) UTF16_FWD_1_UNSAFE(s, i) 00979 00981 #define UTF_FWD_1_SAFE(s, i, length) UTF16_FWD_1_SAFE(s, i, length) 00982 00983 00985 #define UTF_FWD_N_UNSAFE(s, i, n) UTF16_FWD_N_UNSAFE(s, i, n) 00986 00988 #define UTF_FWD_N_SAFE(s, i, length, n) UTF16_FWD_N_SAFE(s, i, length, n) 00989 00990 00992 #define UTF_SET_CHAR_START_UNSAFE(s, i) UTF16_SET_CHAR_START_UNSAFE(s, i) 00993 00995 #define UTF_SET_CHAR_START_SAFE(s, start, i) UTF16_SET_CHAR_START_SAFE(s, start, i) 00996 00997 00999 #define UTF_PREV_CHAR_UNSAFE(s, i, c) UTF16_PREV_CHAR_UNSAFE(s, i, c) 01000 01002 #define UTF_PREV_CHAR_SAFE(s, start, i, c, strict) UTF16_PREV_CHAR_SAFE(s, start, i, c, strict) 01003 01004 01006 #define UTF_BACK_1_UNSAFE(s, i) UTF16_BACK_1_UNSAFE(s, i) 01007 01009 #define UTF_BACK_1_SAFE(s, start, i) UTF16_BACK_1_SAFE(s, start, i) 01010 01011 01013 #define UTF_BACK_N_UNSAFE(s, i, n) UTF16_BACK_N_UNSAFE(s, i, n) 01014 01016 #define UTF_BACK_N_SAFE(s, start, i, n) UTF16_BACK_N_SAFE(s, start, i, n) 01017 01018 01020 #define UTF_SET_CHAR_LIMIT_UNSAFE(s, i) UTF16_SET_CHAR_LIMIT_UNSAFE(s, i) 01021 01023 #define UTF_SET_CHAR_LIMIT_SAFE(s, start, i, length) UTF16_SET_CHAR_LIMIT_SAFE(s, start, i, length) 01024 01025 /* Define default macros (UTF-16 "safe") ------------------------------------ */ 01026 01032 #define UTF_IS_SINGLE(uchar) U16_IS_SINGLE(uchar) 01033 01039 #define UTF_IS_LEAD(uchar) U16_IS_LEAD(uchar) 01040 01046 #define UTF_IS_TRAIL(uchar) U16_IS_TRAIL(uchar) 01047 01053 #define UTF_NEED_MULTIPLE_UCHAR(c) UTF16_NEED_MULTIPLE_UCHAR(c) 01054 01060 #define UTF_CHAR_LENGTH(c) U16_LENGTH(c) 01061 01067 #define UTF_MAX_CHAR_LENGTH U16_MAX_LENGTH 01068 01078 #define UTF_GET_CHAR(s, start, i, length, c) U16_GET(s, start, i, length, c) 01079 01091 #define UTF_NEXT_CHAR(s, i, length, c) U16_NEXT(s, i, length, c) 01092 01104 #define UTF_APPEND_CHAR(s, i, length, c) UTF16_APPEND_CHAR_SAFE(s, i, length, c) 01105 01115 #define UTF_FWD_1(s, i, length) U16_FWD_1(s, i, length) 01116 01126 #define UTF_FWD_N(s, i, length, n) U16_FWD_N(s, i, length, n) 01127 01142 #define UTF_SET_CHAR_START(s, start, i) U16_SET_CP_START(s, start, i) 01143 01155 #define UTF_PREV_CHAR(s, start, i, c) U16_PREV(s, start, i, c) 01156 01168 #define UTF_BACK_1(s, start, i) U16_BACK_1(s, start, i) 01169 01181 #define UTF_BACK_N(s, start, i, n) U16_BACK_N(s, start, i, n) 01182 01197 #define UTF_SET_CHAR_LIMIT(s, start, i, length) U16_SET_CP_LIMIT(s, start, i, length) 01198 01199 #endif // !U_HIDE_DEPRECATED_API && !U_HIDE_OBSOLETE_UTF_OLD_H 01200 01201 #endif
1.7.6.1