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