ICU 58.2 58.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

uniset.h
Go to the documentation of this file.
1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 ***************************************************************************
5 * Copyright (C) 1999-2016, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ***************************************************************************
8 * Date Name Description
9 * 10/20/99 alan Creation.
10 ***************************************************************************
11 */
12
13 #ifndef UNICODESET_H
14 #define UNICODESET_H
15
16 #include "unicode/unifilt.h"
17 #include "unicode/unistr.h"
18 #include "unicode/uset.h"
19
25 U_NAMESPACE_BEGIN
26
27 // Forward Declarations.
28 void U_CALLCONV UnicodeSet_initInclusion(int32_t src, UErrorCode &status);
30 class BMPSet;
31 class ParsePosition;
32 class RBBIRuleScanner;
33 class SymbolTable;
34 class UnicodeSetStringSpan;
35 class UVector;
36 class RuleCharacterIterator;
37
278 class U_COMMON_API UnicodeSet U_FINAL : public UnicodeFilter {
279
280 int32_t len; // length of list used; 0 <= len <= capacity
281 int32_t capacity; // capacity of list
282 UChar32* list; // MUST be terminated with HIGH
283 BMPSet *bmpSet; // The set is frozen iff either bmpSet or stringSpan is not NULL.
284 UChar32* buffer; // internal buffer, may be NULL
285 int32_t bufferCapacity; // capacity of buffer
286 int32_t patLen;
287
297 UChar *pat;
298 UVector* strings; // maintained in sorted order
299 UnicodeSetStringSpan *stringSpan;
300
301 private:
302 enum { // constants
303 kIsBogus = 1 // This set is bogus (i.e. not valid)
304 };
305 uint8_t fFlags; // Bit flag (see constants above)
306 public:
316 inline UBool isBogus(void) const;
317
334 void setToBogus();
335
336 public:
337
338 enum {
343 MIN_VALUE = 0,
344
349 MAX_VALUE = 0x10ffff
350 };
351
352 //----------------------------------------------------------------
353 // Constructors &c
354 //----------------------------------------------------------------
355
356 public:
357
362 UnicodeSet();
363
372 UnicodeSet(UChar32 start, UChar32 end);
373
374 #ifndef U_HIDE_INTERNAL_API
375
378 enum ESerialization {
379 kSerialized /* result of serialize() */
380 };
381
392 UnicodeSet(const uint16_t buffer[], int32_t bufferLen,
393 ESerialization serialization, UErrorCode &status);
394 #endif /* U_HIDE_INTERNAL_API */
395
404 UnicodeSet(const UnicodeString& pattern,
405 UErrorCode& status);
406
407 #ifndef U_HIDE_INTERNAL_API
408
420 UnicodeSet(const UnicodeString& pattern,
421 uint32_t options,
422 const SymbolTable* symbols,
423 UErrorCode& status);
424 #endif /* U_HIDE_INTERNAL_API */
425
439 UnicodeSet(const UnicodeString& pattern, ParsePosition& pos,
440 uint32_t options,
441 const SymbolTable* symbols,
442 UErrorCode& status);
443
448 UnicodeSet(const UnicodeSet& o);
449
454 virtual ~UnicodeSet();
455
461 UnicodeSet& operator=(const UnicodeSet& o);
462
474 virtual UBool operator==(const UnicodeSet& o) const;
475
481 UBool operator!=(const UnicodeSet& o) const;
482
492 virtual UnicodeFunctor* clone() const;
493
501 virtual int32_t hashCode(void) const;
502
511 inline static UnicodeSet *fromUSet(USet *uset);
512
521 inline static const UnicodeSet *fromUSet(const USet *uset);
522
530 inline USet *toUSet();
531
532
540 inline const USet * toUSet() const;
541
542
543 //----------------------------------------------------------------
544 // Freezable API
545 //----------------------------------------------------------------
546
555 inline UBool isFrozen() const;
556
570 UnicodeFunctor *freeze();
571
580 UnicodeFunctor *cloneAsThawed() const;
581
582 //----------------------------------------------------------------
583 // Public API
584 //----------------------------------------------------------------
585
596 UnicodeSet& set(UChar32 start, UChar32 end);
597
603 static UBool resemblesPattern(const UnicodeString& pattern,
604 int32_t pos);
605
618 UnicodeSet& applyPattern(const UnicodeString& pattern,
619 UErrorCode& status);
620
621 #ifndef U_HIDE_INTERNAL_API
622
638 UnicodeSet& applyPattern(const UnicodeString& pattern,
639 uint32_t options,
640 const SymbolTable* symbols,
641 UErrorCode& status);
642 #endif /* U_HIDE_INTERNAL_API */
643
675 UnicodeSet& applyPattern(const UnicodeString& pattern,
676 ParsePosition& pos,
677 uint32_t options,
678 const SymbolTable* symbols,
679 UErrorCode& status);
680
694 virtual UnicodeString& toPattern(UnicodeString& result,
695 UBool escapeUnprintable = FALSE) const;
696
719 UnicodeSet& applyIntPropertyValue(UProperty prop,
720 int32_t value,
721 UErrorCode& ec);
722
752 UnicodeSet& applyPropertyAlias(const UnicodeString& prop,
753 const UnicodeString& value,
754 UErrorCode& ec);
755
764 virtual int32_t size(void) const;
765
772 virtual UBool isEmpty(void) const;
773
781 virtual UBool contains(UChar32 c) const;
782
791 virtual UBool contains(UChar32 start, UChar32 end) const;
792
800 UBool contains(const UnicodeString& s) const;
801
809 virtual UBool containsAll(const UnicodeSet& c) const;
810
818 UBool containsAll(const UnicodeString& s) const;
819
828 UBool containsNone(UChar32 start, UChar32 end) const;
829
837 UBool containsNone(const UnicodeSet& c) const;
838
846 UBool containsNone(const UnicodeString& s) const;
847
856 inline UBool containsSome(UChar32 start, UChar32 end) const;
857
865 inline UBool containsSome(const UnicodeSet& s) const;
866
874 inline UBool containsSome(const UnicodeString& s) const;
875
894 int32_t span(const UChar *s, int32_t length, USetSpanCondition spanCondition) const;
895
908 inline int32_t span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const;
909
927 int32_t spanBack(const UChar *s, int32_t length, USetSpanCondition spanCondition) const;
928
942 inline int32_t spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const;
943
962 int32_t spanUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
963
981 int32_t spanBackUTF8(const char *s, int32_t length, USetSpanCondition spanCondition) const;
982
987 virtual UMatchDegree matches(const Replaceable& text,
988 int32_t& offset,
989 int32_t limit,
990 UBool incremental);
991
992 private:
1015 static int32_t matchRest(const Replaceable& text,
1016 int32_t start, int32_t limit,
1017 const UnicodeString& s);
1018
1028 int32_t findCodePoint(UChar32 c) const;
1029
1030 public:
1031
1039 virtual void addMatchSetTo(UnicodeSet& toUnionTo) const;
1040
1049 int32_t indexOf(UChar32 c) const;
1050
1060 UChar32 charAt(int32_t index) const;
1061
1076 virtual UnicodeSet& add(UChar32 start, UChar32 end);
1077
1085 UnicodeSet& add(UChar32 c);
1086
1098 UnicodeSet& add(const UnicodeString& s);
1099
1100 private:
1106 static int32_t getSingleCP(const UnicodeString& s);
1107
1108 void _add(const UnicodeString& s);
1109
1110 public:
1119 UnicodeSet& addAll(const UnicodeString& s);
1120
1129 UnicodeSet& retainAll(const UnicodeString& s);
1130
1139 UnicodeSet& complementAll(const UnicodeString& s);
1140
1149 UnicodeSet& removeAll(const UnicodeString& s);
1150
1159 static UnicodeSet* U_EXPORT2 createFrom(const UnicodeString& s);
1160
1161
1169 static UnicodeSet* U_EXPORT2 createFromAll(const UnicodeString& s);
1170
1184 virtual UnicodeSet& retain(UChar32 start, UChar32 end);
1185
1186
1192 UnicodeSet& retain(UChar32 c);
1193
1207 virtual UnicodeSet& remove(UChar32 start, UChar32 end);
1208
1216 UnicodeSet& remove(UChar32 c);
1217
1227 UnicodeSet& remove(const UnicodeString& s);
1228
1236 virtual UnicodeSet& complement(void);
1237
1252 virtual UnicodeSet& complement(UChar32 start, UChar32 end);
1253
1261 UnicodeSet& complement(UChar32 c);
1262
1273 UnicodeSet& complement(const UnicodeString& s);
1274
1287 virtual UnicodeSet& addAll(const UnicodeSet& c);
1288
1300 virtual UnicodeSet& retainAll(const UnicodeSet& c);
1301
1313 virtual UnicodeSet& removeAll(const UnicodeSet& c);
1314
1325 virtual UnicodeSet& complementAll(const UnicodeSet& c);
1326
1333 virtual UnicodeSet& clear(void);
1334
1360 UnicodeSet& closeOver(int32_t attribute);
1361
1368 virtual UnicodeSet &removeAllStrings();
1369
1377 virtual int32_t getRangeCount(void) const;
1378
1386 virtual UChar32 getRangeStart(int32_t index) const;
1387
1395 virtual UChar32 getRangeEnd(int32_t index) const;
1396
1445 int32_t serialize(uint16_t *dest, int32_t destCapacity, UErrorCode& ec) const;
1446
1453 virtual UnicodeSet& compact();
1454
1466 static UClassID U_EXPORT2 getStaticClassID(void);
1467
1476 virtual UClassID getDynamicClassID(void) const;
1477
1478 private:
1479
1480 // Private API for the USet API
1481
1482 friend class USetAccess;
1483
1484 int32_t getStringCount() const;
1485
1486 const UnicodeString* getString(int32_t index) const;
1487
1488 //----------------------------------------------------------------
1489 // RuleBasedTransliterator support
1490 //----------------------------------------------------------------
1491
1492 private:
1493
1499 virtual UBool matchesIndexValue(uint8_t v) const;
1500
1501 private:
1502 friend class RBBIRuleScanner;
1503
1504 //----------------------------------------------------------------
1505 // Implementation: Clone as thawed (see ICU4J Freezable)
1506 //----------------------------------------------------------------
1507
1508 UnicodeSet(const UnicodeSet& o, UBool /* asThawed */);
1509
1510 //----------------------------------------------------------------
1511 // Implementation: Pattern parsing
1512 //----------------------------------------------------------------
1513
1514 void applyPatternIgnoreSpace(const UnicodeString& pattern,
1515 ParsePosition& pos,
1516 const SymbolTable* symbols,
1517 UErrorCode& status);
1518
1519 void applyPattern(RuleCharacterIterator& chars,
1520 const SymbolTable* symbols,
1521 UnicodeString& rebuiltPat,
1522 uint32_t options,
1523 UnicodeSet& (UnicodeSet::*caseClosure)(int32_t attribute),
1524 UErrorCode& ec);
1525
1526 //----------------------------------------------------------------
1527 // Implementation: Utility methods
1528 //----------------------------------------------------------------
1529
1530 void ensureCapacity(int32_t newLen, UErrorCode& ec);
1531
1532 void ensureBufferCapacity(int32_t newLen, UErrorCode& ec);
1533
1534 void swapBuffers(void);
1535
1536 UBool allocateStrings(UErrorCode &status);
1537
1538 UnicodeString& _toPattern(UnicodeString& result,
1539 UBool escapeUnprintable) const;
1540
1541 UnicodeString& _generatePattern(UnicodeString& result,
1542 UBool escapeUnprintable) const;
1543
1544 static void _appendToPat(UnicodeString& buf, const UnicodeString& s, UBool escapeUnprintable);
1545
1546 static void _appendToPat(UnicodeString& buf, UChar32 c, UBool escapeUnprintable);
1547
1548 //----------------------------------------------------------------
1549 // Implementation: Fundamental operators
1550 //----------------------------------------------------------------
1551
1552 void exclusiveOr(const UChar32* other, int32_t otherLen, int8_t polarity);
1553
1554 void add(const UChar32* other, int32_t otherLen, int8_t polarity);
1555
1556 void retain(const UChar32* other, int32_t otherLen, int8_t polarity);
1557
1563 static UBool resemblesPropertyPattern(const UnicodeString& pattern,
1564 int32_t pos);
1565
1566 static UBool resemblesPropertyPattern(RuleCharacterIterator& chars,
1567 int32_t iterOpts);
1568
1608 UnicodeSet& applyPropertyPattern(const UnicodeString& pattern,
1609 ParsePosition& ppos,
1610 UErrorCode &ec);
1611
1612 void applyPropertyPattern(RuleCharacterIterator& chars,
1613 UnicodeString& rebuiltPat,
1614 UErrorCode& ec);
1615
1616 friend void U_CALLCONV UnicodeSet_initInclusion(int32_t src, UErrorCode &status);
1617 static const UnicodeSet* getInclusions(int32_t src, UErrorCode &status);
1618
1623 typedef UBool (*Filter)(UChar32 codePoint, void* context);
1624
1634 void applyFilter(Filter filter,
1635 void* context,
1636 int32_t src,
1637 UErrorCode &status);
1638
1642 void setPattern(const UnicodeString& newPat);
1646 void releasePattern();
1647
1648 friend class UnicodeSetIterator;
1649 };
1650
1651
1652
1653 inline UBool UnicodeSet::operator!=(const UnicodeSet& o) const {
1654 return !operator==(o);
1655 }
1656
1657 inline UBool UnicodeSet::isFrozen() const {
1658 return (UBool)(bmpSet!=NULL || stringSpan!=NULL);
1659 }
1660
1661 inline UBool UnicodeSet::containsSome(UChar32 start, UChar32 end) const {
1662 return !containsNone(start, end);
1663 }
1664
1665 inline UBool UnicodeSet::containsSome(const UnicodeSet& s) const {
1666 return !containsNone(s);
1667 }
1668
1669 inline UBool UnicodeSet::containsSome(const UnicodeString& s) const {
1670 return !containsNone(s);
1671 }
1672
1673 inline UBool UnicodeSet::isBogus() const {
1674 return (UBool)(fFlags & kIsBogus);
1675 }
1676
1677 inline UnicodeSet *UnicodeSet::fromUSet(USet *uset) {
1678 return reinterpret_cast<UnicodeSet *>(uset);
1679 }
1680
1681 inline const UnicodeSet *UnicodeSet::fromUSet(const USet *uset) {
1682 return reinterpret_cast<const UnicodeSet *>(uset);
1683 }
1684
1685 inline USet *UnicodeSet::toUSet() {
1686 return reinterpret_cast<USet *>(this);
1687 }
1688
1689 inline const USet *UnicodeSet::toUSet() const {
1690 return reinterpret_cast<const USet *>(this);
1691 }
1692
1693 inline int32_t UnicodeSet::span(const UnicodeString &s, int32_t start, USetSpanCondition spanCondition) const {
1694 int32_t sLength=s.length();
1695 if(start<0) {
1696 start=0;
1697 } else if(start>sLength) {
1698 start=sLength;
1699 }
1700 return start+span(s.getBuffer()+start, sLength-start, spanCondition);
1701 }
1702
1703 inline int32_t UnicodeSet::spanBack(const UnicodeString &s, int32_t limit, USetSpanCondition spanCondition) const {
1704 int32_t sLength=s.length();
1705 if(limit<0) {
1706 limit=0;
1707 } else if(limit>sLength) {
1708 limit=sLength;
1709 }
1710 return spanBack(s.getBuffer(), limit, spanCondition);
1711 }
1712
1713 U_NAMESPACE_END
1714
1715 #endif
icu::UnicodeSet::containsSome
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:1661
icu::UnicodeSet::spanBack
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...
icu::UnicodeFilter::getStaticClassID
static UClassID getStaticClassID()
ICU "poor man&#39;s RTTI", returns a UClassID for this class.
icu::UMatchDegree
UMatchDegree
Constants returned by UnicodeMatcher::matches() indicating the degree of match.
Definition: unimatch.h:32
unistr.h
C++ API: Unicode String.
icu::operator==
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
icu::UnicodeSetIterator
UnicodeSetIterator iterates over the contents of a UnicodeSet.
Definition: usetiter.h:63
U_CALLCONV
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:857
UClassID
void * UClassID
UClassID is used to identify classes without using the compiler&#39;s RTTI.
Definition: uobject.h:93
icu::UnicodeSet::isFrozen
UBool isFrozen() const
Determines whether the set has been frozen (made immutable) or not.
Definition: uniset.h:1657
icu::UnicodeSet::fromUSet
static UnicodeSet * fromUSet(USet *uset)
Get a UnicodeSet pointer from a USet.
Definition: uniset.h:1677
icu::UnicodeSet::ESerialization
ESerialization
Definition: uniset.h:378
icu::UnicodeSet::operator!=
UBool operator!=(const UnicodeSet &o) const
Compares the specified object with this set for equality.
Definition: uniset.h:1653
icu::UnicodeMatcher::matchesIndexValue
virtual UBool matchesIndexValue(uint8_t v) const =0
Returns TRUE if this matcher will match a character c, where c & 0xFF == v, at offset, in the forward direction (with limit > offset).
uset.h
C API: Unicode Set.
icu::SymbolTable
An interface that defines both lookup protocol and parsing of symbolic names.
Definition: symtable.h:56
icu::UnicodeSet::isBogus
UBool isBogus(void) const
Determine if this object contains a valid set.
Definition: uniset.h:1673
icu::UnicodeFunctor::getDynamicClassID
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID polymorphically.
icu::UnicodeFunctor::clone
virtual UnicodeFunctor * clone() const =0
Return a copy of this object.
icu::Replaceable
Replaceable is an abstract base class representing a string of characters that supports the replaceme...
Definition: rep.h:73
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:131
icu::UnicodeFilter
UnicodeFilter defines a protocol for selecting a subset of the full range (U+0000 to U+10FFFF) of Uni...
Definition: unifilt.h:61
icu::UnicodeString::getBuffer
UChar * getBuffer(int32_t minCapacity)
Get a read/write pointer to the internal buffer.
icu::UnicodeMatcher::addMatchSetTo
virtual void addMatchSetTo(UnicodeSet &toUnionTo) const =0
Union the set of all characters that may be matched by this object into the given set...
icu::operator!=
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
Definition: stringpiece.h:220
UChar32
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:357
NULL
#define NULL
Define NULL if necessary, to 0 for C++ and to ((void *)0) for C.
Definition: utypes.h:188
icu::UnicodeFunctor
UnicodeFunctor is an abstract base class for objects that perform match and/or replace operations on ...
Definition: unifunct.h:35
icu::UnicodeFilter::matches
virtual UMatchDegree matches(const Replaceable &text, int32_t &offset, int32_t limit, UBool incremental)
Implement UnicodeMatcher API.
icu::UnicodeSet
A mutable set of Unicode characters and multicharacter strings.
Definition: uniset.h:278
USetSpanCondition
USetSpanCondition
Argument values for whether span() and similar functions continue while the current character is cont...
Definition: uset.h:152
icu::UnicodeSet::span
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...
UChar
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:337
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:132
USet
struct USet USet
Definition: ucnv.h:69
UProperty
UProperty
Selection constants for Unicode properties.
Definition: uchar.h:163
UErrorCode
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
icu::ParsePosition
ParsePosition is a simple class used by Format and its subclasses to keep track of the current positi...
Definition: parsepos.h:49
icu::UnicodeSet_initInclusion
void UnicodeSet_initInclusion(int32_t src, UErrorCode &status)
icu::UnicodeMatcher::toPattern
virtual UnicodeString & toPattern(UnicodeString &result, UBool escapeUnprintable=FALSE) const =0
Returns a string representation of this matcher.
icu::UnicodeFilter::contains
virtual UBool contains(UChar32 c) const =0
Returns true for characters that are in the selected subset.
FALSE
#define FALSE
The FALSE value of a UBool.
Definition: umachine.h:267
U_COMMON_API
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:359
icu::UnicodeString
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
icu::UnicodeSet::toUSet
USet * toUSet()
Produce a USet * pointer for this UnicodeSet.
Definition: uniset.h:1685
unifilt.h
C++ API: Unicode Filter.
icu::UnicodeString::length
int32_t length(void) const
Return the length of the UnicodeString object.
Definition: unistr.h:3792
UBool
int8_t UBool
The ICU boolean type.
Definition: umachine.h:259