ICU 50.2 50.2
uniset.h
Go to the documentation of this file.
1/*
2***************************************************************************
3* Copyright (C) 1999-2011, International Business Machines Corporation
4* and others. All Rights Reserved.
5***************************************************************************
6* Date Name Description
7* 10/20/99 alan Creation.
8***************************************************************************
9*/
10
11#ifndef UNICODESET_H
12#define UNICODESET_H
13
14#include "unicode/unifilt.h"
15#include "unicode/unistr.h"
16#include "unicode/uset.h"
17
22
24
25class BMPSet;
26class ParsePosition;
27class RBBIRuleScanner;
28class SymbolTable;
29class UnicodeSetStringSpan;
30class UVector;
31class RuleCharacterIterator;
32
274
275 int32_t len; // length of list used; 0 <= len <= capacity
276 int32_t capacity; // capacity of list
277 UChar32* list; // MUST be terminated with HIGH
278 BMPSet *bmpSet; // The set is frozen iff either bmpSet or stringSpan is not NULL.
279 UChar32* buffer; // internal buffer, may be NULL
280 int32_t bufferCapacity; // capacity of buffer
281 int32_t patLen;
282
292 UChar *pat;
293 UVector* strings; // maintained in sorted order
294 UnicodeSetStringSpan *stringSpan;
295
296private:
297 enum { // constants
298 kIsBogus = 1 // This set is bogus (i.e. not valid)
299 };
300 uint8_t fFlags; // Bit flag (see constants above)
301public:
311 inline UBool isBogus(void) const;
312
330
331public:
332
333 enum {
339
344 MAX_VALUE = 0x10ffff
345 };
346
347 //----------------------------------------------------------------
348 // Constructors &c
349 //----------------------------------------------------------------
350
351public:
352
358
368
377 UnicodeSet(const UnicodeString& pattern,
378 UErrorCode& status);
379
380#ifndef U_HIDE_INTERNAL_API
393 UnicodeSet(const UnicodeString& pattern,
394 uint32_t options,
395 const SymbolTable* symbols,
396 UErrorCode& status);
397#endif /* U_HIDE_INTERNAL_API */
398
413 uint32_t options,
414 const SymbolTable* symbols,
415 UErrorCode& status);
416
422
427 virtual ~UnicodeSet();
428
435
447 virtual UBool operator==(const UnicodeSet& o) const;
448
454 UBool operator!=(const UnicodeSet& o) const;
455
465 virtual UnicodeFunctor* clone() const;
466
474 virtual int32_t hashCode(void) const;
475
484 inline static UnicodeSet *fromUSet(USet *uset);
485
494 inline static const UnicodeSet *fromUSet(const USet *uset);
495
503 inline USet *toUSet();
504
505
513 inline const USet * toUSet() const;
514
515
516 //----------------------------------------------------------------
517 // Freezable API
518 //----------------------------------------------------------------
519
528 inline UBool isFrozen() const;
529
544
554
555 //----------------------------------------------------------------
556 // Public API
557 //----------------------------------------------------------------
558
570
576 static UBool resemblesPattern(const UnicodeString& pattern,
577 int32_t pos);
578
592 UErrorCode& status);
593
594#ifndef U_HIDE_INTERNAL_API
612 uint32_t options,
613 const SymbolTable* symbols,
614 UErrorCode& status);
615#endif /* U_HIDE_INTERNAL_API */
616
649 ParsePosition& pos,
650 uint32_t options,
651 const SymbolTable* symbols,
652 UErrorCode& status);
653
668 UBool escapeUnprintable = FALSE) const;
669
693 int32_t value,
694 UErrorCode& ec);
695
726 const UnicodeString& value,
727 UErrorCode& ec);
728
737 virtual int32_t size(void) const;
738
745 virtual UBool isEmpty(void) const;
746
754 virtual UBool contains(UChar32 c) const;
755
764 virtual UBool contains(UChar32 start, UChar32 end) const;
765
773 UBool contains(const UnicodeString& s) const;
774
782 virtual UBool containsAll(const UnicodeSet& c) const;
783
792
802
811
820
829 inline UBool containsSome(UChar32 start, UChar32 end) const;
830
838 inline UBool containsSome(const UnicodeSet& s) const;
839
847 inline UBool containsSome(const UnicodeString& s) const;
848
867 int32_t span(const UChar *s, int32_t length, USetSpanCondition spanCondition) const;
868
881 inline int32_t span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const;
882
900 int32_t spanBack(const UChar *s, int32_t length, USetSpanCondition spanCondition) const;
901
915 inline int32_t spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const;
916
935 int32_t spanUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
936
954 int32_t spanBackUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
955
960 virtual UMatchDegree matches(const Replaceable& text,
961 int32_t& offset,
962 int32_t limit,
963 UBool incremental);
964
965private:
988 static int32_t matchRest(const Replaceable& text,
989 int32_t start, int32_t limit,
990 const UnicodeString& s);
991
1001 int32_t findCodePoint(UChar32 c) const;
1002
1003public:
1004
1012 virtual void addMatchSetTo(UnicodeSet& toUnionTo) const;
1013
1022 int32_t indexOf(UChar32 c) const;
1023
1033 UChar32 charAt(int32_t index) const;
1034
1049 virtual UnicodeSet& add(UChar32 start, UChar32 end);
1050
1059
1072
1073 private:
1079 static int32_t getSingleCP(const UnicodeString& s);
1080
1081 void _add(const UnicodeString& s);
1082
1083 public:
1093
1103
1113
1123
1132 static UnicodeSet* U_EXPORT2 createFrom(const UnicodeString& s);
1133
1134
1142 static UnicodeSet* U_EXPORT2 createFromAll(const UnicodeString& s);
1143
1157 virtual UnicodeSet& retain(UChar32 start, UChar32 end);
1158
1159
1166
1180 virtual UnicodeSet& remove(UChar32 start, UChar32 end);
1181
1190
1201
1209 virtual UnicodeSet& complement(void);
1210
1225 virtual UnicodeSet& complement(UChar32 start, UChar32 end);
1226
1235
1247
1260 virtual UnicodeSet& addAll(const UnicodeSet& c);
1261
1273 virtual UnicodeSet& retainAll(const UnicodeSet& c);
1274
1286 virtual UnicodeSet& removeAll(const UnicodeSet& c);
1287
1299
1306 virtual UnicodeSet& clear(void);
1307
1333 UnicodeSet& closeOver(int32_t attribute);
1334
1342
1350 virtual int32_t getRangeCount(void) const;
1351
1359 virtual UChar32 getRangeStart(int32_t index) const;
1360
1368 virtual UChar32 getRangeEnd(int32_t index) const;
1369
1418 int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const;
1419
1427
1439 static UClassID U_EXPORT2 getStaticClassID(void);
1440
1449 virtual UClassID getDynamicClassID(void) const;
1450
1451private:
1452
1453 // Private API for the USet API
1454
1455 friend class USetAccess;
1456
1457 int32_t getStringCount() const;
1458
1459 const UnicodeString* getString(int32_t index) const;
1460
1461 //----------------------------------------------------------------
1462 // RuleBasedTransliterator support
1463 //----------------------------------------------------------------
1464
1465private:
1466
1472 virtual UBool matchesIndexValue(uint8_t v) const;
1473
1474private:
1475 friend class RBBIRuleScanner;
1476
1477 //----------------------------------------------------------------
1478 // Implementation: Clone as thawed (see ICU4J Freezable)
1479 //----------------------------------------------------------------
1480
1481 UnicodeSet(const UnicodeSet& o, UBool /* asThawed */);
1482
1483 //----------------------------------------------------------------
1484 // Implementation: Pattern parsing
1485 //----------------------------------------------------------------
1486
1487 void applyPatternIgnoreSpace(const UnicodeString& pattern,
1488 ParsePosition& pos,
1489 const SymbolTable* symbols,
1490 UErrorCode& status);
1491
1492 void applyPattern(RuleCharacterIterator& chars,
1493 const SymbolTable* symbols,
1494 UnicodeString& rebuiltPat,
1495 uint32_t options,
1496 UnicodeSet& (UnicodeSet::*caseClosure)(int32_t attribute),
1497 UErrorCode& ec);
1498
1499 //----------------------------------------------------------------
1500 // Implementation: Utility methods
1501 //----------------------------------------------------------------
1502
1503 void ensureCapacity(int32_t newLen, UErrorCode& ec);
1504
1505 void ensureBufferCapacity(int32_t newLen, UErrorCode& ec);
1506
1507 void swapBuffers(void);
1508
1509 UBool allocateStrings(UErrorCode &status);
1510
1511 UnicodeString& _toPattern(UnicodeString& result,
1512 UBool escapeUnprintable) const;
1513
1514 UnicodeString& _generatePattern(UnicodeString& result,
1515 UBool escapeUnprintable) const;
1516
1517 static void _appendToPat(UnicodeString& buf, const UnicodeString& s, UBool escapeUnprintable);
1518
1519 static void _appendToPat(UnicodeString& buf, UChar32 c, UBool escapeUnprintable);
1520
1521 //----------------------------------------------------------------
1522 // Implementation: Fundamental operators
1523 //----------------------------------------------------------------
1524
1525 void exclusiveOr(const UChar32* other, int32_t otherLen, int8_t polarity);
1526
1527 void add(const UChar32* other, int32_t otherLen, int8_t polarity);
1528
1529 void retain(const UChar32* other, int32_t otherLen, int8_t polarity);
1530
1536 static UBool resemblesPropertyPattern(const UnicodeString& pattern,
1537 int32_t pos);
1538
1539 static UBool resemblesPropertyPattern(RuleCharacterIterator& chars,
1540 int32_t iterOpts);
1541
1581 UnicodeSet& applyPropertyPattern(const UnicodeString& pattern,
1582 ParsePosition& ppos,
1583 UErrorCode &ec);
1584
1585 void applyPropertyPattern(RuleCharacterIterator& chars,
1586 UnicodeString& rebuiltPat,
1587 UErrorCode& ec);
1588
1589 static const UnicodeSet* getInclusions(int32_t src, UErrorCode &status);
1590
1595 typedef UBool (*Filter)(UChar32 codePoint, void* context);
1596
1606 void applyFilter(Filter filter,
1607 void* context,
1608 int32_t src,
1609 UErrorCode &status);
1610
1614 void setPattern(const UnicodeString& newPat);
1618 void releasePattern();
1619
1620 friend class UnicodeSetIterator;
1621};
1622
1623
1624
1626 return !operator==(o);
1627}
1628
1630 return (UBool)(bmpSet!=NULL || stringSpan!=NULL);
1631}
1632
1634 return !containsNone(start, end);
1635}
1636
1638 return !containsNone(s);
1639}
1640
1642 return !containsNone(s);
1643}
1644
1646 return (UBool)(fFlags & kIsBogus);
1647}
1648
1650 return reinterpret_cast<UnicodeSet *>(uset);
1651}
1652
1653inline const UnicodeSet *UnicodeSet::fromUSet(const USet *uset) {
1654 return reinterpret_cast<const UnicodeSet *>(uset);
1655}
1656
1658 return reinterpret_cast<USet *>(this);
1659}
1660
1661inline const USet *UnicodeSet::toUSet() const {
1662 return reinterpret_cast<const USet *>(this);
1663}
1664
1665inline int32_t UnicodeSet::span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const {
1666 int32_t sLength=s.length();
1667 if(start<0) {
1668 start=0;
1669 } else if(start>sLength) {
1670 start=sLength;
1671 }
1672 return start+span(s.getBuffer()+start, sLength-start, spanCondition);
1673}
1674
1675inline int32_t UnicodeSet::spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const {
1676 int32_t sLength=s.length();
1677 if(limit<0) {
1678 limit=0;
1679 } else if(limit>sLength) {
1680 limit=sLength;
1681 }
1682 return spanBack(s.getBuffer(), limit, spanCondition);
1683}
1684
1686
1687#endif
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition parsepos.h:47
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition rep.h:71
An interface that defines both lookup protocol and parsing of symbolic names.
Definition symtable.h:54
UnicodeFilter defines a protocol for selecting a subset of the full range (U+0000 to U+10FFFF) of Uni...
Definition unifilt.h:59
UnicodeFunctor is an abstract base class for objects that perform match and/or replace operations on ...
Definition unifunct.h:33
virtual UBool matchesIndexValue(uint8_t v) const =0
Returns TRUE if this matcher will match a character c, where c & 0xFF == v, at offset,...
UnicodeFunctor * freeze()
Freeze the set (make it immutable).
virtual UnicodeSet & clear(void)
Removes all of the elements from this set.
static UnicodeSet * fromUSet(USet *uset)
Get a UnicodeSet pointer from a USet.
Definition uniset.h:1649
UnicodeSet()
Constructs an empty set.
virtual int32_t getRangeCount(void) const
Iteration method that returns the number of ranges contained in this set.
UBool isFrozen() const
Determines whether the set has been frozen (made immutable) or not.
Definition uniset.h:1629
virtual int32_t size(void) const
Returns the number of elements in this set (its cardinality).
static UnicodeSet * createFrom(const UnicodeString &s)
Makes a set from a multicharacter string.
UnicodeSet & addAll(const UnicodeString &s)
Adds each of the characters in this string to the set.
virtual UChar32 getRangeEnd(int32_t index) const
Iteration method that returns the last character in the specified range of this set.
static UClassID getStaticClassID(void)
Return the class ID for this class.
UnicodeSet & remove(UChar32 c)
Removes the specified character from this set if it is present.
UBool containsNone(const UnicodeSet &c) const
Returns true if this set contains none of the characters and strings of the given set.
virtual ~UnicodeSet()
Destructs the set.
UBool operator!=(const UnicodeSet &o) const
Compares the specified object with this set for equality.
Definition uniset.h:1625
UnicodeSet & add(UChar32 c)
Adds the specified character to this set if it is not already present.
virtual UnicodeSet & compact()
Reallocate this objects internal structures to take up the least possible space, without changing thi...
virtual UMatchDegree matches(const Replaceable &text, int32_t &offset, int32_t limit, UBool incremental)
Implement UnicodeMatcher::matches()
void setToBogus()
Make this UnicodeSet object invalid.
virtual void addMatchSetTo(UnicodeSet &toUnionTo) const
Implementation of UnicodeMatcher API.
UnicodeSet(const UnicodeSet &o)
Constructs a set that is identical to the given UnicodeSet.
UnicodeSet & remove(const UnicodeString &s)
Removes the specified string from this set if it is present.
UBool containsNone(UChar32 start, UChar32 end) const
Returns true if this set contains none of the characters of the given range.
virtual UnicodeSet & removeAllStrings()
Remove all strings from this set.
virtual UChar32 getRangeStart(int32_t index) const
Iteration method that returns the first character in the specified range of this set.
UnicodeSet & complement(UChar32 c)
Complements the specified character in this set.
virtual UnicodeSet & add(UChar32 start, UChar32 end)
Adds the specified range to this set if it is not already present.
static UBool resemblesPattern(const UnicodeString &pattern, int32_t pos)
Return true if the given position, in the given pattern, appears to be the start of a UnicodeSet patt...
UBool isBogus(void) const
Determine if this object contains a valid set.
Definition uniset.h:1645
UnicodeSet & closeOver(int32_t attribute)
Close this set over the given attribute.
UnicodeSet & operator=(const UnicodeSet &o)
Assigns this object to be a copy of another.
int32_t indexOf(UChar32 c) const
Returns the index of the given character within this set, where the set is ordered by ascending code ...
UChar32 charAt(int32_t index) const
Returns the character at the given index within this set, where the set is ordered by ascending code ...
virtual UBool contains(UChar32 start, UChar32 end) const
Returns true if this set contains every character of the given range.
int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode &ec) const
Serializes this set into an array of 16-bit integers.
virtual UBool contains(UChar32 c) const
Returns true if this set contains the given character.
UBool containsSome(UChar32 start, UChar32 end) const
Returns true if this set contains one or more of the characters in the given range.
Definition uniset.h:1633
virtual UnicodeSet & remove(UChar32 start, UChar32 end)
Removes the specified range from this set if it is present.
virtual int32_t hashCode(void) const
Returns the hash code value for this set.
virtual UBool isEmpty(void) const
Returns true if this set contains no elements.
UnicodeSet & removeAll(const UnicodeString &s)
Remove EACH of the characters in this string.
UBool contains(const UnicodeString &s) const
Returns true if this set contains the given multicharacter string.
UnicodeSet & complementAll(const UnicodeString &s)
Complement EACH of the characters in this string.
UnicodeSet & applyPattern(const UnicodeString &pattern, ParsePosition &pos, uint32_t options, const SymbolTable *symbols, UErrorCode &status)
Parses the given pattern, starting at the given position.
UnicodeSet & add(const UnicodeString &s)
Adds the specified multicharacter to this set if it is not already present.
virtual UBool operator==(const UnicodeSet &o) const
Compares the specified object with this set for equality.
UnicodeSet(UChar32 start, UChar32 end)
Constructs a set containing the given range.
UnicodeSet & retainAll(const UnicodeString &s)
Retains EACH of the characters in this string.
virtual UnicodeSet & retain(UChar32 start, UChar32 end)
Retain only the elements in this set that are contained in the specified range.
UnicodeSet(const UnicodeString &pattern, uint32_t options, const SymbolTable *symbols, UErrorCode &status)
Constructs a set from the given pattern.
virtual UnicodeString & toPattern(UnicodeString &result, UBool escapeUnprintable=FALSE) const
Returns a string representation of this set.
USet * toUSet()
Produce a USet * pointer for this UnicodeSet.
Definition uniset.h:1657
virtual UnicodeSet & complement(void)
Inverts this set.
UnicodeSet & retain(UChar32 c)
Retain the specified character from this set if it is present.
UnicodeSet & applyPattern(const UnicodeString &pattern, uint32_t options, const SymbolTable *symbols, UErrorCode &status)
Modifies this set to represent the set specified by the given pattern, optionally ignoring Unicode Pa...
UBool containsNone(const UnicodeString &s) const
Returns true if this set contains none of the characters of the given string.
virtual UnicodeSet & complement(UChar32 start, UChar32 end)
Complements the specified range in this set.
virtual UnicodeSet & removeAll(const UnicodeSet &c)
Removes from this set all of its elements that are contained in the specified set.
virtual UnicodeFunctor * clone() const
Returns a copy of this object.
UnicodeSet & applyPattern(const UnicodeString &pattern, UErrorCode &status)
Modifies this set to represent the set specified by the given pattern, ignoring Unicode Pattern_White...
UnicodeSet & applyPropertyAlias(const UnicodeString &prop, const UnicodeString &value, UErrorCode &ec)
Modifies this set to contain those code points which have the given value for the given property.
int32_t spanBackUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const
Returns the start of the trailing substring of the input string which consists only of characters and...
UBool containsAll(const UnicodeString &s) const
Returns true if this set contains all the characters of the given string.
virtual UBool containsAll(const UnicodeSet &c) const
Returns true if this set contains all the characters and strings of the given set.
virtual UnicodeSet & retainAll(const UnicodeSet &c)
Retains only the elements in this set that are contained in the specified set.
virtual UClassID getDynamicClassID(void) const
Implement UnicodeFunctor API.
UnicodeSet & complement(const UnicodeString &s)
Complement the specified string in this set.
UnicodeSet(const UnicodeString &pattern, UErrorCode &status)
Constructs a set from the given pattern.
@ MIN_VALUE
Minimum value that can be stored in a UnicodeSet.
Definition uniset.h:338
@ MAX_VALUE
Maximum value that can be stored in a UnicodeSet.
Definition uniset.h:344
UnicodeSet & set(UChar32 start, UChar32 end)
Make this object represent the range start - end.
int32_t span(const UChar *s, int32_t length, USetSpanCondition spanCondition) const
Returns the length of the initial substring of the input string which consists only of characters and...
virtual UnicodeSet & addAll(const UnicodeSet &c)
Adds all of the elements in the specified set to this set if they're not already present.
int32_t spanUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const
Returns the length of the initial substring of the input string which consists only of characters and...
virtual UnicodeSet & complementAll(const UnicodeSet &c)
Complements in this set all elements contained in the specified set.
static UnicodeSet * createFromAll(const UnicodeString &s)
Makes a set from each of the characters in the string.
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 binary or enu...
int32_t spanBack(const UChar *s, int32_t length, USetSpanCondition spanCondition) const
Returns the start of the trailing substring of the input string which consists only of characters and...
UnicodeFunctor * cloneAsThawed() const
Clone the set and make the clone mutable.
UnicodeSet(const UnicodeString &pattern, ParsePosition &pos, uint32_t options, const SymbolTable *symbols, UErrorCode &status)
Constructs a set from the given pattern.
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition unistr.h:247
UChar * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
int32_t length(void) const
Return the length of the UnicodeString object.
Definition unistr.h:3610
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
UProperty
Selection constants for Unicode properties.
Definition uchar.h:161
struct USet USet
A UnicodeSet.
Definition ucnv.h:67
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:298
int8_t UBool
The ICU boolean type.
Definition umachine.h:200
#define FALSE
The FALSE value of a UBool.
Definition umachine.h:208
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition umachine.h:278
C++ API: Unicode Filter.
UMatchDegree
Constants returned by UnicodeMatcher::matches() indicating the degree of match.
Definition unimatch.h:30
C++ API: Unicode String.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition uobject.h:96
C API: Unicode Set.
USetSpanCondition
Argument values for whether span() and similar functions continue while the current character is cont...
Definition uset.h:150
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition utypes.h:186
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:476
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
Definition utypes.h:357
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition uversion.h:130
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition uversion.h:129