ICU-59131.0.1.tar.gz
[apple/icu.git] / icuSources / common / uset.cpp
index add0ee0f6a8993aabe71be21df5511ee2e2f2e0b..39ad0a340c4414dbb53c5a2978439fa6dcffa8cb 100644 (file)
@@ -1,21 +1,20 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2002-2007, International Business Machines
+*   Copyright (C) 2002-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
-*   file name:  uset.c
-*   encoding:   US-ASCII
+*   file name:  uset.cpp
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
 *   created on: 2002mar07
 *   created by: Markus W. Scherer
 *
-*   The serialized structure, the array of range limits, is
-*   the same as in UnicodeSet, except that the HIGH value is not stored.
-*
 *   There are functions to efficiently serialize a USet into an array of uint16_t
 *   and functions to use such a serialized form efficiently without
 *   instantiating a new USet.
 
 U_NAMESPACE_USE
 
+U_CAPI USet* U_EXPORT2
+uset_openEmpty() {
+    return (USet*) new UnicodeSet();
+}
+
 U_CAPI USet* U_EXPORT2
 uset_open(UChar32 start, UChar32 end) {
     return (USet*) new UnicodeSet(start, end);
@@ -147,6 +151,11 @@ uset_clear(USet* set) {
     ((UnicodeSet*) set)->UnicodeSet::clear();
 }
 
+U_CAPI void U_EXPORT2
+uset_removeAllStrings(USet* set) {
+    ((UnicodeSet*) set)->UnicodeSet::removeAllStrings();
+}
+
 U_CAPI UBool U_EXPORT2
 uset_isEmpty(const USet* set) {
     return ((const UnicodeSet*) set)->UnicodeSet::isEmpty();
@@ -482,13 +491,12 @@ uset_getSerializedRange(const USerializedSet* set, int32_t rangeIndex,
     if(rangeIndex<bmpLength) {
         *pStart=array[rangeIndex++];
         if(rangeIndex<bmpLength) {
-            *pEnd=array[rangeIndex];
+            *pEnd=array[rangeIndex]-1;
         } else if(rangeIndex<length) {
-            *pEnd=(((int32_t)array[rangeIndex])<<16)|array[rangeIndex+1];
+            *pEnd=((((int32_t)array[rangeIndex])<<16)|array[rangeIndex+1])-1;
         } else {
-            *pEnd=0x110000;
+            *pEnd=0x10ffff;
         }
-        --*pEnd;
         return TRUE;
     } else {
         rangeIndex-=bmpLength;
@@ -499,11 +507,10 @@ uset_getSerializedRange(const USerializedSet* set, int32_t rangeIndex,
             *pStart=(((int32_t)array[rangeIndex])<<16)|array[rangeIndex+1];
             rangeIndex+=2;
             if(rangeIndex<length) {
-                *pEnd=(((int32_t)array[rangeIndex])<<16)|array[rangeIndex+1];
+                *pEnd=((((int32_t)array[rangeIndex])<<16)|array[rangeIndex+1])-1;
             } else {
-                *pEnd=0x110000;
+                *pEnd=0x10ffff;
             }
-            --*pEnd;
             return TRUE;
         } else {
             return FALSE;
@@ -521,7 +528,7 @@ uset_getSerializedRange(const USerializedSet* set, int32_t rangeIndex,
 // ---
 // #define USET_GROW_DELTA 20
 // 
-// static U_INLINE int32_t
+// static int32_t
 // findChar(const UChar32* array, int32_t length, UChar32 c) {
 //     int32_t i;
 //