]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/unicode/ucharstrie.h
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / common / unicode / ucharstrie.h
index 0575a974d0c957acc7d37fcc00e36d038a7c1aba..533e8c554b7aeab14539c6e390a63ceee4bd59a8 100644 (file)
@@ -1,10 +1,12 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 *   Copyright (C) 2010-2012, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *******************************************************************************
 *   file name:  ucharstrie.h
-*   encoding:   US-ASCII
+*   encoding:   UTF-8
 *   tab size:   8 (not used)
 *   indentation:4
 *
@@ -26,6 +28,7 @@
 #include "unicode/uobject.h"
 #include "unicode/ustringtrie.h"
 
+#if U_SHOW_CPLUSPLUS_API
 U_NAMESPACE_BEGIN
 
 class Appendable;
@@ -34,7 +37,7 @@ class UVector32;
 
 /**
  * Light-weight, non-const reader class for a UCharsTrie.
- * Traverses a UChar-serialized data structure with minimal state,
+ * Traverses a char16_t-serialized data structure with minimal state,
  * for mapping strings (16-bit-unit sequences) to non-negative integer values.
  *
  * This class owns the serialized trie data only if it was constructed by
@@ -50,18 +53,18 @@ public:
     /**
      * Constructs a UCharsTrie reader instance.
      *
-     * The trieUChars must contain a copy of a UChar sequence from the UCharsTrieBuilder,
-     * starting with the first UChar of that sequence.
-     * The UCharsTrie object will not read more UChars than
+     * The trieUChars must contain a copy of a char16_t sequence from the UCharsTrieBuilder,
+     * starting with the first char16_t of that sequence.
+     * The UCharsTrie object will not read more char16_ts than
      * the UCharsTrieBuilder generated in the corresponding build() call.
      *
      * The array is not copied/cloned and must not be modified while
      * the UCharsTrie object is in use.
      *
-     * @param trieUChars The UChar array that contains the serialized trie.
+     * @param trieUChars The char16_t array that contains the serialized trie.
      * @stable ICU 4.8
      */
-    UCharsTrie(const UChar *trieUChars)
+    UCharsTrie(ConstChar16Ptr trieUChars)
             : ownedArray_(NULL), uchars_(trieUChars),
               pos_(uchars_), remainingMatchLength_(-1) {}
 
@@ -73,7 +76,7 @@ public:
 
     /**
      * Copy constructor, copies the other trie reader object and its state,
-     * but not the UChar array which will be shared. (Shallow copy.)
+     * but not the char16_t array which will be shared. (Shallow copy.)
      * @param other Another UCharsTrie object.
      * @stable ICU 4.8
      */
@@ -107,8 +110,8 @@ public:
     private:
         friend class UCharsTrie;
 
-        const UChar *uchars;
-        const UChar *pos;
+        const char16_t *uchars;
+        const char16_t *pos;
         int32_t remainingMatchLength;
     };
 
@@ -146,14 +149,14 @@ public:
 
     /**
      * Determines whether the string so far matches, whether it has a value,
-     * and whether another input UChar can continue a matching string.
+     * and whether another input char16_t can continue a matching string.
      * @return The match/value Result.
      * @stable ICU 4.8
      */
     UStringTrieResult current() const;
 
     /**
-     * Traverses the trie from the initial state for this input UChar.
+     * Traverses the trie from the initial state for this input char16_t.
      * Equivalent to reset().next(uchar).
      * @param uchar Input char value. Values below 0 and above 0xffff will never match.
      * @return The match/value Result.
@@ -175,7 +178,7 @@ public:
     UStringTrieResult firstForCodePoint(UChar32 cp);
 
     /**
-     * Traverses the trie from the current state for this input UChar.
+     * Traverses the trie from the current state for this input char16_t.
      * @param uchar Input char value. Values below 0 and above 0xffff will never match.
      * @return The match/value Result.
      * @stable ICU 4.8
@@ -206,7 +209,7 @@ public:
      * @return The match/value Result.
      * @stable ICU 4.8
      */
