LCOV - code coverage report
Current view: top level - intl/icu/source/common - uchar.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 14 314 4.5 %
Date: 2017-07-14 16:53:18 Functions: 3 49 6.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // © 2016 and later: Unicode, Inc. and others.
       2             : // License & terms of use: http://www.unicode.org/copyright.html
       3             : /*
       4             : ********************************************************************************
       5             : *   Copyright (C) 1996-2016, International Business Machines
       6             : *   Corporation and others.  All Rights Reserved.
       7             : ********************************************************************************
       8             : *
       9             : * File UCHAR.C
      10             : *
      11             : * Modification History:
      12             : *
      13             : *   Date        Name        Description
      14             : *   04/02/97    aliu        Creation.
      15             : *   4/15/99     Madhu       Updated all the function definitions for C Implementation
      16             : *   5/20/99     Madhu       Added the function u_getVersion()
      17             : *   8/19/1999   srl         Upgraded scripts to Unicode3.0 
      18             : *   11/11/1999  weiv        added u_isalnum(), cleaned comments
      19             : *   01/11/2000  helena      Renamed u_getVersion to u_getUnicodeVersion.
      20             : *   06/20/2000  helena      OS/400 port changes; mostly typecast.
      21             : ******************************************************************************
      22             : */
      23             : 
      24             : #include "unicode/utypes.h"
      25             : #include "unicode/uchar.h"
      26             : #include "unicode/uscript.h"
      27             : #include "unicode/udata.h"
      28             : #include "uassert.h"
      29             : #include "cmemory.h"
      30             : #include "ucln_cmn.h"
      31             : #include "utrie2.h"
      32             : #include "udataswp.h"
      33             : #include "uprops.h"
      34             : #include "ustr_imp.h"
      35             : 
      36             : /* uchar_props_data.h is machine-generated by genprops --csource */
      37             : #define INCLUDED_FROM_UCHAR_C
      38             : #include "uchar_props_data.h"
      39             : 
      40             : /* constants and macros for access to the data ------------------------------ */
      41             : 
      42             : /* getting a uint32_t properties word from the data */
      43             : #define GET_PROPS(c, result) ((result)=UTRIE2_GET16(&propsTrie, c));
      44             : 
      45             : U_CFUNC UBool
      46           0 : uprv_haveProperties(UErrorCode *pErrorCode) {
      47           0 :     if(U_FAILURE(*pErrorCode)) {
      48           0 :         return FALSE;
      49             :     }
      50           0 :     return TRUE;
      51             : }
      52             : 
      53             : /* API functions ------------------------------------------------------------ */
      54             : 
      55             : /* Gets the Unicode character's general category.*/
      56             : U_CAPI int8_t U_EXPORT2
      57        1158 : u_charType(UChar32 c) {
      58             :     uint32_t props;
      59        1158 :     GET_PROPS(c, props);
      60        1158 :     return (int8_t)GET_CATEGORY(props);
      61             : }
      62             : 
      63             : /* Enumerate all code points with their general categories. */
      64             : struct _EnumTypeCallback {
      65             :     UCharEnumTypeRange *enumRange;
      66             :     const void *context;
      67             : };
      68             : 
      69             : static uint32_t U_CALLCONV
      70           0 : _enumTypeValue(const void *context, uint32_t value) {
      71             :     (void)context;
      72           0 :     return GET_CATEGORY(value);
      73             : }
      74             : 
      75             : static UBool U_CALLCONV
      76           0 : _enumTypeRange(const void *context, UChar32 start, UChar32 end, uint32_t value) {
      77             :     /* just cast the value to UCharCategory */
      78             :     return ((struct _EnumTypeCallback *)context)->
      79           0 :         enumRange(((struct _EnumTypeCallback *)context)->context,
      80           0 :                   start, end+1, (UCharCategory)value);
      81             : }
      82             : 
      83             : U_CAPI void U_EXPORT2
      84           0 : u_enumCharTypes(UCharEnumTypeRange *enumRange, const void *context) {
      85             :     struct _EnumTypeCallback callback;
      86             : 
      87           0 :     if(enumRange==NULL) {
      88           0 :         return;
      89             :     }
      90             : 
      91           0 :     callback.enumRange=enumRange;
      92           0 :     callback.context=context;
      93           0 :     utrie2_enum(&propsTrie, _enumTypeValue, _enumTypeRange, &callback);
      94             : }
      95             : 
      96             : /* Checks if ch is a lower case letter.*/
      97             : U_CAPI UBool U_EXPORT2
      98           0 : u_islower(UChar32 c) {
      99             :     uint32_t props;
     100           0 :     GET_PROPS(c, props);
     101           0 :     return (UBool)(GET_CATEGORY(props)==U_LOWERCASE_LETTER);
     102             : }
     103             : 
     104             : /* Checks if ch is an upper case letter.*/
     105             : U_CAPI UBool U_EXPORT2
     106           0 : u_isupper(UChar32 c) {
     107             :     uint32_t props;
     108           0 :     GET_PROPS(c, props);
     109           0 :     return (UBool)(GET_CATEGORY(props)==U_UPPERCASE_LETTER);
     110             : }
     111             : 
     112             : /* Checks if ch is a title case letter; usually upper case letters.*/
     113             : U_CAPI UBool U_EXPORT2
     114           0 : u_istitle(UChar32 c) {
     115             :     uint32_t props;
     116           0 :     GET_PROPS(c, props);
     117           0 :     return (UBool)(GET_CATEGORY(props)==U_TITLECASE_LETTER);
     118             : }
     119             : 
     120             : /* Checks if ch is a decimal digit. */
     121             : U_CAPI UBool U_EXPORT2
     122           0 : u_isdigit(UChar32 c) {
     123             :     uint32_t props;
     124           0 :     GET_PROPS(c, props);
     125           0 :     return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER);
     126             : }
     127             : 
     128             : U_CAPI UBool U_EXPORT2
     129           0 : u_isxdigit(UChar32 c) {
     130             :     uint32_t props;
     131             : 
     132             :     /* check ASCII and Fullwidth ASCII a-fA-F */
     133           0 :     if(
     134           0 :         (c<=0x66 && c>=0x41 && (c<=0x46 || c>=0x61)) ||
     135           0 :         (c>=0xff21 && c<=0xff46 && (c<=0xff26 || c>=0xff41))
     136             :     ) {
     137           0 :         return TRUE;
     138             :     }
     139             : 
     140           0 :     GET_PROPS(c, props);
     141           0 :     return (UBool)(GET_CATEGORY(props)==U_DECIMAL_DIGIT_NUMBER);
     142             : }
     143             : 
     144             : /* Checks if the Unicode character is a letter.*/
     145             : U_CAPI UBool U_EXPORT2
     146           0 : u_isalpha(UChar32 c) {
     147             :     uint32_t props;
     148           0 :     GET_PROPS(c, props);
     149           0 :     return (UBool)((CAT_MASK(props)&U_GC_L_MASK)!=0);
     150             : }
     151             : 
     152             : U_CAPI UBool U_EXPORT2
     153           0 : u_isUAlphabetic(UChar32 c) {
     154           0 :     return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_ALPHABETIC))!=0;
     155             : }
     156             : 
     157             : /* Checks if c is a letter or a decimal digit */
     158             : U_CAPI UBool U_EXPORT2
     159           0 : u_isalnum(UChar32 c) {
     160             :     uint32_t props;
     161           0 :     GET_PROPS(c, props);
     162           0 :     return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_ND_MASK))!=0);
     163             : }
     164             : 
     165             : /**
     166             :  * Checks if c is alphabetic, or a decimal digit; implements UCHAR_POSIX_ALNUM.
     167             :  * @internal
     168             :  */
     169             : U_CFUNC UBool
     170           0 : u_isalnumPOSIX(UChar32 c) {
     171           0 :     return (UBool)(u_isUAlphabetic(c) || u_isdigit(c));
     172             : }
     173             : 
     174             : /* Checks if ch is a unicode character with assigned character type.*/
     175             : U_CAPI UBool U_EXPORT2
     176           0 : u_isdefined(UChar32 c) {
     177             :     uint32_t props;
     178           0 :     GET_PROPS(c, props);
     179           0 :     return (UBool)(GET_CATEGORY(props)!=0);
     180             : }
     181             : 
     182             : /* Checks if the Unicode character is a base form character that can take a diacritic.*/
     183             : U_CAPI UBool U_EXPORT2
     184           0 : u_isbase(UChar32 c) {
     185             :     uint32_t props;
     186           0 :     GET_PROPS(c, props);
     187           0 :     return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_N_MASK|U_GC_MC_MASK|U_GC_ME_MASK))!=0);
     188             : }
     189             : 
     190             : /* Checks if the Unicode character is a control character.*/
     191             : U_CAPI UBool U_EXPORT2
     192           0 : u_iscntrl(UChar32 c) {
     193             :     uint32_t props;
     194           0 :     GET_PROPS(c, props);
     195           0 :     return (UBool)((CAT_MASK(props)&(U_GC_CC_MASK|U_GC_CF_MASK|U_GC_ZL_MASK|U_GC_ZP_MASK))!=0);
     196             : }
     197             : 
     198             : U_CAPI UBool U_EXPORT2
     199           0 : u_isISOControl(UChar32 c) {
     200           0 :     return (uint32_t)c<=0x9f && (c<=0x1f || c>=0x7f);
     201             : }
     202             : 
     203             : /* Some control characters that are used as space. */
     204             : #define IS_THAT_CONTROL_SPACE(c) \
     205             :     (c<=0x9f && ((c>=TAB && c<=CR) || (c>=0x1c && c <=0x1f) || c==NL))
     206             : 
     207             : /* Java has decided that U+0085 New Line is not whitespace any more. */
     208             : #define IS_THAT_ASCII_CONTROL_SPACE(c) \
     209             :     (c<=0x1f && c>=TAB && (c<=CR || c>=0x1c))
     210             : 
     211             : /* Checks if the Unicode character is a space character.*/
     212             : U_CAPI UBool U_EXPORT2
     213           0 : u_isspace(UChar32 c) {
     214             :     uint32_t props;
     215           0 :     GET_PROPS(c, props);
     216           0 :     return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0 || IS_THAT_CONTROL_SPACE(c));
     217             : }
     218             : 
     219             : U_CAPI UBool U_EXPORT2
     220           0 : u_isJavaSpaceChar(UChar32 c) {
     221             :     uint32_t props;
     222           0 :     GET_PROPS(c, props);
     223           0 :     return (UBool)((CAT_MASK(props)&U_GC_Z_MASK)!=0);
     224             : }
     225             : 
     226             : /* Checks if the Unicode character is a whitespace character.*/
     227             : U_CAPI UBool U_EXPORT2
     228           0 : u_isWhitespace(UChar32 c) {
     229             :     uint32_t props;
     230           0 :     GET_PROPS(c, props);
     231             :     return (UBool)(
     232           0 :                 ((CAT_MASK(props)&U_GC_Z_MASK)!=0 &&
     233           0 :                     c!=NBSP && c!=FIGURESP && c!=NNBSP) || /* exclude no-break spaces */
     234           0 :                 IS_THAT_ASCII_CONTROL_SPACE(c)
     235           0 :            );
     236             : }
     237             : 
     238             : U_CAPI UBool U_EXPORT2
     239           0 : u_isblank(UChar32 c) {
     240           0 :     if((uint32_t)c<=0x9f) {
     241           0 :         return c==9 || c==0x20; /* TAB or SPACE */
     242             :     } else {
     243             :         /* Zs */
     244             :         uint32_t props;
     245           0 :         GET_PROPS(c, props);
     246           0 :         return (UBool)(GET_CATEGORY(props)==U_SPACE_SEPARATOR);
     247             :     }
     248             : }
     249             : 
     250             : U_CAPI UBool U_EXPORT2
     251           0 : u_isUWhiteSpace(UChar32 c) {
     252           0 :     return (u_getUnicodeProperties(c, 1)&U_MASK(UPROPS_WHITE_SPACE))!=0;
     253             : }
     254             : 
     255             : /* Checks if the Unicode character is printable.*/
     256             : U_CAPI UBool U_EXPORT2
     257           0 : u_isprint(UChar32 c) {
     258             :     uint32_t props;
     259           0 :     GET_PROPS(c, props);
     260             :     /* comparing ==0 returns FALSE for the categories mentioned */
     261           0 :     return (UBool)((CAT_MASK(props)&U_GC_C_MASK)==0);
     262             : }
     263             : 
     264             : /**
     265             :  * Checks if c is in \p{graph}\p{blank} - \p{cntrl}.
     266             :  * Implements UCHAR_POSIX_PRINT.
     267             :  * @internal
     268             :  */
     269             : U_CFUNC UBool
     270           0 : u_isprintPOSIX(UChar32 c) {
     271             :     uint32_t props;
     272           0 :     GET_PROPS(c, props);
     273             :     /*
     274             :      * The only cntrl character in graph+blank is TAB (in blank).
     275             :      * Here we implement (blank-TAB)=Zs instead of calling u_isblank().
     276             :      */
     277           0 :     return (UBool)((GET_CATEGORY(props)==U_SPACE_SEPARATOR) || u_isgraphPOSIX(c));
     278             : }
     279             : 
     280             : U_CAPI UBool U_EXPORT2
     281           0 : u_isgraph(UChar32 c) {
     282             :     uint32_t props;
     283           0 :     GET_PROPS(c, props);
     284             :     /* comparing ==0 returns FALSE for the categories mentioned */
     285           0 :     return (UBool)((CAT_MASK(props)&
     286             :                     (U_GC_CC_MASK|U_GC_CF_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
     287           0 :                    ==0);
     288             : }
     289             : 
     290             : /**
     291             :  * Checks if c is in
     292             :  * [^\p{space}\p{gc=Control}\p{gc=Surrogate}\p{gc=Unassigned}]
     293             :  * with space=\p{Whitespace} and Control=Cc.
     294             :  * Implements UCHAR_POSIX_GRAPH.
     295             :  * @internal
     296             :  */
     297             : U_CFUNC UBool
     298           0 : u_isgraphPOSIX(UChar32 c) {
     299             :     uint32_t props;
     300           0 :     GET_PROPS(c, props);
     301             :     /* \p{space}\p{gc=Control} == \p{gc=Z}\p{Control} */
     302             :     /* comparing ==0 returns FALSE for the categories mentioned */
     303           0 :     return (UBool)((CAT_MASK(props)&
     304             :                     (U_GC_CC_MASK|U_GC_CS_MASK|U_GC_CN_MASK|U_GC_Z_MASK))
     305           0 :                    ==0);
     306             : }
     307             : 
     308             : U_CAPI UBool U_EXPORT2
     309           0 : u_ispunct(UChar32 c) {
     310             :     uint32_t props;
     311           0 :     GET_PROPS(c, props);
     312           0 :     return (UBool)((CAT_MASK(props)&U_GC_P_MASK)!=0);
     313             : }
     314             : 
     315             : /* Checks if the Unicode character can start a Unicode identifier.*/
     316             : U_CAPI UBool U_EXPORT2
     317           0 : u_isIDStart(UChar32 c) {
     318             :     /* same as u_isalpha() */
     319             :     uint32_t props;
     320           0 :     GET_PROPS(c, props);
     321           0 :     return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_NL_MASK))!=0);
     322             : }
     323             : 
     324             : /* Checks if the Unicode character can be a Unicode identifier part other than starting the
     325             :  identifier.*/
     326             : U_CAPI UBool U_EXPORT2
     327           0 : u_isIDPart(UChar32 c) {
     328             :     uint32_t props;
     329           0 :     GET_PROPS(c, props);
     330             :     return (UBool)(
     331           0 :            (CAT_MASK(props)&
     332             :             (U_GC_ND_MASK|U_GC_NL_MASK|
     333             :              U_GC_L_MASK|
     334             :              U_GC_PC_MASK|U_GC_MC_MASK|U_GC_MN_MASK)
     335           0 :            )!=0 ||
     336           0 :            u_isIDIgnorable(c));
     337             : }
     338             : 
     339             : /*Checks if the Unicode character can be ignorable in a Java or Unicode identifier.*/
     340             : U_CAPI UBool U_EXPORT2
     341           0 : u_isIDIgnorable(UChar32 c) {
     342           0 :     if(c<=0x9f) {
     343           0 :         return u_isISOControl(c) && !IS_THAT_ASCII_CONTROL_SPACE(c);
     344             :     } else {
     345             :         uint32_t props;
     346           0 :         GET_PROPS(c, props);
     347           0 :         return (UBool)(GET_CATEGORY(props)==U_FORMAT_CHAR);
     348             :     }
     349             : }
     350             : 
     351             : /*Checks if the Unicode character can start a Java identifier.*/
     352             : U_CAPI UBool U_EXPORT2
     353           0 : u_isJavaIDStart(UChar32 c) {
     354             :     uint32_t props;
     355           0 :     GET_PROPS(c, props);
     356           0 :     return (UBool)((CAT_MASK(props)&(U_GC_L_MASK|U_GC_SC_MASK|U_GC_PC_MASK))!=0);
     357             : }
     358             : 
     359             : /*Checks if the Unicode character can be a Java identifier part other than starting the
     360             :  * identifier.
     361             :  */
     362             : U_CAPI UBool U_EXPORT2
     363           0 : u_isJavaIDPart(UChar32 c) {
     364             :     uint32_t props;
     365           0 :     GET_PROPS(c, props);
     366             :     return (UBool)(
     367           0 :            (CAT_MASK(props)&
     368             :             (U_GC_ND_MASK|U_GC_NL_MASK|
     369             :              U_GC_L_MASK|
     370             :              U_GC_SC_MASK|U_GC_PC_MASK|
     371             :              U_GC_MC_MASK|U_GC_MN_MASK)
     372           0 :            )!=0 ||
     373           0 :            u_isIDIgnorable(c));
     374             : }
     375             : 
     376             : U_CAPI int32_t U_EXPORT2
     377           0 : u_charDigitValue(UChar32 c) {
     378             :     uint32_t props;
     379             :     int32_t value;
     380           0 :     GET_PROPS(c, props);
     381           0 :     value=(int32_t)GET_NUMERIC_TYPE_VALUE(props)-UPROPS_NTV_DECIMAL_START;
     382           0 :     if(value<=9) {
     383           0 :         return value;
     384             :     } else {
     385           0 :         return -1;
     386             :     }
     387             : }
     388             : 
     389             : U_CAPI double U_EXPORT2
     390           0 : u_getNumericValue(UChar32 c) {
     391             :     uint32_t props;
     392             :     int32_t ntv;
     393           0 :     GET_PROPS(c, props);
     394           0 :     ntv=(int32_t)GET_NUMERIC_TYPE_VALUE(props);
     395             : 
     396           0 :     if(ntv==UPROPS_NTV_NONE) {
     397           0 :         return U_NO_NUMERIC_VALUE;
     398           0 :     } else if(ntv<UPROPS_NTV_DIGIT_START) {
     399             :         /* decimal digit */
     400           0 :         return ntv-UPROPS_NTV_DECIMAL_START;
     401           0 :     } else if(ntv<UPROPS_NTV_NUMERIC_START) {
     402             :         /* other digit */
     403           0 :         return ntv-UPROPS_NTV_DIGIT_START;
     404           0 :     } else if(ntv<UPROPS_NTV_FRACTION_START) {
     405             :         /* small integer */
     406           0 :         return ntv-UPROPS_NTV_NUMERIC_START;
     407           0 :     } else if(ntv<UPROPS_NTV_LARGE_START) {
     408             :         /* fraction */
     409           0 :         int32_t numerator=(ntv>>4)-12;
     410           0 :         int32_t denominator=(ntv&0xf)+1;
     411           0 :         return (double)numerator/denominator;
     412           0 :     } else if(ntv<UPROPS_NTV_BASE60_START) {
     413             :         /* large, single-significant-digit integer */
     414             :         double numValue;
     415           0 :         int32_t mant=(ntv>>5)-14;
     416           0 :         int32_t exp=(ntv&0x1f)+2;
     417           0 :         numValue=mant;
     418             : 
     419             :         /* multiply by 10^exp without math.h */
     420           0 :         while(exp>=4) {
     421           0 :             numValue*=10000.;
     422           0 :             exp-=4;
     423             :         }
     424           0 :         switch(exp) {
     425             :         case 3:
     426           0 :             numValue*=1000.;
     427           0 :             break;
     428             :         case 2:
     429           0 :             numValue*=100.;
     430           0 :             break;
     431             :         case 1:
     432           0 :             numValue*=10.;
     433           0 :             break;
     434             :         case 0:
     435             :         default:
     436           0 :             break;
     437             :         }
     438             : 
     439           0 :         return numValue;
     440           0 :     } else if(ntv<UPROPS_NTV_FRACTION20_START) {
     441             :         /* sexagesimal (base 60) integer */
     442           0 :         int32_t numValue=(ntv>>2)-0xbf;
     443           0 :         int32_t exp=(ntv&3)+1;
     444             : 
     445           0 :         switch(exp) {
     446             :         case 4:
     447           0 :             numValue*=60*60*60*60;
     448           0 :             break;
     449             :         case 3:
     450           0 :             numValue*=60*60*60;
     451           0 :             break;
     452             :         case 2:
     453           0 :             numValue*=60*60;
     454           0 :             break;
     455             :         case 1:
     456           0 :             numValue*=60;
     457           0 :             break;
     458             :         case 0:
     459             :         default:
     460           0 :             break;
     461             :         }
     462             : 
     463           0 :         return numValue;
     464           0 :     } else if(ntv<UPROPS_NTV_RESERVED_START) {
     465             :         // fraction-20 e.g. 3/80
     466           0 :         int32_t frac20=ntv-UPROPS_NTV_FRACTION20_START;  // 0..0x17
     467           0 :         int32_t numerator=2*(frac20&3)+1;
     468           0 :         int32_t denominator=20<<(frac20>>2);
     469           0 :         return (double)numerator/denominator;
     470             :     } else {
     471             :         /* reserved */
     472           0 :         return U_NO_NUMERIC_VALUE;
     473             :     }
     474             : }
     475             : 
     476             : U_CAPI int32_t U_EXPORT2
     477           0 : u_digit(UChar32 ch, int8_t radix) {
     478             :     int8_t value;
     479           0 :     if((uint8_t)(radix-2)<=(36-2)) {
     480           0 :         value=(int8_t)u_charDigitValue(ch);
     481           0 :         if(value<0) {
     482             :             /* ch is not a decimal digit, try latin letters */
     483           0 :             if(ch>=0x61 && ch<=0x7A) {
     484           0 :                 value=(int8_t)(ch-0x57);  /* ch - 'a' + 10 */
     485           0 :             } else if(ch>=0x41 && ch<=0x5A) {
     486           0 :                 value=(int8_t)(ch-0x37);  /* ch - 'A' + 10 */
     487           0 :             } else if(ch>=0xFF41 && ch<=0xFF5A) {
     488           0 :                 value=(int8_t)(ch-0xFF37);  /* fullwidth ASCII a-z */
     489           0 :             } else if(ch>=0xFF21 && ch<=0xFF3A) {
     490           0 :                 value=(int8_t)(ch-0xFF17);  /* fullwidth ASCII A-Z */
     491             :             }
     492             :         }
     493             :     } else {
     494           0 :         value=-1;   /* invalid radix */
     495             :     }
     496           0 :     return (int8_t)((value<radix) ? value : -1);
     497             : }
     498             : 
     499             : U_CAPI UChar32 U_EXPORT2
     500           0 : u_forDigit(int32_t digit, int8_t radix) {
     501           0 :     if((uint8_t)(radix-2)>(36-2) || (uint32_t)digit>=(uint32_t)radix) {
     502           0 :         return 0;
     503           0 :     } else if(digit<10) {
     504           0 :         return (UChar32)(0x30+digit);
     505             :     } else {
     506           0 :         return (UChar32)((0x61-10)+digit);
     507             :     }
     508             : }
     509             : 
     510             : /* miscellaneous, and support for uprops.cpp -------------------------------- */
     511             : 
     512             : U_CAPI void U_EXPORT2
     513           0 : u_getUnicodeVersion(UVersionInfo versionArray) {
     514           0 :     if(versionArray!=NULL) {
     515           0 :         uprv_memcpy(versionArray, dataVersion, U_MAX_VERSION_LENGTH);
     516             :     }
     517           0 : }
     518             : 
     519             : U_CFUNC uint32_t
     520           0 : u_getMainProperties(UChar32 c) {
     521             :     uint32_t props;
     522           0 :     GET_PROPS(c, props);
     523           0 :     return props;
     524             : }
     525             : 
     526             : U_CFUNC uint32_t
     527         923 : u_getUnicodeProperties(UChar32 c, int32_t column) {
     528         923 :     U_ASSERT(column>=0);
     529         923 :     if(column>=propsVectorsColumns) {
     530           0 :         return 0;
     531             :     } else {
     532         923 :         uint16_t vecIndex=UTRIE2_GET16(&propsVectorsTrie, c);
     533         923 :         return propsVectors[vecIndex+column];
     534             :     }
     535             : }
     536             : 
     537             : U_CFUNC int32_t
     538           0 : uprv_getMaxValues(int32_t column) {
     539           0 :     switch(column) {
     540             :     case 0:
     541           0 :         return indexes[UPROPS_MAX_VALUES_INDEX];
     542             :     case 2:
     543           0 :         return indexes[UPROPS_MAX_VALUES_2_INDEX];
     544             :     default:
     545           0 :         return 0;
     546             :     }
     547             : }
     548             : 
     549             : U_CAPI void U_EXPORT2
     550           0 : u_charAge(UChar32 c, UVersionInfo versionArray) {
     551           0 :     if(versionArray!=NULL) {
     552           0 :         uint32_t version=u_getUnicodeProperties(c, 0)>>UPROPS_AGE_SHIFT;
     553           0 :         versionArray[0]=(uint8_t)(version>>4);
     554           0 :         versionArray[1]=(uint8_t)(version&0xf);
     555           0 :         versionArray[2]=versionArray[3]=0;
     556             :     }
     557           0 : }
     558             : 
     559             : U_CAPI UScriptCode U_EXPORT2
     560         658 : uscript_getScript(UChar32 c, UErrorCode *pErrorCode) {
     561             :     uint32_t scriptX;
     562         658 :     if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
     563           0 :         return USCRIPT_INVALID_CODE;
     564             :     }
     565         658 :     if((uint32_t)c>0x10ffff) {
     566           0 :         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
     567           0 :         return USCRIPT_INVALID_CODE;
     568             :     }
     569         658 :     scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
     570         658 :     if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
     571         658 :         return (UScriptCode)scriptX;
     572           0 :     } else if(scriptX<UPROPS_SCRIPT_X_WITH_INHERITED) {
     573           0 :         return USCRIPT_COMMON;
     574           0 :     } else if(scriptX<UPROPS_SCRIPT_X_WITH_OTHER) {
     575           0 :         return USCRIPT_INHERITED;
     576             :     } else {
     577           0 :         return (UScriptCode)scriptExtensions[scriptX&UPROPS_SCRIPT_MASK];
     578             :     }
     579             : }
     580             : 
     581             : U_CAPI UBool U_EXPORT2
     582           0 : uscript_hasScript(UChar32 c, UScriptCode sc) {
     583             :     const uint16_t *scx;
     584           0 :     uint32_t scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
     585           0 :     if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
     586           0 :         return sc==(UScriptCode)scriptX;
     587             :     }
     588             : 
     589           0 :     scx=scriptExtensions+(scriptX&UPROPS_SCRIPT_MASK);
     590           0 :     if(scriptX>=UPROPS_SCRIPT_X_WITH_OTHER) {
     591           0 :         scx=scriptExtensions+scx[1];
     592             :     }
     593           0 :     if(sc>=USCRIPT_CODE_LIMIT) {
     594             :         /* Guard against bogus input that would make us go past the Script_Extensions terminator. */
     595           0 :         return FALSE;
     596             :     }
     597           0 :     while(sc>*scx) {
     598           0 :         ++scx;
     599             :     }
     600           0 :     return sc==(*scx&0x7fff);
     601             : }
     602             : 
     603             : U_CAPI int32_t U_EXPORT2
     604           0 : uscript_getScriptExtensions(UChar32 c,
     605             :                             UScriptCode *scripts, int32_t capacity,
     606             :                             UErrorCode *pErrorCode) {
     607             :     uint32_t scriptX;
     608             :     int32_t length;
     609             :     const uint16_t *scx;
     610             :     uint16_t sx;
     611           0 :     if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
     612           0 :         return 0;
     613             :     }
     614           0 :     if(capacity<0 || (capacity>0 && scripts==NULL)) {
     615           0 :         *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
     616           0 :         return 0;
     617             :     }
     618           0 :     scriptX=u_getUnicodeProperties(c, 0)&UPROPS_SCRIPT_X_MASK;
     619           0 :     if(scriptX<UPROPS_SCRIPT_X_WITH_COMMON) {
     620           0 :         if(capacity==0) {
     621           0 :             *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
     622             :         } else {
     623           0 :             scripts[0]=(UScriptCode)scriptX;
     624             :         }
     625           0 :         return 1;
     626             :     }
     627             : 
     628           0 :     scx=scriptExtensions+(scriptX&UPROPS_SCRIPT_MASK);
     629           0 :     if(scriptX>=UPROPS_SCRIPT_X_WITH_OTHER) {
     630           0 :         scx=scriptExtensions+scx[1];
     631             :     }
     632           0 :     length=0;
     633           0 :     do {
     634           0 :         sx=*scx++;
     635           0 :         if(length<capacity) {
     636           0 :             scripts[length]=(UScriptCode)(sx&0x7fff);
     637             :         }
     638           0 :         ++length;
     639           0 :     } while(sx<0x8000);
     640           0 :     if(length>capacity) {
     641           0 :         *pErrorCode=U_BUFFER_OVERFLOW_ERROR;
     642             :     }
     643           0 :     return length;
     644             : }
     645             : 
     646             : U_CAPI UBlockCode U_EXPORT2
     647           0 : ublock_getCode(UChar32 c) {
     648           0 :     return (UBlockCode)((u_getUnicodeProperties(c, 0)&UPROPS_BLOCK_MASK)>>UPROPS_BLOCK_SHIFT);
     649             : }
     650             : 
     651             : /* property starts for UnicodeSet ------------------------------------------- */
     652             : 
     653             : static UBool U_CALLCONV
     654           0 : _enumPropertyStartsRange(const void *context, UChar32 start, UChar32 end, uint32_t value) {
     655             :     /* add the start code point to the USet */
     656           0 :     const USetAdder *sa=(const USetAdder *)context;
     657           0 :     sa->add(sa->set, start);
     658             :     (void)end;
     659             :     (void)value;
     660           0 :     return TRUE;
     661             : }
     662             : 
     663             : #define USET_ADD_CP_AND_NEXT(sa, cp) sa->add(sa->set, cp); sa->add(sa->set, cp+1)
     664             : 
     665             : U_CFUNC void U_EXPORT2
     666           0 : uchar_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
     667           0 :     if(U_FAILURE(*pErrorCode)) {
     668           0 :         return;
     669             :     }
     670             : 
     671             :     /* add the start code point of each same-value range of the main trie */
     672           0 :     utrie2_enum(&propsTrie, NULL, _enumPropertyStartsRange, sa);
     673             : 
     674             :     /* add code points with hardcoded properties, plus the ones following them */
     675             : 
     676             :     /* add for u_isblank() */
     677           0 :     USET_ADD_CP_AND_NEXT(sa, TAB);
     678             : 
     679             :     /* add for IS_THAT_CONTROL_SPACE() */
     680           0 :     sa->add(sa->set, CR+1); /* range TAB..CR */
     681           0 :     sa->add(sa->set, 0x1c);
     682           0 :     sa->add(sa->set, 0x1f+1);
     683           0 :     USET_ADD_CP_AND_NEXT(sa, NL);
     684             : 
     685             :     /* add for u_isIDIgnorable() what was not added above */
     686           0 :     sa->add(sa->set, DEL); /* range DEL..NBSP-1, NBSP added below */
     687           0 :     sa->add(sa->set, HAIRSP);
     688           0 :     sa->add(sa->set, RLM+1);
     689           0 :     sa->add(sa->set, INHSWAP);
     690           0 :     sa->add(sa->set, NOMDIG+1);
     691           0 :     USET_ADD_CP_AND_NEXT(sa, ZWNBSP);
     692             : 
     693             :     /* add no-break spaces for u_isWhitespace() what was not added above */
     694           0 :     USET_ADD_CP_AND_NEXT(sa, NBSP);
     695           0 :     USET_ADD_CP_AND_NEXT(sa, FIGURESP);
     696           0 :     USET_ADD_CP_AND_NEXT(sa, NNBSP);
     697             : 
     698             :     /* add for u_digit() */
     699           0 :     sa->add(sa->set, U_a);
     700           0 :     sa->add(sa->set, U_z+1);
     701           0 :     sa->add(sa->set, U_A);
     702           0 :     sa->add(sa->set, U_Z+1);
     703           0 :     sa->add(sa->set, U_FW_a);
     704           0 :     sa->add(sa->set, U_FW_z+1);
     705           0 :     sa->add(sa->set, U_FW_A);
     706           0 :     sa->add(sa->set, U_FW_Z+1);
     707             : 
     708             :     /* add for u_isxdigit() */
     709           0 :     sa->add(sa->set, U_f+1);
     710           0 :     sa->add(sa->set, U_F+1);
     711           0 :     sa->add(sa->set, U_FW_f+1);
     712           0 :     sa->add(sa->set, U_FW_F+1);
     713             : 
     714             :     /* add for UCHAR_DEFAULT_IGNORABLE_CODE_POINT what was not added above */
     715           0 :     sa->add(sa->set, WJ); /* range WJ..NOMDIG */
     716           0 :     sa->add(sa->set, 0xfff0);
     717           0 :     sa->add(sa->set, 0xfffb+1);
     718           0 :     sa->add(sa->set, 0xe0000);
     719           0 :     sa->add(sa->set, 0xe0fff+1);
     720             : 
     721             :     /* add for UCHAR_GRAPHEME_BASE and others */
     722           0 :     USET_ADD_CP_AND_NEXT(sa, CGJ);
     723             : }
     724             : 
     725             : U_CFUNC void U_EXPORT2
     726           0 : upropsvec_addPropertyStarts(const USetAdder *sa, UErrorCode *pErrorCode) {
     727           0 :     if(U_FAILURE(*pErrorCode)) {
     728           0 :         return;
     729             :     }
     730             : 
     731             :     /* add the start code point of each same-value range of the properties vectors trie */
     732             :     if(propsVectorsColumns>0) {
     733             :         /* if propsVectorsColumns==0 then the properties vectors trie may not be there at all */
     734           0 :         utrie2_enum(&propsVectorsTrie, NULL, _enumPropertyStartsRange, sa);
     735             :     }
     736             : }

Generated by: LCOV version 1.13