• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2layout: default
3title: Properties
4nav_order: 2
5parent: Chars and Strings
6---
7<!--
8© 2020 and later: Unicode, Inc. and others.
9License & terms of use: http://www.unicode.org/copyright.html
10-->
11
12# Properties
13
14## Overview
15
16Text processing requires that a program treat text appropriately. If text is
17exchanged between several systems, it is important for them to process the text
18consistently. This is done by assigning each character, or a range of
19characters, attributes or properties used for text processing, and by defining
20standard algorithms for at least the basic text operations.
21
22Traditionally, such attributes and algorithms have not been well-defined for
23most character sets, and text processing had to rely on ad-hoc solutions. Over
24time, standards were created for querying properties of the system codepage.
25However, the set of these properties was limited. Their data was not coordinated
26among implementations, and standard algorithms were not available.
27
28It is one of the strengths of Unicode that it not only defines a very large
29character set, but also assigns a comprehensive set of properties and usage
30notes to all characters. It defines standard algorithms for critical text
31processing, and the data is publicly provided and kept up-to-date. See
32https://www.unicode.org/ and https://www.unicode.org/main.html for more information.
33
34Sample code is available in the ICU source code library at
35[icu4c/source/samples/props/props.cpp](https://github.com/unicode-org/icu/blob/master/icu4c/source/samples/props/props.cpp).
36See also the source code for the [Unicode
37browser](https://github.com/unicode-org/icu-demos/tree/master/ubrowse) demo
38application, which can be used
39[online](http://demo.icu-project.org/icu-bin/ubrowse) to browse Unicode
40characters with their properties.
41
42## Unicode Character Database properties in ICU APIs
43
44The following table shows all Unicode Character Database properties (except for
45purely "extracted" ones and Unihan properties) and the corresponding ICU APIs.
46Most of the time, ICU4C provides functions in
47icu4c/source/common/unicode/uchar.h and ICU4J provides parallel functions in the
48com.ibm.icu.lang.UCharacter class. Properties of a single Unicode character are
49accessed by its 21-bit code point value (type: UChar32=int32_t in C/C++, int in
50Java).
51
52[Surrogate code points](https://www.unicode.org/glossary/#surrogate_code_point)
53mostly have default property values, except for the General_Category (gc=Cs).
54
55For integer values outside the Unicode code point range (negative or ≥
560x110000), most API functions return null values (false, 0, etc.). API functions
57that map a code point to another (e.g., u_foldCase()/UCharacter.foldCase())
58normally return out-of-range values (i.e., map them to themselves), just like
59for unassigned code points or generally code points that have no specific
60mappings. In particular, -1 (=U_SENTINEL in ICU4C) is mapped to -1.
61
62Most properties are also available via UnicodeSet APIs and patterns. See the
63Lookup section below.
64
65See [UAX #44, Unicode Character
66Database](https://www.unicode.org/reports/tr44/#Properties) itself for
67comparison. The UCD files
68[PropertyAliases.txt](https://www.unicode.org/Public/UCD/latest/ucd/PropertyAliases.txt)
69and
70[PropertyValueAliases.txt](https://www.unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt)
71list all properties and their values by name and type.
72
73UAX #44 also shows which UCD files have data for which properties,
74and many other useful details.
75
76Most properties that use binary, integer, or enumerated values are available via
77functions u_hasBinaryProperty and u_getIntPropertyValue which take UProperty
78enum constants to select the property. (ICU4J UCharacter member functions do not
79have the "u_" prefix.) The constant names include the long property name
80according to PropertyAliases.txt, e.g., UCHAR_LINE_BREAK. Corresponding property
81value enum constant names often contain the short property name and the long
82value name, e.g., U_LB_LINE_FEED. For enumeration/integer type properties, the
83enumeration result type is also listed here.
84
85Some UnicodeSet APIs use the same UProperty constants. Other UnicodeSet APIs and
86UnicodeSet and regular expression patterns use the long or short property
87aliases and property value aliases (see PropertyAliases.txt and
88PropertyValueAliases.txt).
89
90There is one pseudo-property, UCHAR_GENERAL_CATEGORY_MASK for which the APIs do
91not use a single value but a bit-set (a mask) of zero or more values, with each
92bit corresponding to one UCHAR_GENERAL_CATEGORY value. This allows ICU to
93represent property value aliases for multiple general categories, like "Letters"
94(which stands for "Uppercase Letters", "Lowercase Letters", etc.). In other
95words, there are two ICU properties for the same Unicode property, one
96delivering single values (for per-code point lookup) and the other delivering
97sets of values (for use with value aliases and UnicodeSet).
98
99| UCD Name | Type |  | ICU4C uchar.h / ICU4J UCharacter |
100|--------------|--------|-----|------------------------------|
101| Age | Unicode version | (U) | C: u_charAge fills in UVersionInfo<br>Java: getAge returns a VersionInfo reference |
102| Alphabetic | binary | (U) | u_isUAlphabetic, UCHAR_ALPHABETIC |
103| ASCII_Hex_Digit | binary | (U) | UCHAR_ASCII_HEX_DIGIT |
104| Bidi_Class | enum | (U) | u_charDirection, UCHAR_BIDI_CLASS<br>returns enum UCharDirection |
105| Bidi_Control | binary | (U) | UCHAR_BIDI_CONTROL |
106| Bidi_Mirrored | binary | (U) | u_isMirrored, UCHAR_BIDI_MIRRORED |
107| Bidi_Mirroring_Glyph | code point |  | u_charMirror |
108| Block | enum | (U) | ublock_getCode, UCHAR_BLOCK<br>returns enum UBlockCode |
109| Canonical_Combining_Class | 0..255 | (U) | u_getCombiningClass, UCHAR_CANONICAL_COMBINING_CLASS |
110| Case_Folding | Unicode string |  | u_strFoldCase (ustring.h) |
111| Case_Ignorable | binary | (U) | UCHAR_CASE_IGNORABLE |
112| Cased | binary | (U) | UCHAR_CASED |
113| Changes_When_Casefolded | binary | (U) | UCHAR_CHANGES_WHEN_CASEFOLDED |
114| Changes_When_Casemapped | binary | (U) | UCHAR_CHANGES_WHEN_CASEMAPPED |
115| Changes_When_NFKC_Casefolded | binary | (U) | UCHAR_CHANGES_WHEN_NFKC_CASEFOLDED |
116| Changes_When_Lowercased | binary | (U) | UCHAR_CHANGES_WHEN_LOWERCASED |
117| Changes_When_Titlecased | binary | (U) | UCHAR_CHANGES_WHEN_TITLECASED |
118| Changes_When_Uppercased | binary | (U) | UCHAR_CHANGES_WHEN_UPPERCASED |
119| Composition_Exclusion | binary | (c) | contributes to Full_Composition_Exclusion |
120| Dash | binary | (U) | UCHAR_DASH |
121| Decomposition_Mapping | Unicode string |  | NFKC Normalizer2::getRawDecomposition() |
122| Decomposition_Type | enum | (U) | UCHAR_DECOMPOSITION_TYPE<br>returns enum UDecompositionType |
123| Default_Ignorable_Code_Point | binary | (U) | UCHAR_DEFAULT​_IGNORABLE_CODE_POINT |
124| Deprecated | binary | (U) | UCHAR_DEPRECATED |
125| Diacritic | binary | (U) | UCHAR_DIACRITIC |
126| East_Asian_Width | enum | (U) | UCHAR_EAST_ASIAN_WIDTH<br>returns enum UEastAsianWidth |
127| Expands_On_NF* | binary |  | available via normalization API (normalizer2.h) |
128| Extender | binary | (U) | UCHAR_EXTENDER |
129| FC_NFKC_Closure | Unicode string |  | u_getFC_NFKC_Closure |
130| Full_Composition_Exclusion | binary | (U) | UCHAR_FULL​_COMPOSITION_EXCLUSION |
131| General_Category | enum | (U) | u_charType, UCHAR_GENERAL_CATEGORY, UCHAR_GENERAL_CATEGORY_MASK<br>returns enum UCharCategory |
132| Grapheme_Base | binary | (U) | UCHAR_GRAPHEME_BASE |
133| Grapheme_Cluster_Break | enum | (U) | UCHAR_GRAPHEME_CLUSTER_BREAK<br>returns enum UGraphemeClusterBreak |
134| Grapheme_Extend | binary | (U) | UCHAR_GRAPHEME_EXTEND |
135| Grapheme_Link | binary | (U) | UCHAR_GRAPHEME_LINK |
136| Hangul_Syllable_Type | enum | (U) | UCHAR_HANGUL_SYLLABLE_TYPE<br>returns enum UHangulSyllableType |
137| Hex_Digit | binary | (U) | UCHAR_HEX_DIGIT |
138| Hyphen | binary | (U) | UCHAR_HYPHEN |
139| ID_Continue | binary | (U) | UCHAR_ID_CONTINUE |
140| ID_Start | binary | (U) | UCHAR_ID_START |
141| Ideographic | binary | (U) | UCHAR_IDEOGRAPHIC |
142| IDS_Binary_Operator | binary | (U) | UCHAR_IDS_BINARY_OPERATOR |
143| IDS_Triary_Operator | binary | (U) | UCHAR_IDS_TRINARY_OPERATOR |
144| Indic_Positional_Category | enum | (U) | UCHAR_INDIC_POSITIONAL_CATEGORY<br>returns enum UIndicPositionalCategory |
145| Indic_Syllabic_Category | enum | (U) | UCHAR_INDIC_SYLLABIC_CATEGORY<br>returns enum UIndicSyllabicCategory |
146| ISO_Comment | ASCII string |  | u_getISOComment |
147| Jamo_Short_Name | ASCII string | (c) | contributes to Name |
148| Join_Control | binary | (U) | UCHAR_JOIN_CONTROL |
149| Joining_Group | enum | (U) | UCHAR_JOINING_GROUP<br>returns enum UJoiningGroup |
150| Joining_Type | enum | (U) | UCHAR_JOINING_TYPE<br>returns enum UJoiningType |
151| Line_Break | enum | (U) | UCHAR_LINE_BREAK<br>returns enum ULineBreak |
152| Logical_Order_Exception | binary | (U) | UCHAR_LOGICAL_ORDER_EXCEPTION |
153| Lowercase | binary | (U) | u_isULowercase, UCHAR_LOWERCASE |
154| Lowercase_Mapping | Unicode string |  | available via u_strToLower (ustring.h) |
155| Math | binary | (U) | UCHAR_MATH |
156| Name | ASCII string | (U) | u_charName(U_UNICODE_CHAR_NAME or U_EXTENDED_CHAR_NAME) |
157| Name_Alias | ASCII string |  | u_charName(U_CHAR_NAME_ALIAS) |
158| NF*_QuickCheck | enum | (U) | UCHAR_NF*_QUICK_CHECK and available via quickCheck (normalizer2.h)<br>returns UNormalizationCheckResult (no/maybe/yes) |
159| NFKC_Casefold | Unicode string |  | available via normalization API (normalizer2.h "nfkc_cf") |
160| Noncharacter_Code_Point | binary | (U) | UCHAR_NONCHARACTER​_CODE_POINT, <br /> U_IS_UNICODE_NONCHAR (utf.h) |
161| Numeric_Type | enum | (U) | UCHAR_NUMERIC_TYPE<br>returns enum UNumericType |
162| Numeric_Value | double | (U) | u_getNumericValueJava/UnicodeSet: only non-negative integers, no fractions |
163| Other_Alphabetic | binary | (c) | contributes to Alphabetic |
164| Other_Default_Ignorable​_Code_Point | binary | (c) | contributes to Default_Ignorable​_Code_Point |
165| Other_Grapheme_Extend | binary | (c) | contributes to Grapheme_Extend |
166| Other_Lowercase | binary | (c) | contributes to Lowercase |
167| Other_Math | binary | (c) | contributes to Math |
168| Other_Uppercase | binary | (c) | contributes to Uppercase |
169| Pattern_Syntax | binary | (U) | UCHAR_PATTERN_SYNTAX |
170| Pattern_White_Space | binary | (U) | UCHAR_PATTERN_WHITE_SPACE |
171| Quotation_Mark | binary | (U) | UCHAR_QUOTATION_MARK |
172| Radical | binary | (U) | UCHAR_RADICAL |
173| Script | enum | (U) | uscript_getCode (uscript.h), UCHAR_SCRIPT<br>returns enum UScriptCode |
174| Script_Extensions | list | (U) | uscript_getScriptExtensions & uscript_hasScript (uscript.h), UCHAR_SCRIPT_EXTENSIONS<br>returns a list of enum UScriptCode values |
175| Sentence_Break | enum | (U) | UCHAR_SENTENCE_BREAK<br>returns enum USentenceBreak |
176| Simple_Case_Folding | code point |  | u_foldCase |
177| Simple_Lowercase_ Mapping | code point |  | u_tolower |
178| Simple_Titlecase_ Mapping | code point |  | u_totitle |
179| Simple_Uppercase_ Mapping | code point |  | u_toupper |
180| Soft_Dotted | binary | (U) | UCHAR_SOFT_DOTTED |
181| STerm | binary | (U) | UCHAR_S_TERM |
182| Terminal_Punctuation | binary | (U) | UCHAR_TERMINAL_PUNCTUATION |
183| Titlecase_Mapping | Unicode string |  | u_strToTitle (ustring.h) |
184| Unicode_1_Name | ASCII string | (U) | u_charName(U_UNICODE_10_CHAR_NAME or U_EXTENDED_CHAR_NAME) |
185| Unified_Ideograph | binary | (U) | UCHAR_UNIFIED_IDEOGRAPH |
186| Uppercase | binary | (U) | u_isUUppercase, UCHAR_UPPERCASE |
187| Uppercase_Mapping | Unicode string |  | u_strToUpper (ustring.h) |
188| Vertical_Orientation | enum | (U) | UCHAR_VERTICAL_ORIENTATION<br>returns enum UVerticalOrientation |
189| White_Space | binary | (U) | u_isUWhiteSpace, UCHAR_WHITE_SPACE |
190| Word_Break | enum | (U) | UCHAR_WORD_BREAK<br>returns enum UWordBreakValues |
191| XID_Continue | binary | (U) | UCHAR_XID_CONTINUE |
192| XID_Start | binary | (U) | UCHAR_XID_START |
193
194Notes:
195
1961.  (c) - This property only **contributes** to "real" properties (mostly
197    "Other_..." properties), so there is no direct support for this property in
198    ICU.
199
2002.  (U) - This property is available via the UnicodeSet APIs and patterns. Any
201    property available in UnicodeSet is also available in regular expressions.
202    Properties which are not available in UnicodeSet are generally those that
203    are not available through a UProperty selector.
204
2053.  UnicodeSet `[:scx=Arab:]` is a superset of `[:sc=Arab:]`;
206    see https://www.unicode.org/reports/tr18/#Script_Property
207
2084.  Full case mapping properties (e.g., Lowercase_Mapping) are complex.
209    The string case mapping functions that implement them handle language-specific
210    and/or context-sensitive mappings.
211    The output may have more code points or fewer code points than the input.
212
213## Customization
214
215ICU does not provide the means to modify properties at runtime. The properties
216are provided exactly as specified by a recent version of the Unicode Standard
217(as published in the [Character
218Database](http://www.unicode.org/onlinedat/online.html)).
219
220For custom sets and maps, it is easiest to make UnicodeSet or
221UCPTrie/CodePointTrie objects with the desired values.
222
223However, if an application requires custom properties (for example, for [Private
224Use](http://www.unicode.org/glossary/) characters), then it is possible to
225change or add them at build-time. This is doable but not easy.
226
227It is done by modifying the Character Database files copied into the ICU source
228tree at
229[icu4c/source/data/unidata](https://github.com/unicode-org/icu/tree/master/icu4c/source/data/unidata).
230Since ICU 49, most of the properties have been combined into one file,
231unidata/ppucd.txt (see the [Preparsed
232UCD](http://site.icu-project.org/design/props/ppucd) design doc). Some of the
233remaining UCD files are still inputs, others are only used for unit tests.
234
235To add a character to such a file, a line must be inserted into the file with
236the format used in that file (see the online documentation on the [Unicode
237site](http://www.unicode.org/reports/tr44/) for more information). After
238modifying one or more of these files, the ICU data needs to be rebuilt, and the
239resulting files need to be checked into the ICU source tree. The files are
240processed by special ICU tools outside of the normal ICU build. The
241[unidata/changes.txt](https://github.com/unicode-org/icu/blob/master/icu4c/source/data/unidata/changes.txt)
242file documents the process that has been used for the last several Unicode
243version updates; skip the file preparation and API update steps.
244
245Any available Unicode code point (0 to 10FFFF<sub>16</sub>) can be used.
246Code point values
247should be written with either 4, 5, or 6 hex digits. The minimum number of
248digits possible should be used (but no fewer than 4). Note that the Unicode
249Standard specifies that the 32 code points U+FDD0..U+FDEF and the 34 code points
250U+...xFFFE and U+...xFFFF (where x=0, 1, 2, ..., F, 10) are not characters,
251therefore they should not be added to any of the character database files.
252
253## Lookup
254
255For lookup by code point, iterate through the string, fetch code points, and
256either call the unicode/uchar.h / UCharacter or similar functions, or use
257dedicated sets and maps. For binary properties, and sets in general, there are
258also more efficient methods for iterating over substrings.
259
260### Binary property from code point
261
262Call one of the binary-property functions. Alternatively, make a UnicodeSet for
263the property (remember to freeze() it) or for a custom set of characters, and
264call contains().
265
266### Binary property over string
267
268It is often useful to partition a string into substrings where every character
269has the property, and substrings where every character does not have the
270property. For example, to split the string at separator characters, remove
271certain types of characters, trim white space, etc. Use a UnicodeSet with its
272span() and spanBack() methods (available in C++ in UTF-8 versions). In Java, you
273can also use a UnicodeSetSpanner.
274
275### Enumerated property from code point
276
277Call one of the int-property functions. Alternatively, build a UCPTrie /
278CodePointTrie (new in ICU 63) via its mutable version and build method, then use
279that to get the int value for each code point.
280
281### Enumerated property over string
282
283Easiest is to iterate over code points of the string and call per-code point
284lookup methods (or use a code point trie).
285
286The UCPTrie / CodePointTrie (new in ICU 63) also offers C macros and a Java
287String iterator class where the iteration and data lookup are integrated to
288avoid redundancies in validation and range checks.
289
290The UTF-16 code point macros and the Java String iterator also provide the code
291point as output, because it has to be fetched or assembled anyway.
292
293The UTF-8 macros do not assemble the code point because that would be some
294amount of extra work, but often only the lookup value is used and the code point
295is not needed. When it is needed after all, it is possible to take advantage of
296the macros having validated the byte sequence: If the sequence was ill-formed,
297then the trie's error value is set. Therefore, if a value other than the trie
298error value was returned, then the sequence was well-formed, and the code point
299can be fetched without revalidating the sequence (e.g., via U8_NEXT_UNSAFE()).
300Since the length of the sequence (1..4 bytes) is also known from the iteration
301(string index before/after next() call), an even simpler piece of code can be
302used. (See for example the ICU-internal function codePointFromValidUTF8() in
303normalizer2impl.cpp.)
304
305### Code point trie most-optimized UTF-16 access
306
307UTF-16 text processing can be further optimized by detecting surrogate pairs and
308assembling supplementary code points only when there is non-trivial data
309available.
310
311At build time, iterate over all supplementary code points
312(umutablecptrie_getRange() / MutableCodePointTrie.getRange() starting from
313U+10000) to see if there is non-trivial data for any of the supplementary code
314points associated with a lead surrogate. If so, then set a special
315(application-specific) value for the lead surrogate.
316
317At runtime, use UCPTRIE_FAST_BMP_GET() per code *unit*. If there is non-trivial
318data and the code unit is a lead surrogate, then check if a trail surrogate
319follows. If so, assemble the supplementary code point with
320U16_GET_SUPPLEMENTARY() and look up its value with UCPTRIE_FAST_SUPP_GET();
321otherwise deal with the unpaired surrogate in some way. (Java CodePointTrie.Fast
322and java.lang.Character have equivalent methods.)
323
324If there is only trivial data for lead and trail surrogates, then processing can
325often skip them. (In this case, there will be two data lookups, one for the lead
326surrogate and one for the trail surrogate, but they are fast, and this
327optimization speeds up the more common BMP characters by not checking for
328surrogates each time.)
329
330For example, in normalization or case mapping all characters that do not have
331any mappings are simply copied as is.
332
333## Properties in ICU Rule Syntax
334
335ICU rule syntaxes should use the Unicode Pattern_White_Space set as syntactic
336"spaces" to allow for the usage of white space characters outside of the normal
337ASCII range while still maintaining backward compatibility. See
338<https://www.unicode.org/reports/tr31/#Pattern_Syntax> for more information.
339