intl/icu/source/common/unicode/ucharstriebuilder.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2 *******************************************************************************
     3 *   Copyright (C) 2010-2013, International Business Machines
     4 *   Corporation and others.  All Rights Reserved.
     5 *******************************************************************************
     6 *   file name:  ucharstriebuilder.h
     7 *   encoding:   US-ASCII
     8 *   tab size:   8 (not used)
     9 *   indentation:4
    10 *
    11 *   created on: 2010nov14
    12 *   created by: Markus W. Scherer
    13 */
    15 #ifndef __UCHARSTRIEBUILDER_H__
    16 #define __UCHARSTRIEBUILDER_H__
    18 #include "unicode/utypes.h"
    19 #include "unicode/stringtriebuilder.h"
    20 #include "unicode/ucharstrie.h"
    21 #include "unicode/unistr.h"
    23 /**
    24  * \file
    25  * \brief C++ API: Builder for icu::UCharsTrie
    26  */
    28 U_NAMESPACE_BEGIN
    30 class UCharsTrieElement;
    32 /**
    33  * Builder class for UCharsTrie.
    34  *
    35  * This class is not intended for public subclassing.
    36  * @stable ICU 4.8
    37  */
    38 class U_COMMON_API UCharsTrieBuilder : public StringTrieBuilder {
    39 public:
    40     /**
    41      * Constructs an empty builder.
    42      * @param errorCode Standard ICU error code.
    43      * @stable ICU 4.8
    44      */
    45     UCharsTrieBuilder(UErrorCode &errorCode);
    47     /**
    48      * Destructor.
    49      * @stable ICU 4.8
    50      */
    51     virtual ~UCharsTrieBuilder();
    53     /**
    54      * Adds a (string, value) pair.
    55      * The string must be unique.
    56      * The string contents will be copied; the builder does not keep
    57      * a reference to the input UnicodeString or its buffer.
    58      * @param s The input string.
    59      * @param value The value associated with this string.
    60      * @param errorCode Standard ICU error code. Its input value must
    61      *                  pass the U_SUCCESS() test, or else the function returns
    62      *                  immediately. Check for U_FAILURE() on output or use with
    63      *                  function chaining. (See User Guide for details.)
    64      * @return *this
    65      * @stable ICU 4.8
    66      */
    67     UCharsTrieBuilder &add(const UnicodeString &s, int32_t value, UErrorCode &errorCode);
    69     /**
    70      * Builds a UCharsTrie for the add()ed data.
    71      * Once built, no further data can be add()ed until clear() is called.
    72      *
    73      * A UCharsTrie cannot be empty. At least one (string, value) pair
    74      * must have been add()ed.
    75      *
    76      * This method passes ownership of the builder's internal result array to the new trie object.
    77      * Another call to any build() variant will re-serialize the trie.
    78      * After clear() has been called, a new array will be used as well.
    79      * @param buildOption Build option, see UStringTrieBuildOption.
    80      * @param errorCode Standard ICU error code. Its input value must
    81      *                  pass the U_SUCCESS() test, or else the function returns
    82      *                  immediately. Check for U_FAILURE() on output or use with
    83      *                  function chaining. (See User Guide for details.)
    84      * @return A new UCharsTrie for the add()ed data.
    85      * @stable ICU 4.8
    86      */
    87     UCharsTrie *build(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
    89     /**
    90      * Builds a UCharsTrie for the add()ed data and UChar-serializes it.
    91      * Once built, no further data can be add()ed until clear() is called.
    92      *
    93      * A UCharsTrie cannot be empty. At least one (string, value) pair
    94      * must have been add()ed.
    95      *
    96      * Multiple calls to buildUnicodeString() set the UnicodeStrings to the
    97      * builder's same UChar array, without rebuilding.
    98      * If buildUnicodeString() is called after build(), the trie will be
    99      * re-serialized into a new array.
   100      * If build() is called after buildUnicodeString(), the trie object will become
   101      * the owner of the previously returned array.
   102      * After clear() has been called, a new array will be used as well.
   103      * @param buildOption Build option, see UStringTrieBuildOption.
   104      * @param result A UnicodeString which will be set to the UChar-serialized
   105      *               UCharsTrie for the add()ed data.
   106      * @param errorCode Standard ICU error code. Its input value must
   107      *                  pass the U_SUCCESS() test, or else the function returns
   108      *                  immediately. Check for U_FAILURE() on output or use with
   109      *                  function chaining. (See User Guide for details.)
   110      * @return result
   111      * @stable ICU 4.8
   112      */
   113     UnicodeString &buildUnicodeString(UStringTrieBuildOption buildOption, UnicodeString &result,
   114                                       UErrorCode &errorCode);
   116     /**
   117      * Removes all (string, value) pairs.
   118      * New data can then be add()ed and a new trie can be built.
   119      * @return *this
   120      * @stable ICU 4.8
   121      */
   122     UCharsTrieBuilder &clear() {
   123         strings.remove();
   124         elementsLength=0;
   125         ucharsLength=0;
   126         return *this;
   127     }
   129 private:
   130     UCharsTrieBuilder(const UCharsTrieBuilder &other);  // no copy constructor
   131     UCharsTrieBuilder &operator=(const UCharsTrieBuilder &other);  // no assignment operator
   133     void buildUChars(UStringTrieBuildOption buildOption, UErrorCode &errorCode);
   135     virtual int32_t getElementStringLength(int32_t i) const;
   136     virtual UChar getElementUnit(int32_t i, int32_t unitIndex) const;
   137     virtual int32_t getElementValue(int32_t i) const;
   139     virtual int32_t getLimitOfLinearMatch(int32_t first, int32_t last, int32_t unitIndex) const;
   141     virtual int32_t countElementUnits(int32_t start, int32_t limit, int32_t unitIndex) const;
   142     virtual int32_t skipElementsBySomeUnits(int32_t i, int32_t unitIndex, int32_t count) const;
   143     virtual int32_t indexOfElementWithNextUnit(int32_t i, int32_t unitIndex, UChar unit) const;
   145     virtual UBool matchNodesCanHaveValues() const { return TRUE; }
   147     virtual int32_t getMaxBranchLinearSubNodeLength() const { return UCharsTrie::kMaxBranchLinearSubNodeLength; }
   148     virtual int32_t getMinLinearMatch() const { return UCharsTrie::kMinLinearMatch; }
   149     virtual int32_t getMaxLinearMatchLength() const { return UCharsTrie::kMaxLinearMatchLength; }
   151 #ifndef U_HIDE_INTERNAL_API
   152     class UCTLinearMatchNode : public LinearMatchNode {
   153     public:
   154         UCTLinearMatchNode(const UChar *units, int32_t len, Node *nextNode);
   155         virtual UBool operator==(const Node &other) const;
   156         virtual void write(StringTrieBuilder &builder);
   157     private:
   158         const UChar *s;
   159     };
   160 #endif
   162     virtual Node *createLinearMatchNode(int32_t i, int32_t unitIndex, int32_t length,
   163                                         Node *nextNode) const;
   165     UBool ensureCapacity(int32_t length);
   166     virtual int32_t write(int32_t unit);
   167     int32_t write(const UChar *s, int32_t length);
   168     virtual int32_t writeElementUnits(int32_t i, int32_t unitIndex, int32_t length);
   169     virtual int32_t writeValueAndFinal(int32_t i, UBool isFinal);
   170     virtual int32_t writeValueAndType(UBool hasValue, int32_t value, int32_t node);
   171     virtual int32_t writeDeltaTo(int32_t jumpTarget);
   173     UnicodeString strings;
   174     UCharsTrieElement *elements;
   175     int32_t elementsCapacity;
   176     int32_t elementsLength;
   178     // UChar serialization of the trie.
   179     // Grows from the back: ucharsLength measures from the end of the buffer!
   180     UChar *uchars;
   181     int32_t ucharsCapacity;
   182     int32_t ucharsLength;
   183 };
   185 U_NAMESPACE_END
   187 #endif  // __UCHARSTRIEBUILDER_H__

mercurial