Skip to content

UnicodeSet documentation - #4171

Draft
eggrobin wants to merge 7 commits into
unicode-org:mainfrom
eggrobin:unicodeset-docs
Draft

UnicodeSet documentation#4171
eggrobin wants to merge 7 commits into
unicode-org:mainfrom
eggrobin:unicodeset-docs

Conversation

@eggrobin

@eggrobin eggrobin commented Sep 8, 2026

Copy link
Copy Markdown
Member

TODO: Please describe your changes here.

TODO: Please read the following on ICU Contributing, and then delete these instructions.

Thank you for your pull request!

TODO: Fill out the checklist below.

Checklist

  • Required: Issue filed: ICU-NNNNN
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable
  • Approver: Feel free to merge on my behalf

@markusicu markusicu self-assigned this Sep 8, 2026
character strings. The contents of that object can be specified either by
patterns or by building them programmatically.
A UnicodeSet is an object that represents a finite set of Unicode code point
sequences. The contents of that object can be specified either by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sequences. The contents of that object can be specified either by
sequences, optimized for single code points. The contents of that object can be specified either by

character strings. The contents of that object can be specified either by
patterns or by building them programmatically.
A UnicodeSet is an object that represents a finite set of Unicode code point
sequences. The contents of that object can be specified either by

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid double spaces between sentences.

patterns or by building them programmatically.
A UnicodeSet is an object that represents a finite set of Unicode code point
sequences. The contents of that object can be specified either by
patterns using the UnicodeSet syntax defined in

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
patterns using the UnicodeSet syntax defined in
pattern strings using the UnicodeSet syntax defined in

Comment on lines +49 to +50
* <em>character classes</em> used in regular expressions. A UnicodeSet specifies a finite set of
* Unicode code points sequences.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* <em>character classes</em> used in regular expressions. A UnicodeSet specifies a finite set of
* Unicode code points sequences.
* <em>character classes</em> used in regular expressions. A UnicodeSet specifies a finite set of
* Unicode code point sequences, optimized for single code points.

* toPattern()</code> API from the <code>
* java.text.Format</code>-derived classes. Unlike the methods that add characters, add categories,
* and control the logic of the set, the method <code>applyPattern()</code> sets all attributes of a
* <code>UnicodeSet</code> at once, based on a string pattern.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* <code>UnicodeSet</code> at once, based on a string pattern.
* <code>UnicodeSet</code> at once, based on a pattern string.

