1999-12-28 23:57:50 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2001-03-22 00:09:10 +00:00
|
|
|
* Copyright (C) 1999, International Business Machines Corporation and others. All Rights Reserved.
|
1999-12-28 23:57:50 +00:00
|
|
|
**********************************************************************
|
|
|
|
* Date Name Description
|
|
|
|
* 10/20/99 alan Creation.
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UNICODESET_H
|
|
|
|
#define UNICODESET_H
|
|
|
|
|
2000-01-18 20:00:56 +00:00
|
|
|
#include "unicode/unifilt.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/unistr.h"
|
2002-10-30 18:24:00 +00:00
|
|
|
#include "unicode/uchar.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
class ParsePosition;
|
2000-02-08 02:49:15 +00:00
|
|
|
class SymbolTable;
|
2000-01-18 19:57:46 +00:00
|
|
|
class TransliterationRuleParser;
|
|
|
|
class TransliterationRule;
|
2001-10-08 23:26:58 +00:00
|
|
|
class Transliterator;
|
|
|
|
class TransliteratorParser;
|
2002-04-25 23:39:57 +00:00
|
|
|
class UVector;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2002-04-25 23:39:57 +00:00
|
|
|
* A mutable set of Unicode characters and multicharacter strings. Objects of this class
|
1999-12-28 23:57:50 +00:00
|
|
|
* represent <em>character classes</em> used in regular expressions.
|
2001-11-22 00:05:50 +00:00
|
|
|
* A character specifies a subset of Unicode code points. Legal
|
|
|
|
* code points are U+0000 to U+10FFFF, inclusive.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
2001-11-22 00:05:50 +00:00
|
|
|
* <p><code>UnicodeSet</code> supports two APIs. The first is the
|
|
|
|
* <em>operand</em> API that allows the caller to modify the value of
|
|
|
|
* a <code>UnicodeSet</code> object. It conforms to Java 2's
|
|
|
|
* <code>java.util.Set</code> interface, although
|
|
|
|
* <code>UnicodeSet</code> does not actually implement that
|
|
|
|
* interface. All methods of <code>Set</code> are supported, with the
|
|
|
|
* modification that they take a character range or single character
|
|
|
|
* instead of an <code>Object</code>, and they take a
|
|
|
|
* <code>UnicodeSet</code> instead of a <code>Collection</code>. The
|
|
|
|
* operand API may be thought of in terms of boolean logic: a boolean
|
|
|
|
* OR is implemented by <code>add</code>, a boolean AND is implemented
|
|
|
|
* by <code>retain</code>, a boolean XOR is implemented by
|
|
|
|
* <code>complement</code> taking an argument, and a boolean NOT is
|
|
|
|
* implemented by <code>complement</code> with no argument. In terms
|
|
|
|
* of traditional set theory function names, <code>add</code> is a
|
|
|
|
* union, <code>retain</code> is an intersection, <code>remove</code>
|
|
|
|
* is an asymmetric difference, and <code>complement</code> with no
|
|
|
|
* argument is a set complement with respect to the superset range
|
|
|
|
* <code>MIN_VALUE-MAX_VALUE</code>
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
|
|
|
* <p>The second API is the
|
|
|
|
* <code>applyPattern()</code>/<code>toPattern()</code> API from the
|
2001-11-22 00:05:50 +00:00
|
|
|
* <code>java.text.Format</code>-derived classes. Unlike the
|
1999-12-28 23:57:50 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* <p><b>Pattern syntax</b></p>
|
|
|
|
*
|
|
|
|
* Patterns are accepted by the constructors and the
|
|
|
|
* <code>applyPattern()</code> methods and returned by the
|
|
|
|
* <code>toPattern()</code> method. These patterns follow a syntax
|
|
|
|
* similar to that employed by version 8 regular expression character
|
|
|
|
* classes:
|
|
|
|
*
|
2000-01-13 07:28:31 +00:00
|
|
|
* <blockquote>
|
|
|
|
* <table>
|
|
|
|
* <tr align="top">
|
|
|
|
* <td nowrap valign="top" align="right"><code>pattern := </code></td>
|
|
|
|
* <td valign="top"><code>('[' '^'? item* ']') |
|
2001-11-22 00:05:50 +00:00
|
|
|
* property</code></td>
|
2000-01-13 07:28:31 +00:00
|
|
|
* </tr>
|
|
|
|
* <tr align="top">
|
|
|
|
* <td nowrap valign="top" align="right"><code>item := </code></td>
|
|
|
|
* <td valign="top"><code>char | (char '-' char) | pattern-expr<br>
|
|
|
|
* </code></td>
|
|
|
|
* </tr>
|
|
|
|
* <tr align="top">
|
|
|
|
* <td nowrap valign="top" align="right"><code>pattern-expr := </code></td>
|
|
|
|
* <td valign="top"><code>pattern | pattern-expr pattern |
|
|
|
|
* pattern-expr op pattern<br>
|
|
|
|
* </code></td>
|
|
|
|
* </tr>
|
|
|
|
* <tr align="top">
|
|
|
|
* <td nowrap valign="top" align="right"><code>op := </code></td>
|
|
|
|
* <td valign="top"><code>'&' | '-'<br>
|
|
|
|
* </code></td>
|
|
|
|
* </tr>
|
|
|
|
* <tr align="top">
|
|
|
|
* <td nowrap valign="top" align="right"><code>special := </code></td>
|
|
|
|
* <td valign="top"><code>'[' | ']' | '-'<br>
|
|
|
|
* </code></td>
|
|
|
|
* </tr>
|
|
|
|
* <tr align="top">
|
|
|
|
* <td nowrap valign="top" align="right"><code>char := </code></td>
|
|
|
|
* <td valign="top"><em>any character that is not</em><code> special<br>
|
|
|
|
* | ('\u005C' </code><em>any character</em><code>)<br>
|
|
|
|
* | ('\u005Cu' hex hex hex hex)<br>
|
|
|
|
* </code></td>
|
|
|
|
* </tr>
|
|
|
|
* <tr align="top">
|
|
|
|
* <td nowrap valign="top" align="right"><code>hex := </code></td>
|
|
|
|
* <td valign="top"><em>any character for which
|
2001-11-22 00:05:50 +00:00
|
|
|
* </em><code>Character.digit(c, 16)</code><em>
|
2000-01-13 07:28:31 +00:00
|
|
|
* returns a non-negative result</em></td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
2001-11-22 00:05:50 +00:00
|
|
|
* <td nowrap valign="top" align="right"><code>property := </code></td>
|
|
|
|
* <td valign="top"><em>a Unicode property set pattern</td>
|
2000-01-13 07:28:31 +00:00
|
|
|
* </tr>
|
|
|
|
* </table>
|
|
|
|
* <br>
|
|
|
|
* <table border="1">
|
|
|
|
* <tr>
|
|
|
|
* <td>Legend: <table>
|
|
|
|
* <tr>
|
|
|
|
* <td nowrap valign="top"><code>a := b</code></td>
|
|
|
|
* <td width="20" valign="top"> </td>
|
|
|
|
* <td valign="top"><code>a</code> may be replaced by <code>b</code> </td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td nowrap valign="top"><code>a?</code></td>
|
|
|
|
* <td valign="top"></td>
|
|
|
|
* <td valign="top">zero or one instance of <code>a</code><br>
|
|
|
|
* </td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td nowrap valign="top"><code>a*</code></td>
|
|
|
|
* <td valign="top"></td>
|
|
|
|
* <td valign="top">one or more instances of <code>a</code><br>
|
|
|
|
* </td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td nowrap valign="top"><code>a | b</code></td>
|
|
|
|
* <td valign="top"></td>
|
|
|
|
* <td valign="top">either <code>a</code> or <code>b</code><br>
|
|
|
|
* </td>
|
|
|
|
* </tr>
|
|
|
|
* <tr>
|
|
|
|
* <td nowrap valign="top"><code>'a'</code></td>
|
|
|
|
* <td valign="top"></td>
|
|
|
|
* <td valign="top">the literal string between the quotes </td>
|
|
|
|
* </tr>
|
|
|
|
* </table>
|
|
|
|
* </td>
|
|
|
|
* </tr>
|
|
|
|
* </table>
|
1999-12-28 23:57:50 +00:00
|
|
|
* </blockquote>
|
|
|
|
*
|
2000-01-13 07:28:31 +00:00
|
|
|
* Any character may be preceded by a backslash in order to remove any special
|
2001-11-22 00:05:50 +00:00
|
|
|
* meaning. White space characters, as defined by UCharacter.isWhitespace(), are
|
2000-01-13 07:28:31 +00:00
|
|
|
* ignored, unless they are escaped.
|
|
|
|
*
|
2001-11-22 00:05:50 +00:00
|
|
|
* <p>Property patterns specify a set of characters having a certain
|
|
|
|
* property as defined by the Unicode standard. Both the POSIX-like
|
|
|
|
* "[:Lu:]" and the Perl-like syntax "\p{Lu}" are recognized. For a
|
|
|
|
* complete list of supported property patterns, see the User's Guide
|
|
|
|
* for UnicodeSet at
|
|
|
|
* <a href="http://oss.software.ibm.com/icu/userguide/unicodeset.html">
|
|
|
|
* http://oss.software.ibm.com/icu/userguide/unicodeset.html</a>.
|
|
|
|
* Actual determination of property data is defined by the underlying
|
|
|
|
* Unicode database as implemented by UCharacter.
|
|
|
|
*
|
|
|
|
* <p>Patterns specify individual characters, ranges of characters, and
|
|
|
|
* Unicode property sets. When elements are concatenated, they
|
1999-12-28 23:57:50 +00:00
|
|
|
* specify their union. To complement a set, place a '^' immediately
|
2001-11-22 00:05:50 +00:00
|
|
|
* after the opening '['. Property patterns are inverted by modifying
|
|
|
|
* their delimiters; "[:^foo]" and "\P{foo}". In any other location,
|
|
|
|
* '^' has no special meaning.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
|
|
|
* <p>Ranges are indicated by placing two a '-' between two
|
|
|
|
* characters, as in "a-z". This specifies the range of all
|
|
|
|
* characters from the left to the right, in Unicode order. If the
|
2001-11-22 00:05:50 +00:00
|
|
|
* left character is greater than or equal to the
|
1999-12-28 23:57:50 +00:00
|
|
|
* right character it is a syntax error. If a '-' occurs as the first
|
|
|
|
* character after the opening '[' or '[^', or if it occurs as the
|
|
|
|
* last character before the closing ']', then it is taken as a
|
2001-11-22 00:05:50 +00:00
|
|
|
* literal. Thus "[a\u005C-b]", "[-ab]", and "[ab-]" all indicate the same
|
1999-12-28 23:57:50 +00:00
|
|
|
* set of three characters, 'a', 'b', and '-'.
|
|
|
|
*
|
|
|
|
* <p>Sets may be intersected using the '&' operator or the asymmetric
|
|
|
|
* set difference may be taken using the '-' operator, for example,
|
2001-11-22 00:05:50 +00:00
|
|
|
* "[[:L:]&[\u005Cu0000-\u005Cu0FFF]]" indicates the set of all Unicode letters
|
1999-12-28 23:57:50 +00:00
|
|
|
* with values less than 4096. Operators ('&' and '|') have equal
|
|
|
|
* precedence and bind left-to-right. Thus
|
2001-11-22 00:05:50 +00:00
|
|
|
* "[[:L:]-[a-z]-[\u005Cu0100-\u005Cu01FF]]" is equivalent to
|
|
|
|
* "[[[:L:]-[a-z]]-[\u005Cu0100-\u005Cu01FF]]". This only really matters for
|
1999-12-28 23:57:50 +00:00
|
|
|
* difference; intersection is commutative.
|
|
|
|
*
|
|
|
|
* <table>
|
|
|
|
* <tr valign=top><td nowrap><code>[a]</code><td>The set containing 'a'
|
|
|
|
* <tr valign=top><td nowrap><code>[a-z]</code><td>The set containing 'a'
|
|
|
|
* through 'z' and all letters in between, in Unicode order
|
|
|
|
* <tr valign=top><td nowrap><code>[^a-z]</code><td>The set containing
|
|
|
|
* all characters but 'a' through 'z',
|
2001-11-22 00:05:50 +00:00
|
|
|
* that is, U+0000 through 'a'-1 and 'z'+1 through U+10FFFF
|
1999-12-28 23:57:50 +00:00
|
|
|
* <tr valign=top><td nowrap><code>[[<em>pat1</em>][<em>pat2</em>]]</code>
|
|
|
|
* <td>The union of sets specified by <em>pat1</em> and <em>pat2</em>
|
|
|
|
* <tr valign=top><td nowrap><code>[[<em>pat1</em>]&[<em>pat2</em>]]</code>
|
|
|
|
* <td>The intersection of sets specified by <em>pat1</em> and <em>pat2</em>
|
|
|
|
* <tr valign=top><td nowrap><code>[[<em>pat1</em>]-[<em>pat2</em>]]</code>
|
|
|
|
* <td>The asymmetric difference of sets specified by <em>pat1</em> and
|
|
|
|
* <em>pat2</em>
|
2001-11-22 00:05:50 +00:00
|
|
|
* <tr valign=top><td nowrap><code>[:Lu:] or \p{Lu}</code>
|
|
|
|
* <td>The set of characters having the specified
|
|
|
|
* Unicode property; in
|
1999-12-28 23:57:50 +00:00
|
|
|
* this case, Unicode uppercase letters
|
2001-11-22 00:05:50 +00:00
|
|
|
* <tr valign=top><td nowrap><code>[:^Lu:] or \P{Lu}</code>
|
|
|
|
* <td>The set of characters <em>not</em> having the given
|
|
|
|
* Unicode property
|
1999-12-28 23:57:50 +00:00
|
|
|
* </table>
|
2002-04-25 23:39:57 +00:00
|
|
|
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
1999-12-28 23:57:50 +00:00
|
|
|
* @author Alan Liu
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-05-29 18:36:09 +00:00
|
|
|
class U_COMMON_API UnicodeSet : public UnicodeFilter {
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
int32_t len; // length of list used; 0 <= len <= capacity
|
|
|
|
int32_t capacity; // capacity of list
|
|
|
|
int32_t bufferCapacity; // capacity of buffer
|
|
|
|
UChar32* list; // MUST be terminated with HIGH
|
|
|
|
UChar32* buffer; // internal buffer, may be NULL
|
|
|
|
|
2002-04-25 23:39:57 +00:00
|
|
|
UVector* strings; // maintained in sorted order
|
|
|
|
|
2001-06-12 17:34:16 +00:00
|
|
|
/**
|
|
|
|
* The pattern representation of this set. This may not be the
|
|
|
|
* most economical pattern. It is the pattern supplied to
|
|
|
|
* applyPattern(), with variables substituted and whitespace
|
|
|
|
* removed. For sets constructed without applyPattern(), or
|
|
|
|
* modified using the non-pattern API, this string will be empty,
|
|
|
|
* indicating that toPattern() must generate a pattern
|
|
|
|
* representation from the inversion list.
|
|
|
|
*/
|
|
|
|
UnicodeString pat;
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2000-05-25 19:27:14 +00:00
|
|
|
* Minimum value that can be stored in a UnicodeSet.
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-25 19:27:14 +00:00
|
|
|
static const UChar32 MIN_VALUE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum value that can be stored in a UnicodeSet.
|
|
|
|
*/
|
|
|
|
static const UChar32 MAX_VALUE;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
// Constructors &c
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs an empty set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
UnicodeSet();
|
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
/**
|
|
|
|
* Constructs a set containing the given range. If <code>end >
|
|
|
|
* start</code> then an empty set is created.
|
|
|
|
*
|
|
|
|
* @param start first character, inclusive, of range
|
|
|
|
* @param end last character, inclusive, of range
|
|
|
|
*/
|
|
|
|
UnicodeSet(UChar32 start, UChar32 end);
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Constructs a set from the given pattern. See the class
|
|
|
|
* description for the syntax of the pattern language.
|
|
|
|
* @param pattern a string specifying what characters are in the set
|
|
|
|
* @exception <code>IllegalArgumentException</code> if the pattern
|
|
|
|
* contains a syntax error.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
UnicodeSet(const UnicodeString& pattern,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
|
|
|
/**
|
2001-10-18 04:06:14 +00:00
|
|
|
* DEPRECATED Constructs a set from the given Unicode character category.
|
1999-12-28 23:57:50 +00:00
|
|
|
* @param category an integer indicating the character category as
|
2001-10-18 04:06:14 +00:00
|
|
|
* defined in uchar.h.
|
|
|
|
* @deprecated To be removed after 2002-DEC-31
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
UnicodeSet(int8_t category, UErrorCode& status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a set that is identical to the given UnicodeSet.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
UnicodeSet(const UnicodeSet& o);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructs the set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual ~UnicodeSet();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assigns this object to be a copy of another.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
UnicodeSet& operator=(const UnicodeSet& o);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares the specified object with this set for equality. Returns
|
|
|
|
* <tt>true</tt> if the two sets
|
|
|
|
* have the same size, and every member of the specified set is
|
|
|
|
* contained in this set (or equivalently, every member of this set is
|
|
|
|
* contained in the specified set).
|
|
|
|
*
|
|
|
|
* @param o set to be compared for equality with this set.
|
|
|
|
* @return <tt>true</tt> if the specified set is equal to this set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool operator==(const UnicodeSet& o) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares the specified object with this set for equality. Returns
|
|
|
|
* <tt>true</tt> if the specified set is not equal to this set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool operator!=(const UnicodeSet& o) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2000-01-18 20:00:56 +00:00
|
|
|
/**
|
2002-02-07 01:07:55 +00:00
|
|
|
* Returns a copy of this object. All UnicodeFunctor objects have
|
2000-01-18 20:00:56 +00:00
|
|
|
* to support cloning in order to allow classes using
|
2002-02-07 01:07:55 +00:00
|
|
|
* UnicodeFunctors, such as Transliterator, to implement cloning.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
2000-01-18 20:00:56 +00:00
|
|
|
*/
|
2002-02-07 01:07:55 +00:00
|
|
|
virtual UnicodeFunctor* clone() const;
|
2000-01-18 20:00:56 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Returns the hash code value for this set.
|
|
|
|
*
|
|
|
|
* @return the hash code value for this set.
|
|
|
|
* @see Object#hashCode()
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual int32_t hashCode(void) const;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
// Public API
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
/**
|
|
|
|
* Make this object represent the range <code>start - end</code>.
|
|
|
|
* If <code>end > start</code> then this object is set to an
|
|
|
|
* an empty range.
|
|
|
|
*
|
|
|
|
* @param start first character in the set, inclusive
|
|
|
|
* @rparam end last character in the set, inclusive
|
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
UnicodeSet& set(UChar32 start, UChar32 end);
|
2000-05-25 19:27:14 +00:00
|
|
|
|
2001-10-18 04:06:14 +00:00
|
|
|
/**
|
|
|
|
* Return true if the given position, in the given pattern, appears
|
|
|
|
* to be the start of a UnicodeSet pattern.
|
|
|
|
*/
|
|
|
|
static UBool resemblesPattern(const UnicodeString& pattern,
|
|
|
|
int32_t pos);
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Modifies this set to represent the set specified by the given
|
|
|
|
* pattern, optionally ignoring white space. See the class
|
|
|
|
* description for the syntax of the pattern language.
|
|
|
|
* @param pattern a string specifying what characters are in the set
|
|
|
|
* @exception <code>IllegalArgumentException</code> if the pattern
|
|
|
|
* contains a syntax error.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& applyPattern(const UnicodeString& pattern,
|
|
|
|
UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a string representation of this set. If the result of
|
|
|
|
* calling this function is passed to a UnicodeSet constructor, it
|
|
|
|
* will produce another set that is equal to this one.
|
2001-06-12 17:34:16 +00:00
|
|
|
* @param result the string to receive the rules. Previous
|
|
|
|
* contents will be deleted.
|
|
|
|
* @param escapeUnprintable if TRUE then convert unprintable
|
|
|
|
* character to their hex escape representations, \uxxxx or
|
|
|
|
* \Uxxxxxxxx. Unprintable characters are those other than
|
|
|
|
* U+000A, U+0020..U+007E.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2001-06-12 17:34:16 +00:00
|
|
|
virtual UnicodeString& toPattern(UnicodeString& result,
|
|
|
|
UBool escapeUnprintable = FALSE) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2002-10-30 18:24:00 +00:00
|
|
|
/**
|
|
|
|
* Modifies this set to contain those code points which have the given value
|
|
|
|
* for the given binary or enumerated property, as returned by
|
|
|
|
* u_getIntPropertyValue. Prior contents of this set are lost.
|
|
|
|
*
|
|
|
|
* @param prop a property in the range UCHAR_BIN_START..UCHAR_BIN_LIMIT-1
|
|
|
|
* or UCHAR_INT_START..UCHAR_INT_LIMIT-1.
|
|
|
|
*
|
|
|
|
* @param value a value in the range u_getIntPropertyMinValue(prop)..
|
|
|
|
* u_getIntPropertyMaxValue(prop), with one exception. If prop is
|
|
|
|
* UCHAR_GENERAL_CATEGORY, then value should not be a UCharCategory, but
|
|
|
|
* rather a mask value produced by U_GET_GC_MASK(). This allows grouped
|
|
|
|
* categories such as [:L:] to be represented. Mask values range
|
|
|
|
* non-contiguously from 1..U_GC_P_MASK.
|
|
|
|
*
|
|
|
|
* @param ec error code input/output parameter
|
|
|
|
*
|
|
|
|
* @return a reference to this set
|
|
|
|
*
|
|
|
|
* @draft ICU 2.2
|
|
|
|
*/
|
|
|
|
UnicodeSet& applyIntPropertyValue(UProperty prop,
|
|
|
|
int32_t value,
|
|
|
|
UErrorCode& ec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Modifies this set to contain those code points which have the
|
|
|
|
* given value for the given property. Prior contents of this
|
|
|
|
* set are lost.
|
|
|
|
*
|
|
|
|
* @param prop a property alias, either short or long. The name is matched
|
|
|
|
* loosely. See PropertyAliases.txt for names and a description of loose
|
|
|
|
* matching. If the value string is empty, then this string is interpreted
|
|
|
|
* as either a General_Category value alias, a Script value alias, a binary
|
|
|
|
* property alias, or a special ID. Special IDs are matched loosely and
|
|
|
|
* correspond to the following sets:
|
|
|
|
*
|
|
|
|
* "ANY" = [\u0000-\U0010FFFF],
|
|
|
|
* "ASCII" = [\u0000-\u007F].
|
|
|
|
*
|
|
|
|
* @param value a value alias, either short or long. The name is matched
|
|
|
|
* loosely. See PropertyValueAliases.txt for names and a description of
|
|
|
|
* loose matching. In addition to aliases listed, numeric values and
|
|
|
|
* canonical combining classes may be expressed numerically, e.g., ("nv",
|
|
|
|
* "0.5") or ("ccc", "220"). The value string may also be empty.
|
|
|
|
*
|
|
|
|
* @param ec error code input/output parameter
|
|
|
|
*
|
|
|
|
* @return a reference to this set
|
|
|
|
*
|
|
|
|
* @draft ICU 2.2
|
|
|
|
*/
|
|
|
|
UnicodeSet& applyPropertyAlias(const UnicodeString& prop,
|
|
|
|
const UnicodeString& value,
|
|
|
|
UErrorCode& ec);
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Returns the number of elements in this set (its cardinality),
|
|
|
|
* <em>n</em>, where <code>0 <= </code><em>n</em><code> <= 65536</code>.
|
|
|
|
*
|
|
|
|
* @return the number of elements in this set (its cardinality).
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
|
|
|
virtual int32_t size(void) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns <tt>true</tt> if this set contains no elements.
|
|
|
|
*
|
|
|
|
* @return <tt>true</tt> if this set contains no elements.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
virtual UBool isEmpty(void) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2002-04-25 23:39:57 +00:00
|
|
|
* Returns true if this set contains the given character.
|
|
|
|
* @param c character to be checked for containment
|
|
|
|
* @return true if the test condition is met
|
|
|
|
* @draft ICU 2.0
|
|
|
|
*/
|
|
|
|
virtual UBool contains(UChar32 c) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this set contains every character
|
|
|
|
* of the given range.
|
|
|
|
* @param start first character, inclusive, of the range
|
|
|
|
* @param end last character, inclusive, of the range
|
|
|
|
* @return true if the test condition is met
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2000-05-25 19:27:14 +00:00
|
|
|
virtual UBool contains(UChar32 start, UChar32 end) const;
|
|
|
|
|
|
|
|
/**
|
2002-04-25 23:39:57 +00:00
|
|
|
* Returns <tt>true</tt> if this set contains the given
|
|
|
|
* multicharacter string.
|
|
|
|
* @param s string to be checked for containment
|
|
|
|
* @return <tt>true</tt> if this set contains the specified string
|
2000-05-25 19:27:14 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
UBool contains(const UnicodeString& s) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this set contains all the characters and strings
|
|
|
|
* of the given set.
|
|
|
|
* @param c set to be checked for containment
|
|
|
|
* @return true if the test condition is met
|
|
|
|
*/
|
|
|
|
virtual UBool containsAll(const UnicodeSet& c) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this set contains all the characters
|
|
|
|
* of the given string.
|
|
|
|
* @param s string containing characters to be checked for containment
|
|
|
|
* @return true if the test condition is met
|
|
|
|
*/
|
|
|
|
UBool containsAll(const UnicodeString& s) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this set contains none of the characters
|
|
|
|
* of the given range.
|
|
|
|
* @param start first character, inclusive, of the range
|
|
|
|
* @param end last character, inclusive, of the range
|
|
|
|
* @return true if the test condition is met
|
|
|
|
*/
|
|
|
|
UBool containsNone(UChar32 start, UChar32 end) const;
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2002-04-25 23:39:57 +00:00
|
|
|
/**
|
|
|
|
* Returns true if this set contains none of the characters and strings
|
|
|
|
* of the given set.
|
|
|
|
* @param c set to be checked for containment
|
|
|
|
* @return true if the test condition is met
|
|
|
|
*/
|
|
|
|
UBool containsNone(const UnicodeSet& c) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this set contains none of the characters
|
|
|
|
* of the given string.
|
|
|
|
* @param s string containing characters to be checked for containment
|
|
|
|
* @return true if the test condition is met
|
|
|
|
*/
|
|
|
|
UBool containsNone(const UnicodeString& s) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this set contains one or more of the characters
|
|
|
|
* in the given range.
|
|
|
|
* @param start first character, inclusive, of the range
|
|
|
|
* @param end last character, inclusive, of the range
|
|
|
|
* @return true if the condition is met
|
|
|
|
*/
|
|
|
|
inline UBool containsSome(UChar32 start, UChar32 end) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this set contains one or more of the characters
|
|
|
|
* and strings of the given set.
|
|
|
|
* @param c set to be checked for containment
|
|
|
|
* @return true if the condition is met
|
|
|
|
*/
|
|
|
|
inline UBool containsSome(const UnicodeSet& s) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this set contains one or more of the characters
|
|
|
|
* of the given string.
|
|
|
|
* @param s string containing characters to be checked for containment
|
|
|
|
* @return true if the condition is met
|
|
|
|
*/
|
|
|
|
inline UBool containsSome(const UnicodeString& s) const;
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
2001-07-25 18:50:09 +00:00
|
|
|
* Implement UnicodeMatcher::matches()
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2001-07-25 18:50:09 +00:00
|
|
|
UMatchDegree matches(const Replaceable& text,
|
|
|
|
int32_t& offset,
|
|
|
|
int32_t limit,
|
2001-10-30 23:55:09 +00:00
|
|
|
UBool incremental);
|
2002-04-25 23:39:57 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Returns the longest match for s in text at the given position.
|
|
|
|
* If limit > start then match forward from start+1 to limit
|
|
|
|
* matching all characters except s.charAt(0). If limit < start,
|
|
|
|
* go backward starting from start-1 matching all characters
|
|
|
|
* except s.charAt(s.length()-1). This method assumes that the
|
|
|
|
* first character, text.charAt(start), matches s, so it does not
|
|
|
|
* check it.
|
|
|
|
* @param text the text to match
|
|
|
|
* @param start the first character to match. In the forward
|
|
|
|
* direction, text.charAt(start) is matched against s.charAt(0).
|
|
|
|
* In the reverse direction, it is matched against
|
|
|
|
* s.charAt(s.length()-1).
|
|
|
|
* @param limit the limit offset for matching, either last+1 in
|
|
|
|
* the forward direction, or last-1 in the reverse direction,
|
|
|
|
* where last is the index of the last character to match.
|
|
|
|
* @return If part of s matches up to the limit, return |limit -
|
|
|
|
* start|. If all of s matches before reaching the limit, return
|
|
|
|
* s.length(). If there is a mismatch between s and text, return
|
|
|
|
* 0
|
|
|
|
*/
|
|
|
|
static int32_t matchRest(const Replaceable& text,
|
|
|
|
int32_t start, int32_t limit,
|
|
|
|
const UnicodeString& s);
|
2001-07-25 18:50:09 +00:00
|
|
|
|
2002-07-29 20:41:49 +00:00
|
|
|
/**
|
|
|
|
* Returns the smallest value i such that c < list[i]. Caller
|
|
|
|
* must ensure that c is a legal value or this method will enter
|
|
|
|
* an infinite loop. This method performs a binary search.
|
|
|
|
* @param c a character in the range MIN_VALUE..MAX_VALUE
|
|
|
|
* inclusive
|
|
|
|
* @return the smallest integer i in the range 0..len-1,
|
|
|
|
* inclusive, such that c < list[i]
|
|
|
|
*/
|
2002-07-30 01:22:08 +00:00
|
|
|
int32_t findCodePoint(UChar32 c) const;
|
2002-07-29 20:41:49 +00:00
|
|
|
|
2002-04-25 23:39:57 +00:00
|
|
|
public:
|
2002-06-28 21:13:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of UnicodeMatcher API. Union the set of all
|
|
|
|
* characters that may be matched by this object into the given
|
|
|
|
* set.
|
|
|
|
* @param toUnionTo the set into which to union the source characters
|
|
|
|
*/
|
|
|
|
void addMatchSetTo(UnicodeSet& toUnionTo) const;
|
|
|
|
|
2001-12-11 01:13:33 +00:00
|
|
|
/**
|
|
|
|
* Returns the index of the given character within this set, where
|
|
|
|
* the set is ordered by ascending code point. If the character
|
|
|
|
* is not in this set, return -1. The inverse of this method is
|
|
|
|
* <code>charAt()</code>.
|
|
|
|
* @return an index from 0..size()-1, or -1
|
|
|
|
*/
|
|
|
|
int32_t indexOf(UChar32 c) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the character at the given index within this set, where
|
|
|
|
* the set is ordered by ascending code point. If the index is
|
|
|
|
* out of range, return (UChar32)-1. The inverse of this method is
|
|
|
|
* <code>indexOf()</code>.
|
|
|
|
* @param index an index from 0..size()-1
|
|
|
|
* @return the character at the given index, or (UChar32)-1.
|
|
|
|
*/
|
|
|
|
UChar32 charAt(int32_t index) const;
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Adds the specified range to this set if it is not already
|
|
|
|
* present. If this set already contains the specified range,
|
2000-05-25 19:27:14 +00:00
|
|
|
* the call leaves this set unchanged. If <code>end > start</code>
|
1999-12-28 23:57:50 +00:00
|
|
|
* then an empty range is added, leaving the set unchanged.
|
2000-05-26 18:32:15 +00:00
|
|
|
* This is equivalent to a boolean logic OR, or a set UNION.
|
1999-12-28 23:57:50 +00:00
|
|
|
*
|
2000-05-25 19:27:14 +00:00
|
|
|
* @param start first character, inclusive, of range to be added
|
1999-12-28 23:57:50 +00:00
|
|
|
* to this set.
|
2000-05-25 19:27:14 +00:00
|
|
|
* @param end last character, inclusive, of range to be added
|
1999-12-28 23:57:50 +00:00
|
|
|
* to this set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& add(UChar32 start, UChar32 end);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified character to this set if it is not already
|
|
|
|
* present. If this set already contains the specified character,
|
|
|
|
* the call leaves this set unchanged.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
UnicodeSet& add(UChar32 c);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds the specified multicharacter to this set if it is not already
|
|
|
|
* present. If this set already contains the multicharacter,
|
|
|
|
* the call leaves this set unchanged.
|
|
|
|
* Thus "ch" => {"ch"}
|
2002-07-03 12:05:56 +00:00
|
|
|
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
2002-04-25 23:39:57 +00:00
|
|
|
* @param s the source string
|
|
|
|
* @return this object, for chaining
|
|
|
|
*/
|
|
|
|
UnicodeSet& add(const UnicodeString& s);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* @return a code point IF the string consists of a single one.
|
|
|
|
* otherwise returns -1.
|
|
|
|
* @param string to test
|
|
|
|
*/
|
|
|
|
static int32_t getSingleCP(const UnicodeString& s);
|
|
|
|
|
|
|
|
void _add(const UnicodeString& s);
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Adds each of the characters in this string to the set. Thus "ch" => {"c", "h"}
|
|
|
|
* If this set already any particular character, it has no effect on that character.
|
|
|
|
* @param s the source string
|
|
|
|
* @return this object, for chaining
|
|
|
|
*/
|
|
|
|
UnicodeSet& addAll(const UnicodeString& s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retains EACH of the characters in this string. Note: "ch" == {"c", "h"}
|
|
|
|
* If this set already any particular character, it has no effect on that character.
|
|
|
|
* @param s the source string
|
|
|
|
* @return this object, for chaining
|
|
|
|
*/
|
|
|
|
UnicodeSet& retainAll(const UnicodeString& s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Complement EACH of the characters in this string. Note: "ch" == {"c", "h"}
|
|
|
|
* If this set already any particular character, it has no effect on that character.
|
|
|
|
* @param s the source string
|
|
|
|
* @return this object, for chaining
|
|
|
|
*/
|
|
|
|
UnicodeSet& complementAll(const UnicodeString& s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove EACH of the characters in this string. Note: "ch" == {"c", "h"}
|
|
|
|
* If this set already any particular character, it has no effect on that character.
|
|
|
|
* @param s the source string
|
|
|
|
* @return this object, for chaining
|
|
|
|
*/
|
|
|
|
UnicodeSet& removeAll(const UnicodeString& s);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a set from a multicharacter string. Thus "ch" => {"ch"}
|
2002-07-03 12:05:56 +00:00
|
|
|
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
2002-04-25 23:39:57 +00:00
|
|
|
* @param s the source string
|
|
|
|
* @return a newly created set containing the given string.
|
|
|
|
* The caller owns the return object and is responsible for deleting it.
|
|
|
|
*/
|
|
|
|
static UnicodeSet* createFrom(const UnicodeString& s);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a set from each of the characters in the string. Thus "ch" => {"c", "h"}
|
|
|
|
* @param s the source string
|
|
|
|
* @return a newly created set containing the given characters
|
|
|
|
* The caller owns the return object and is responsible for deleting it.
|
|
|
|
*/
|
|
|
|
static UnicodeSet* createFromAll(const UnicodeString& s);
|
2000-05-25 19:27:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retain only the elements in this set that are contained in the
|
|
|
|
* specified range. If <code>end > start</code> then an empty range is
|
2000-05-26 18:32:15 +00:00
|
|
|
* retained, leaving the set empty. This is equivalent to
|
|
|
|
* a boolean logic AND, or a set INTERSECTION.
|
2000-05-25 19:27:14 +00:00
|
|
|
*
|
|
|
|
* @param start first character, inclusive, of range to be retained
|
|
|
|
* to this set.
|
|
|
|
* @param end last character, inclusive, of range to be retained
|
|
|
|
* to this set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
2000-05-25 19:27:14 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& retain(UChar32 start, UChar32 end);
|
2000-05-25 19:27:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retain the specified character from this set if it is present.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
2000-05-25 19:27:14 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
UnicodeSet& retain(UChar32 c);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the specified range from this set if it is present.
|
|
|
|
* The set will not contain the specified range once the call
|
2000-05-25 19:27:14 +00:00
|
|
|
* returns. If <code>end > start</code> then an empty range is
|
1999-12-28 23:57:50 +00:00
|
|
|
* removed, leaving the set unchanged.
|
2001-03-22 00:09:10 +00:00
|
|
|
*
|
2000-05-25 19:27:14 +00:00
|
|
|
* @param start first character, inclusive, of range to be removed
|
1999-12-28 23:57:50 +00:00
|
|
|
* from this set.
|
2000-05-25 19:27:14 +00:00
|
|
|
* @param end last character, inclusive, of range to be removed
|
1999-12-28 23:57:50 +00:00
|
|
|
* from this set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& remove(UChar32 start, UChar32 end);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the specified character from this set if it is present.
|
|
|
|
* The set will not contain the specified range once the call
|
|
|
|
* returns.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
UnicodeSet& remove(UChar32 c);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the specified string from this set if it is present.
|
|
|
|
* The set will not contain the specified character once the call
|
|
|
|
* returns.
|
|
|
|
* @param s the source string
|
|
|
|
* @return this object, for chaining
|
|
|
|
*/
|
|
|
|
UnicodeSet& remove(const UnicodeString& s);
|
2000-05-25 19:27:14 +00:00
|
|
|
|
2000-05-26 18:32:15 +00:00
|
|
|
/**
|
|
|
|
* Inverts this set. This operation modifies this set so that
|
|
|
|
* its value is its complement. This is equivalent to
|
|
|
|
* <code>complement(MIN_VALUE, MAX_VALUE)</code>.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
2000-05-26 18:32:15 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& complement(void);
|
2000-05-26 18:32:15 +00:00
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
/**
|
|
|
|
* Complements the specified range in this set. Any character in
|
|
|
|
* the range will be removed if it is in this set, or will be
|
|
|
|
* added if it is not in this set. If <code>end > start</code>
|
2000-05-26 18:32:15 +00:00
|
|
|
* then an empty range is complemented, leaving the set unchanged.
|
|
|
|
* This is equivalent to a boolean logic XOR.
|
2000-05-25 19:27:14 +00:00
|
|
|
*
|
|
|
|
* @param start first character, inclusive, of range to be removed
|
|
|
|
* from this set.
|
|
|
|
* @param end last character, inclusive, of range to be removed
|
|
|
|
* from this set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
2000-05-25 19:27:14 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& complement(UChar32 start, UChar32 end);
|
2000-05-25 19:27:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Complements the specified character in this set. The character
|
|
|
|
* will be removed if it is in this set, or will be added if it is
|
|
|
|
* not in this set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @draft ICU 2.0
|
2000-05-25 19:27:14 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
UnicodeSet& complement(UChar32 c);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
2002-04-25 23:39:57 +00:00
|
|
|
* Complement the specified string in this set.
|
|
|
|
* The set will not contain the specified string once the call
|
|
|
|
* returns.
|
|
|
|
* <br><b>Warning: you cannot add an empty string ("") to a UnicodeSet.</b>
|
|
|
|
* @param s the string to complement
|
|
|
|
* @return this object, for chaining
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
UnicodeSet& complement(const UnicodeString& s);
|
2001-12-03 20:50:50 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Adds all of the elements in the specified set to this set if
|
|
|
|
* they're not already present. This operation effectively
|
|
|
|
* modifies this set so that its value is the <i>union</i> of the two
|
|
|
|
* sets. The behavior of this operation is unspecified if the specified
|
|
|
|
* collection is modified while the operation is in progress.
|
|
|
|
*
|
|
|
|
* @param c set whose elements are to be added to this set.
|
|
|
|
* @see #add(char, char)
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& addAll(const UnicodeSet& c);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retains only the elements in this set that are contained in the
|
|
|
|
* specified set. In other words, removes from this set all of
|
|
|
|
* its elements that are not contained in the specified set. This
|
|
|
|
* operation effectively modifies this set so that its value is
|
|
|
|
* the <i>intersection</i> of the two sets.
|
|
|
|
*
|
|
|
|
* @param c set that defines which elements this set will retain.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& retainAll(const UnicodeSet& c);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes from this set all of its elements that are contained in the
|
|
|
|
* specified set. This operation effectively modifies this
|
|
|
|
* set so that its value is the <i>asymmetric set difference</i> of
|
|
|
|
* the two sets.
|
|
|
|
*
|
|
|
|
* @param c set that defines which elements will be removed from
|
|
|
|
* this set.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& removeAll(const UnicodeSet& c);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
/**
|
|
|
|
* Complements in this set all elements contained in the specified
|
|
|
|
* set. Any character in the other set will be removed if it is
|
|
|
|
* in this set, or will be added if it is not in this set.
|
|
|
|
*
|
|
|
|
* @param c set that defines which elements will be xor'ed from
|
|
|
|
* this set.
|
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& complementAll(const UnicodeSet& c);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all of the elements from this set. This set will be
|
|
|
|
* empty after this call returns.
|
2001-11-14 00:50:39 +00:00
|
|
|
* @stable
|
1999-12-28 23:57:50 +00:00
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& clear(void);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
/**
|
|
|
|
* Iteration method that returns the number of ranges contained in
|
|
|
|
* this set.
|
|
|
|
* @see #getRangeStart
|
|
|
|
* @see #getRangeEnd
|
|
|
|
*/
|
|
|
|
virtual int32_t getRangeCount(void) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iteration method that returns the first character in the
|
|
|
|
* specified range of this set.
|
|
|
|
* @see #getRangeCount
|
|
|
|
* @see #getRangeEnd
|
|
|
|
*/
|
|
|
|
virtual UChar32 getRangeStart(int32_t index) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iteration method that returns the last character in the
|
|
|
|
* specified range of this set.
|
|
|
|
* @see #getRangeStart
|
|
|
|
* @see #getRangeEnd
|
|
|
|
*/
|
|
|
|
virtual UChar32 getRangeEnd(int32_t index) const;
|
|
|
|
|
2002-05-29 18:36:09 +00:00
|
|
|
/**
|
2002-06-04 23:37:20 +00:00
|
|
|
* Serializes this set into an array of 16-bit integers. Serialization
|
|
|
|
* (currently) only records the characters in the set; multicharacter
|
|
|
|
* strings are ignored.
|
|
|
|
*
|
|
|
|
* The array has following format (each line is one 16-bit
|
|
|
|
* integer):
|
2002-05-29 18:36:09 +00:00
|
|
|
*
|
|
|
|
* length = (n+2*m) | (m!=0?0x8000:0)
|
|
|
|
* bmpLength = n; present if m!=0
|
|
|
|
* bmp[0]
|
|
|
|
* bmp[1]
|
|
|
|
* ...
|
|
|
|
* bmp[n-1]
|
|
|
|
* supp-high[0]
|
|
|
|
* supp-low[0]
|
|
|
|
* supp-high[1]
|
|
|
|
* supp-low[1]
|
|
|
|
* ...
|
|
|
|
* supp-high[m-1]
|
|
|
|
* supp-low[m-1]
|
|
|
|
*
|
|
|
|
* The array starts with a header. After the header are n bmp
|
|
|
|
* code points, then m supplementary code points. Either n or m
|
|
|
|
* or both may be zero. n+2*m is always <= 0x7FFF.
|
|
|
|
*
|
|
|
|
* If there are no supplementary characters (if m==0) then the
|
|
|
|
* header is one 16-bit integer, 'length', with value n.
|
|
|
|
*
|
|
|
|
* If there are supplementary characters (if m!=0) then the header
|
|
|
|
* is two 16-bit integers. The first, 'length', has value
|
|
|
|
* (n+2*m)|0x8000. The second, 'bmpLength', has value n.
|
|
|
|
*
|
|
|
|
* After the header the code points are stored in ascending order.
|
|
|
|
* Supplementary code points are stored as most significant 16
|
|
|
|
* bits followed by least significant 16 bits.
|
|
|
|
*
|
|
|
|
* @param dest pointer to buffer of destCapacity 16-bit integers.
|
|
|
|
* May be NULL only if destCapacity is zero.
|
|
|
|
* @param destCapacity size of dest, or zero. Must not be negative.
|
|
|
|
* @param ec error code. Will be set to U_INDEX_OUTOFBOUNDS_ERROR
|
|
|
|
* if n+2*m > 0x7FFF. Will be set to U_BUFFER_OVERFLOW_ERROR if
|
|
|
|
* n+2*m+(m!=0?2:1) > destCapacity.
|
|
|
|
* @return the total length of the serialized format, including
|
|
|
|
* the header, that is, n+2*m+(m!=0?2:1), or 0 on error other
|
|
|
|
* than U_BUFFER_OVERFLOW_ERROR.
|
|
|
|
*/
|
|
|
|
int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const;
|
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
/**
|
|
|
|
* Reallocate this objects internal structures to take up the least
|
|
|
|
* possible space, without changing this object's value.
|
|
|
|
*/
|
2002-04-25 23:39:57 +00:00
|
|
|
virtual UnicodeSet& compact();
|
2000-05-25 19:27:14 +00:00
|
|
|
|
2001-11-09 01:22:59 +00:00
|
|
|
/**
|
|
|
|
* Return the class ID for this class. This is useful only for
|
|
|
|
* comparing to a return value from getDynamicClassID(). For example:
|
|
|
|
* <pre>
|
|
|
|
* . Base* polymorphic_pointer = createPolymorphicObject();
|
|
|
|
* . if (polymorphic_pointer->getDynamicClassID() ==
|
|
|
|
* . Derived::getStaticClassID()) ...
|
|
|
|
* </pre>
|
|
|
|
* @return The class ID for all objects of this class.
|
|
|
|
* @stable
|
|
|
|
*/
|
|
|
|
static UClassID getStaticClassID(void) { return (UClassID)&fgClassID; }
|
|
|
|
|
|
|
|
/**
|
2002-02-07 01:07:55 +00:00
|
|
|
* Implement UnicodeFunctor API.
|
2001-11-09 01:22:59 +00:00
|
|
|
*
|
|
|
|
* @return The class ID for this object. All objects of a given
|
|
|
|
* class have the same class ID. Objects of other classes have
|
|
|
|
* different class IDs.
|
|
|
|
*/
|
|
|
|
virtual UClassID getDynamicClassID(void) const { return getStaticClassID(); };
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2002-06-04 23:37:20 +00:00
|
|
|
// Private API for the USet API
|
|
|
|
|
|
|
|
friend class USetAccess;
|
|
|
|
|
|
|
|
int32_t getStringCount() const;
|
|
|
|
|
|
|
|
const UnicodeString* getString(int32_t index) const;
|
2001-11-09 01:22:59 +00:00
|
|
|
|
2000-01-13 07:28:31 +00:00
|
|
|
private:
|
|
|
|
|
2002-06-04 23:37:20 +00:00
|
|
|
static const char fgClassID;
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
//----------------------------------------------------------------
|
2000-01-13 07:28:31 +00:00
|
|
|
// RuleBasedTransliterator support
|
1999-12-28 23:57:50 +00:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2001-03-31 01:22:58 +00:00
|
|
|
friend class Transliterator;
|
2001-07-13 21:17:11 +00:00
|
|
|
friend class TransliteratorParser;
|
2002-02-07 01:07:55 +00:00
|
|
|
friend class TransliteratorIDParser;
|
2000-01-13 07:28:31 +00:00
|
|
|
friend class TransliterationRule;
|
|
|
|
|
2002-06-25 17:23:07 +00:00
|
|
|
friend class RBBIRuleScanner;
|
2002-10-22 00:09:32 +00:00
|
|
|
friend class RegexCompile;
|
2002-06-25 17:23:07 +00:00
|
|
|
|
2000-01-13 07:28:31 +00:00
|
|
|
/**
|
|
|
|
* Constructs a set from the given pattern. See the class description
|
|
|
|
* for the syntax of the pattern language.
|
|
|
|
|
|
|
|
* @param pattern a string specifying what characters are in the set
|
|
|
|
* @param pos on input, the position in pattern at which to start parsing.
|
|
|
|
* On output, the position after the last character parsed.
|
|
|
|
* @param varNameToChar a mapping from variable names (String) to characters
|
|
|
|
* (Character). May be null. If varCharToSet is non-null, then names may
|
|
|
|
* map to either single characters or sets, depending on whether a mapping
|
|
|
|
* exists in varCharToSet. If varCharToSet is null then all names map to
|
|
|
|
* single characters.
|
|
|
|
* @param varCharToSet a mapping from characters (Character objects from
|
|
|
|
* varNameToChar) to UnicodeSet objects. May be null. Is only used if
|
|
|
|
* varNameToChar is also non-null.
|
|
|
|
* @exception <code>IllegalArgumentException</code> if the pattern
|
|
|
|
* contains a syntax error.
|
|
|
|
*/
|
|
|
|
UnicodeSet(const UnicodeString& pattern, ParsePosition& pos,
|
2000-02-08 02:49:15 +00:00
|
|
|
const SymbolTable& symbols,
|
2000-01-13 07:28:31 +00:00
|
|
|
UErrorCode& status);
|
|
|
|
|
2002-02-07 01:07:55 +00:00
|
|
|
/**
|
|
|
|
* Constructs a set from the given pattern. Identical to the
|
|
|
|
* 4-parameter ParsePosition contstructor, but does not take a
|
|
|
|
* SymbolTable, and does not recognize embedded variables.
|
|
|
|
*/
|
|
|
|
UnicodeSet(const UnicodeString& pattern, ParsePosition& pos,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
2000-01-13 07:28:31 +00:00
|
|
|
/**
|
|
|
|
* Returns <tt>true</tt> if this set contains any character whose low byte
|
|
|
|
* is the given value. This is used by <tt>RuleBasedTransliterator</tt> for
|
|
|
|
* indexing.
|
|
|
|
*/
|
2001-07-27 00:18:53 +00:00
|
|
|
virtual UBool matchesIndexValue(uint8_t v) const;
|
2000-01-13 07:28:31 +00:00
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
private:
|
|
|
|
|
2000-01-13 07:28:31 +00:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
// Implementation: Pattern parsing
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
/**
|
|
|
|
* Parses the given pattern, starting at the given position. The
|
|
|
|
* character at pattern.charAt(pos.getIndex()) must be '[', or the
|
|
|
|
* parse fails. Parsing continues until the corresponding closing
|
|
|
|
* ']'. If a syntax error is encountered between the opening and
|
|
|
|
* closing brace, the parse fails. Upon return from a successful
|
|
|
|
* parse, the ParsePosition is updated to point to the character
|
|
|
|
* following the closing ']', and a StringBuffer containing a
|
|
|
|
* pairs list for the parsed pattern is returned. This method calls
|
|
|
|
* itself recursively to parse embedded subpatterns.
|
|
|
|
*
|
|
|
|
* @param pattern the string containing the pattern to be parsed.
|
|
|
|
* The portion of the string from pos.getIndex(), which must be a
|
|
|
|
* '[', to the corresponding closing ']', is parsed.
|
|
|
|
* @param pos upon entry, the position at which to being parsing.
|
|
|
|
* The character at pattern.charAt(pos.getIndex()) must be a '['.
|
|
|
|
* Upon return from a successful parse, pos.getIndex() is either
|
|
|
|
* the character after the closing ']' of the parsed pattern, or
|
|
|
|
* pattern.length() if the closing ']' is the last character of
|
|
|
|
* the pattern string.
|
|
|
|
* @return a StringBuffer containing a pairs list for the parsed
|
|
|
|
* substring of <code>pattern</code>
|
|
|
|
* @exception IllegalArgumentException if the parse fails.
|
|
|
|
*/
|
2000-05-25 19:27:14 +00:00
|
|
|
void applyPattern(const UnicodeString& pattern,
|
|
|
|
ParsePosition& pos,
|
|
|
|
const SymbolTable* symbols,
|
|
|
|
UErrorCode& status);
|
1999-12-28 23:57:50 +00:00
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
// Implementation: Utility methods
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
void ensureCapacity(int32_t newLen);
|
2001-03-22 00:09:10 +00:00
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
void ensureBufferCapacity(int32_t newLen);
|
2001-03-22 00:09:10 +00:00
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
void swapBuffers(void);
|
|
|
|
|
2002-04-25 23:39:57 +00:00
|
|
|
UBool allocateStrings();
|
|
|
|
|
2001-06-12 17:34:16 +00:00
|
|
|
void _applyPattern(const UnicodeString& pattern,
|
|
|
|
ParsePosition& pos,
|
|
|
|
const SymbolTable* symbols,
|
|
|
|
UnicodeString& rebuiltPat,
|
|
|
|
UErrorCode& status);
|
|
|
|
|
|
|
|
UnicodeString& _toPattern(UnicodeString& result,
|
|
|
|
UBool escapeUnprintable) const;
|
|
|
|
|
|
|
|
UnicodeString& _generatePattern(UnicodeString& result,
|
|
|
|
UBool escapeUnprintable) const;
|
|
|
|
|
2002-04-25 23:39:57 +00:00
|
|
|
static void _appendToPat(UnicodeString& buf, const UnicodeString& s, UBool escapeUnprintable);
|
|
|
|
|
2001-06-12 17:34:16 +00:00
|
|
|
static void _appendToPat(UnicodeString& buf, UChar32 c, UBool escapeUnprintable);
|
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
//----------------------------------------------------------------
|
|
|
|
// Implementation: Fundamental operators
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2000-05-26 01:18:36 +00:00
|
|
|
void exclusiveOr(const UChar32* other, int32_t otherLen, int8_t polarity);
|
2001-03-22 00:09:10 +00:00
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
void add(const UChar32* other, int32_t otherLen, int8_t polarity);
|
2001-03-22 00:09:10 +00:00
|
|
|
|
2000-05-25 19:27:14 +00:00
|
|
|
void retain(const UChar32* other, int32_t otherLen, int8_t polarity);
|
2002-04-25 23:39:57 +00:00
|
|
|
|
2002-10-30 18:24:00 +00:00
|
|
|
/**
|
|
|
|
* Return true if the given position, in the given pattern, appears
|
|
|
|
* to be the start of a property set pattern [:foo:], \p{foo}, or
|
|
|
|
* \P{foo}, or \N{name}.
|
|
|
|
*/
|
|
|
|
static UBool resemblesPropertyPattern(const UnicodeString& pattern,
|
|
|
|
int32_t pos);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the given property pattern at the given parse position
|
|
|
|
* and set this UnicodeSet to the result.
|
|
|
|
*
|
|
|
|
* The original design document is out of date, but still useful.
|
|
|
|
* Ignore the property and value names:
|
|
|
|
* http://oss.software.ibm.com/cvs/icu/~checkout~/icuhtml/design/unicodeset_properties.html
|
|
|
|
*
|
|
|
|
* Recognized syntax:
|
|
|
|
*
|
|
|
|
* [:foo:] [:^foo:] - white space not allowed within "[:" or ":]"
|
|
|
|
* \p{foo} \P{foo} - white space not allowed within "\p" or "\P"
|
|
|
|
* \N{name} - white space not allowed within "\N"
|
|
|
|
*
|
|
|
|
* Other than the above restrictions, white space is ignored. Case
|
|
|
|
* is ignored except in "\p" and "\P" and "\N". In 'name' leading
|
|
|
|
* and trailing space is deleted, and internal runs of whitespace
|
|
|
|
* are collapsed to a single space.
|
|
|
|
*
|
|
|
|
* We support binary properties, enumerated properties, and the
|
|
|
|
* following non-enumerated properties:
|
|
|
|
*
|
|
|
|
* Numeric_Value
|
|
|
|
* Name
|
|
|
|
* Unicode_1_Name
|
|
|
|
*
|
|
|
|
* @param pattern the pattern string
|
|
|
|
* @param ppos on entry, the position at which to begin parsing.
|
|
|
|
* This should be one of the locations marked '^':
|
|
|
|
*
|
|
|
|
* [:blah:] \p{blah} \P{blah} \N{name}
|
|
|
|
* ^ % ^ % ^ % ^ %
|
|
|
|
*
|
|
|
|
* On return, the position after the last character parsed, that is,
|
|
|
|
* the locations marked '%'. If the parse fails, ppos is returned
|
|
|
|
* unchanged.
|
|
|
|
* @return a reference to this.
|
|
|
|
*/
|
|
|
|
UnicodeSet& applyPropertyPattern(const UnicodeString& pattern,
|
|
|
|
ParsePosition& ppos,
|
|
|
|
UErrorCode &ec);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A filter that returns TRUE if the given code point should be
|
|
|
|
* included in the UnicodeSet being constructed.
|
|
|
|
*/
|
|
|
|
typedef UBool (*Filter)(UChar32 codePoint, void* context);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a filter, set this UnicodeSet to the code points
|
|
|
|
* contained by that filter. The filter MUST be
|
|
|
|
* property-conformant. That is, if it returns value v for one
|
|
|
|
* code point, then it must return v for all affiliated code
|
|
|
|
* points, as defined by the inclusions list. See
|
|
|
|
* uprv_getInclusions().
|
|
|
|
*/
|
|
|
|
void applyFilter(Filter filter,
|
|
|
|
void* context,
|
|
|
|
UErrorCode &status);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a cached copy of the inclusions list that
|
|
|
|
* uprv_getInclusions() produces.
|
|
|
|
*/
|
|
|
|
static const UnicodeSet* getInclusions();
|
|
|
|
|
2002-04-25 23:39:57 +00:00
|
|
|
friend class UnicodeSetIterator;
|
1999-12-28 23:57:50 +00:00
|
|
|
};
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
inline UBool UnicodeSet::operator!=(const UnicodeSet& o) const {
|
2002-04-02 02:55:31 +00:00
|
|
|
return !operator==(o);
|
1999-12-28 23:57:50 +00:00
|
|
|
}
|
|
|
|
|
2002-04-25 23:39:57 +00:00
|
|
|
inline UBool UnicodeSet::containsSome(UChar32 start, UChar32 end) const {
|
|
|
|
return !containsNone(start, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline UBool UnicodeSet::containsSome(const UnicodeSet& s) const {
|
|
|
|
return !containsNone(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline UBool UnicodeSet::containsSome(const UnicodeString& s) const {
|
|
|
|
return !containsNone(s);
|
|
|
|
}
|
|
|
|
|
2001-10-08 23:26:58 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#endif
|