-    UStringTrieResult next(const UChar *s, int32_t length);
+    UStringTrieResult next(ConstChar16Ptr s, int32_t length);
 
     /**
      * Returns a matching string's value if called immediately after
@@ -218,7 +221,7 @@ public:
      * @stable ICU 4.8
      */
     inline int32_t getValue() const {
-        const UChar *pos=pos_;
+        const char16_t *pos=pos_;
         int32_t leadUnit=*pos++;
         // U_ASSERT(leadUnit>=kMinValueLead);
         return leadUnit&kValueIsFinal ?
@@ -235,16 +238,16 @@ public:
      * @stable ICU 4.8
      */
     inline UBool hasUniqueValue(int32_t &uniqueValue) const {
-        const UChar *pos=pos_;
+        const char16_t *pos=pos_;
         // Skip the rest of a pending linear-match node.
         return pos!=NULL && findUniqueValue(pos+remainingMatchLength_+1, FALSE, uniqueValue);
     }
 
     /**
-     * Finds each UChar which continues the string from the current state.
-     * That is, each UChar c for which it would be next(c)!=USTRINGTRIE_NO_MATCH now.
-     * @param out Each next UChar is appended to this object.
-     * @return the number of UChars which continue the string from here
+     * Finds each char16_t which continues the string from the current state.
+     * That is, each char16_t c for which it would be next(c)!=USTRINGTRIE_NO_MATCH now.
+     * @param out Each next char16_t is appended to this object.
+     * @return the number of char16_ts which continue the string from here
      * @stable ICU 4.8
      */
     int32_t getNextUChars(Appendable &out) const;
@@ -256,8 +259,8 @@ public:
     class U_COMMON_API Iterator : public UMemory {
     public:
         /**
-         * Iterates from the root of a UChar-serialized UCharsTrie.
-         * @param trieUChars The trie UChars.
+         * Iterates from the root of a char16_t-serialized UCharsTrie.
+         * @param trieUChars The trie char16_ts.
          * @param maxStringLength If 0, the iterator returns full strings.
          *                        Otherwise, the iterator returns strings with this maximum length.
          * @param errorCode Standard ICU error code. Its input value must
@@ -266,7 +269,7 @@ public:
          *                  function chaining. (See User Guide for details.)
          * @stable ICU 4.8
          */
-        Iterator(const UChar *trieUChars, int32_t maxStringLength, UErrorCode &errorCode);
+        Iterator(ConstChar16Ptr trieUChars, int32_t maxStringLength, UErrorCode &errorCode);
 
         /**
          * Iterates from the current state of the specified UCharsTrie.
@@ -334,11 +337,11 @@ public:
             return TRUE;
         }
 
-        const UChar *branchNext(const UChar *pos, int32_t length, UErrorCode &errorCode);
+        const char16_t *branchNext(const char16_t *pos, int32_t length, UErrorCode &errorCode);
 
-        const UChar *uchars_;
-        const UChar *pos_;
-        const UChar *initialPos_;
+        const char16_t *uchars_;
+        const char16_t *pos_;
+        const char16_t *initialPos_;
         int32_t remainingMatchLength_;
         int32_t initialRemainingMatchLength_;
         UBool skipValue_;  // Skip intermediate value which was already delivered.
@@ -366,7 +369,7 @@ private:
      * this constructor adopts the builder's array.
      * This constructor is only called by the builder.
      */
-    UCharsTrie(UChar *adoptUChars, const UChar *trieUChars)
+    UCharsTrie(char16_t *adoptUChars, const char16_t *trieUChars)
             : ownedArray_(adoptUChars), uchars_(trieUChars),
               pos_(uchars_), remainingMatchLength_(-1) {}
 
@@ -379,7 +382,7 @@ private:
 
     // Reads a compact 32-bit integer.
     // pos is already after the leadUnit, and the lead unit has bit 15 reset.
-    static inline int32_t readValue(const UChar *pos, int32_t leadUnit) {
+    static inline int32_t readValue(const char16_t *pos, int32_t leadUnit) {
         int32_t value;
         if(leadUnit<kMinTwoUnitValueLead) {
             value=leadUnit;
@@ -390,7 +393,7 @@ private:
         }
         return value;
     }
-    static inline const UChar *skipValue(const UChar *pos, int32_t leadUnit) {
+    static inline const char16_t *skipValue(const char16_t *pos, int32_t leadUnit) {
         if(leadUnit>=kMinTwoUnitValueLead) {
             if(leadUnit<kThreeUnitValueLead) {
                 ++pos;
@@ -400,12 +403,12 @@ private:
         }
         return pos;
     }
-    static inline const UChar *skipValue(const UChar *pos) {
+    static inline const char16_t *skipValue(const char16_t *pos) {
         int32_t leadUnit=*pos++;
         return skipValue(pos, leadUnit&0x7fff);
     }
 
-    static inline int32_t readNodeValue(const UChar *pos, int32_t leadUnit) {
+    static inline int32_t readNodeValue(const char16_t *pos, int32_t leadUnit) {
         // U_ASSERT(kMinValueLead<=leadUnit && leadUnit<kValueIsFinal);
         int32_t value;
         if(leadUnit<kMinTwoUnitNodeValueLead) {
@@ -417,7 +420,7 @@ private:
         }
         return value;
     }
-    static inline const UChar *skipNodeValue(const UChar *pos, int32_t leadUnit) {
+    static inline const char16_t *skipNodeValue(const char16_t *pos, int32_t leadUnit) {
         // U_ASSERT(kMinValueLead<=leadUnit && leadUnit<kValueIsFinal);
         if(leadUnit>=kMinTwoUnitNodeValueLead) {
             if(leadUnit<kThreeUnitNodeValueLead) {
@@ -429,7 +432,7 @@ private:
         return pos;
     }
 
-    static inline const UChar *jumpByDelta(const UChar *pos) {
+    static inline const char16_t *jumpByDelta(const char16_t *pos) {
         int32_t delta=*pos++;
         if(delta>=kMinTwoUnitDeltaLead) {
             if(delta==kThreeUnitDeltaLead) {
@@ -442,7 +445,7 @@ private:
         return pos+delta;
     }
 
-    static const UChar *skipDelta(const UChar *pos) {
+    static const char16_t *skipDelta(const char16_t *pos) {
         int32_t delta=*pos++;
         if(delta>=kMinTwoUnitDeltaLead) {
             if(delta==kThreeUnitDeltaLead) {
@@ -459,28 +462,28 @@ private:
     }
 
     // Handles a branch node for both next(uchar) and next(string).
-    UStringTrieResult branchNext(const UChar *pos, int32_t length, int32_t uchar);
+    UStringTrieResult branchNext(const char16_t *pos, int32_t length, int32_t uchar);
 
     // Requires remainingLength_<0.
-    UStringTrieResult nextImpl(const UChar *pos, int32_t uchar);
+    UStringTrieResult nextImpl(const char16_t *pos, int32_t uchar);
 
     // Helper functions for hasUniqueValue().
     // Recursively finds a unique value (or whether there is not a unique one)
     // from a branch.
-    static const UChar *findUniqueValueFromBranch(const UChar *pos, int32_t length,
+    static const char16_t *findUniqueValueFromBranch(const char16_t *pos, int32_t length,
                                                   UBool haveUniqueValue, int32_t &uniqueValue);
     // Recursively finds a unique value (or whether there is not a unique one)
     // starting from a position on a node lead unit.
-    static UBool findUniqueValue(const UChar *pos, UBool haveUniqueValue, int32_t &uniqueValue);
+    static UBool findUniqueValue(const char16_t *pos, UBool haveUniqueValue, int32_t &uniqueValue);
 
     // Helper functions for getNextUChars().
     // getNextUChars() when pos is on a branch node.
-    static void getNextBranchUChars(const UChar *pos, int32_t length, Appendable &out);
+    static void getNextBranchUChars(const char16_t *pos, int32_t length, Appendable &out);
 
     // UCharsTrie data structure
     //
-    // The trie consists of a series of UChar-serialized nodes for incremental
-    // Unicode string/UChar sequence matching. (UChar=16-bit unsigned integer)
+    // The trie consists of a series of char16_t-serialized nodes for incremental
+    // Unicode string/char16_t sequence matching. (char16_t=16-bit unsigned integer)
     // The root node is at the beginning of the trie data.
     //
     // Types of nodes are distinguished by their node lead unit ranges.
@@ -489,9 +492,9 @@ private:
     //
     // Node types:
     //  - Final-value node: Stores a 32-bit integer in a compact, variable-length format.
-    //    The value is for the string/UChar sequence so far.
+    //    The value is for the string/char16_t sequence so far.
     //  - Match node, optionally with an intermediate value in a different compact format.
-    //    The value, if present, is for the string/UChar sequence so far.
+    //    The value, if present, is for the string/char16_t sequence so far.
     //
     //  Aside from the value, which uses the node lead unit's high bits:
     //
@@ -558,19 +561,20 @@ private:
 
     static const int32_t kMaxTwoUnitDelta=((kThreeUnitDeltaLead-kMinTwoUnitDeltaLead)<<16)-1;  // 0x03feffff
 
-    UChar *ownedArray_;
+    char16_t *ownedArray_;
 
     // Fixed value referencing the UCharsTrie words.
-    const UChar *uchars_;
+    const char16_t *uchars_;
 
     // Iterator variables.
 
     // Pointer to next trie unit to read. NULL if no more matches.
-    const UChar *pos_;
+    const char16_t *pos_;
     // Remaining length of a linear-match node, minus 1. Negative if not in such a node.
     int32_t remainingMatchLength_;
 };
 
 U_NAMESPACE_END
+#endif // U_SHOW_CPLUSPLUS_API
 
 #endif  // __UCHARSTRIE_H__