Comment on lines +164 to +168
* `\u` [four-hexadecimal-digits](https://www.unicode.org/reports/tr61/#four-hexadecimal-digits)
`\u` [four-hexadecimal-digits](https://www.unicode.org/reports/tr61/#four-hexadecimal-digits)
where the first constituent [four-hexadecimal-digits](https://www.unicode.org/reports/tr61/#four-hexadecimal-digits)
represent a high surrogate and the second constituent
[four-hexadecimal-digits](https://www.unicode.org/reports/tr61/#four-hexadecimal-digits)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional:
when you refer to the same grammar production multiple times closely together, i would put a link only on the first one; the rest can just be plain text
(more readable .md file)

Comment on lines +175 to +187
* `$` is added as a [set-operator](https://www.unicode.org/reports/tr61/#set-operator), and the
following alternatives are added to [Content](https://www.unicode.org/reports/tr61/#Content)</a>:
> | `$`
> | [ElementList](https://www.unicode.org/reports/tr61/#ElementList) `$`
> | [UnescapedHyphenMinus](https://www.unicode.org/reports/tr61/#UnescapedHyphenMinus) [ElementList](https://www.unicode.org/reports/tr61/#ElementList) `$`
The following alternative is added to [ElementList](https://www.unicode.org/reports/tr61/#ElementList):
> | `$` [Elements](https://www.unicode.org/reports/tr61/#Elements)
The following alternative is added to [Union](https://www.unicode.org/reports/tr61/#Union):
> | `$` [UnicodeSet](https://www.unicode.org/reports/tr61/#UnicodeSet)
When the [set-operator](https://www.unicode.org/reports/tr61/#set-operator) `$` occurs
as an immediate constituent of a [Content](https://www.unicode.org/reports/tr61/#Content)</a>,
it represents the noncharacter code point U+FFFF.
When it occurs anywhere else, it represents the character U+0024 $ DOLLAR SIGN.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please precede the legalese with some prose like "a literal $ at the end of a set represents the noncharacter code point U+FFFF"

... and maybe even add something like "this is used in Transliterator rule syntax"
with a link to
https://unicode-org.github.io/icu/userguide/transforms/general/rules.html#%C3%A6ther

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was thinking about that as I was updating the comments in the parser accordingly (the legalese is going to get worse!).

element is introduced:
> variable ⩴ $ reference
where the function `SymbolTable::parseReference` defines the syntactic category
reference. The expansion of a variable is defined by `SymbolTable::lookup`; it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the word reference wants to be quoted or emphasized or something, to suggest that it's the term introduced in the lexical element above

Comment on lines -190 to -193
> :point_right: **Note**:*ICU Regular Expression set expressions have a different (but similar) syntax,
and a different set of recognized backslash escapes. \[Sets\] in ICU Regular
Expressions follow the conventions from Perl and Java regular expressions rather
than the pattern syntax from ICU UnicodeSet.*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this note somewhere on this page

Comment on lines +163 to +168
* the support for variables interacts with the API: If a {@link SymbolTable} is passed to the
* constructor of {@code UnicodeSet}, a new lexical element is introduced:
*
* <blockquote>
*
* <table>
* <tr style="vertical-align: top">
* <td style="white-space: nowrap; vertical-align: top;text-align:right;"><code>pattern :=&nbsp; </code></td>
* <td style="vertical-align: top;"><code>('[' '^'? item* ']') |
* property</code></td>
* </tr>
* <tr style="vertical-align: top">
* <td style="white-space: nowrap; vertical-align: top;text-align:right;"><code>item :=&nbsp; </code></td>
* <td style="vertical-align: top;"><code>char | (char '-' char) | pattern-expr<br>
* </code></td>
* </tr>
* <tr style="vertical-align: top">
* <td style="white-space: nowrap; vertical-align: top;text-align:right;"><code>pattern-expr :=&nbsp; </code></td>
* <td style="vertical-align: top;"><code>pattern | pattern-expr pattern |
* pattern-expr op pattern<br>
* </code></td>
* </tr>
* <tr style="vertical-align: top">
* <td style="white-space: nowrap; vertical-align: top;text-align:right;"><code>op :=&nbsp; </code></td>
* <td style="vertical-align: top;"><code>'&amp;' | '-'<br>
* </code></td>
* </tr>
* <tr style="vertical-align: top">
* <td style="white-space: nowrap; vertical-align: top;text-align:right;"><code>special :=&nbsp; </code></td>
* <td style="vertical-align: top;"><code>'[' | ']' | '-'<br>
* </code></td>
* </tr>
* <tr style="vertical-align: top">
* <td style="white-space: nowrap; vertical-align: top;text-align:right;"><code>char :=&nbsp; </code></td>
* <td style="vertical-align: top;"><em>any character that is not</em><code> special<br>
* | ('\\' </code><em>any character</em><code>)<br>
* | ('&#92;u' hex hex hex hex)<br>
* </code></td>
* </tr>
* <tr style="vertical-align: top">
* <td style="white-space: nowrap; vertical-align: top;text-align:right;"><code>hex :=&nbsp; </code></td>
* <td style="vertical-align: top;"><code>'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |<br>
* &nbsp;&nbsp;&nbsp;&nbsp;'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f'</code></td>
* </tr>
* <tr>
* <td style="white-space: nowrap; vertical-align: top;text-align:right;"><code>property :=&nbsp; </code></td>
* <td style="vertical-align: top;"><em>a Unicode property set pattern</em></td>
* </tr>
* </table>
* variable ⩴ <code>$</code> reference

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: maybe reduce the duplication between this+following and the equivalent User Guide text?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants