xref: /third_party/icu/icu4c/source/i18n/rbt.h (revision 2e5b6d6d)
12e5b6d6dSopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
22e5b6d6dSopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
32e5b6d6dSopenharmony_ci/*
42e5b6d6dSopenharmony_ci**********************************************************************
52e5b6d6dSopenharmony_ci*   Copyright (C) 1999-2007, International Business Machines
62e5b6d6dSopenharmony_ci*   Corporation and others.  All Rights Reserved.
72e5b6d6dSopenharmony_ci**********************************************************************
82e5b6d6dSopenharmony_ci*   Date        Name        Description
92e5b6d6dSopenharmony_ci*   11/17/99    aliu        Creation.
102e5b6d6dSopenharmony_ci**********************************************************************
112e5b6d6dSopenharmony_ci*/
122e5b6d6dSopenharmony_ci#ifndef RBT_H
132e5b6d6dSopenharmony_ci#define RBT_H
142e5b6d6dSopenharmony_ci
152e5b6d6dSopenharmony_ci#include "unicode/utypes.h"
162e5b6d6dSopenharmony_ci
172e5b6d6dSopenharmony_ci#if !UCONFIG_NO_TRANSLITERATION
182e5b6d6dSopenharmony_ci
192e5b6d6dSopenharmony_ci#include "unicode/translit.h"
202e5b6d6dSopenharmony_ci#include "unicode/utypes.h"
212e5b6d6dSopenharmony_ci#include "unicode/parseerr.h"
222e5b6d6dSopenharmony_ci#include "unicode/udata.h"
232e5b6d6dSopenharmony_ci
242e5b6d6dSopenharmony_ci#define U_ICUDATA_TRANSLIT U_ICUDATA_NAME U_TREE_SEPARATOR_STRING "translit"
252e5b6d6dSopenharmony_ci
262e5b6d6dSopenharmony_ciU_NAMESPACE_BEGIN
272e5b6d6dSopenharmony_ci
282e5b6d6dSopenharmony_ciclass TransliterationRuleData;
292e5b6d6dSopenharmony_ci
302e5b6d6dSopenharmony_ci/**
312e5b6d6dSopenharmony_ci * <code>RuleBasedTransliterator</code> is a transliterator
322e5b6d6dSopenharmony_ci * built from a set of rules as defined for
332e5b6d6dSopenharmony_ci * Transliterator::createFromRules().
342e5b6d6dSopenharmony_ci * See the C++ class Transliterator documentation for the rule syntax.
352e5b6d6dSopenharmony_ci *
362e5b6d6dSopenharmony_ci * @author Alan Liu
372e5b6d6dSopenharmony_ci * @internal Use transliterator factory methods instead since this class will be removed in that release.
382e5b6d6dSopenharmony_ci */
392e5b6d6dSopenharmony_ciclass RuleBasedTransliterator : public Transliterator {
402e5b6d6dSopenharmony_ciprivate:
412e5b6d6dSopenharmony_ci    /**
422e5b6d6dSopenharmony_ci     * The data object is immutable, so we can freely share it with
432e5b6d6dSopenharmony_ci     * other instances of RBT, as long as we do NOT own this object.
442e5b6d6dSopenharmony_ci     *  TODO:  data is no longer immutable.  See bugs #1866, 2155
452e5b6d6dSopenharmony_ci     */
462e5b6d6dSopenharmony_ci    TransliterationRuleData* fData;
472e5b6d6dSopenharmony_ci
482e5b6d6dSopenharmony_ci    /**
492e5b6d6dSopenharmony_ci     * If true, we own the data object and must delete it.
502e5b6d6dSopenharmony_ci     */
512e5b6d6dSopenharmony_ci    UBool isDataOwned;
522e5b6d6dSopenharmony_ci
532e5b6d6dSopenharmony_cipublic:
542e5b6d6dSopenharmony_ci
552e5b6d6dSopenharmony_ci    /**
562e5b6d6dSopenharmony_ci     * Constructs a new transliterator from the given rules.
572e5b6d6dSopenharmony_ci     * @param rules rules, separated by ';'
582e5b6d6dSopenharmony_ci     * @param direction either FORWARD or REVERSE.
592e5b6d6dSopenharmony_ci     * @exception IllegalArgumentException if rules are malformed.
602e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
612e5b6d6dSopenharmony_ci     */
622e5b6d6dSopenharmony_ci    RuleBasedTransliterator(const UnicodeString& id,
632e5b6d6dSopenharmony_ci                            const UnicodeString& rules,
642e5b6d6dSopenharmony_ci                            UTransDirection direction,
652e5b6d6dSopenharmony_ci                            UnicodeFilter* adoptedFilter,
662e5b6d6dSopenharmony_ci                            UParseError& parseError,
672e5b6d6dSopenharmony_ci                            UErrorCode& status);
682e5b6d6dSopenharmony_ci
692e5b6d6dSopenharmony_ci    /**
702e5b6d6dSopenharmony_ci     * Constructs a new transliterator from the given rules.
712e5b6d6dSopenharmony_ci     * @param rules rules, separated by ';'
722e5b6d6dSopenharmony_ci     * @param direction either FORWARD or REVERSE.
732e5b6d6dSopenharmony_ci     * @exception IllegalArgumentException if rules are malformed.
742e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
752e5b6d6dSopenharmony_ci     */
762e5b6d6dSopenharmony_ci    /*RuleBasedTransliterator(const UnicodeString& id,
772e5b6d6dSopenharmony_ci                            const UnicodeString& rules,
782e5b6d6dSopenharmony_ci                            UTransDirection direction,
792e5b6d6dSopenharmony_ci                            UnicodeFilter* adoptedFilter,
802e5b6d6dSopenharmony_ci                            UErrorCode& status);*/
812e5b6d6dSopenharmony_ci
822e5b6d6dSopenharmony_ci    /**
832e5b6d6dSopenharmony_ci     * Convenience constructor with no filter.
842e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
852e5b6d6dSopenharmony_ci     */
862e5b6d6dSopenharmony_ci    /*RuleBasedTransliterator(const UnicodeString& id,
872e5b6d6dSopenharmony_ci                            const UnicodeString& rules,
882e5b6d6dSopenharmony_ci                            UTransDirection direction,
892e5b6d6dSopenharmony_ci                            UErrorCode& status);*/
902e5b6d6dSopenharmony_ci
912e5b6d6dSopenharmony_ci    /**
922e5b6d6dSopenharmony_ci     * Convenience constructor with no filter and FORWARD direction.
932e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
942e5b6d6dSopenharmony_ci     */
952e5b6d6dSopenharmony_ci    /*RuleBasedTransliterator(const UnicodeString& id,
962e5b6d6dSopenharmony_ci                            const UnicodeString& rules,
972e5b6d6dSopenharmony_ci                            UErrorCode& status);*/
982e5b6d6dSopenharmony_ci
992e5b6d6dSopenharmony_ci    /**
1002e5b6d6dSopenharmony_ci     * Convenience constructor with FORWARD direction.
1012e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
1022e5b6d6dSopenharmony_ci     */
1032e5b6d6dSopenharmony_ci    /*RuleBasedTransliterator(const UnicodeString& id,
1042e5b6d6dSopenharmony_ci                            const UnicodeString& rules,
1052e5b6d6dSopenharmony_ci                            UnicodeFilter* adoptedFilter,
1062e5b6d6dSopenharmony_ci                            UErrorCode& status);*/
1072e5b6d6dSopenharmony_ciprivate:
1082e5b6d6dSopenharmony_ci
1092e5b6d6dSopenharmony_ci     friend class TransliteratorRegistry; // to access TransliterationRuleData convenience ctor
1102e5b6d6dSopenharmony_ci    /**
1112e5b6d6dSopenharmony_ci     * Convenience constructor.
1122e5b6d6dSopenharmony_ci     * @param id            the id for the transliterator.
1132e5b6d6dSopenharmony_ci     * @param theData       the rule data for the transliterator.
1142e5b6d6dSopenharmony_ci     * @param adoptedFilter the filter for the transliterator
1152e5b6d6dSopenharmony_ci     */
1162e5b6d6dSopenharmony_ci    RuleBasedTransliterator(const UnicodeString& id,
1172e5b6d6dSopenharmony_ci                            const TransliterationRuleData* theData,
1182e5b6d6dSopenharmony_ci                            UnicodeFilter* adoptedFilter = 0);
1192e5b6d6dSopenharmony_ci
1202e5b6d6dSopenharmony_ci
1212e5b6d6dSopenharmony_ci    friend class Transliterator; // to access following ct
1222e5b6d6dSopenharmony_ci
1232e5b6d6dSopenharmony_ci    /**
1242e5b6d6dSopenharmony_ci     * Internal constructor.
1252e5b6d6dSopenharmony_ci     * @param id            the id for the transliterator.
1262e5b6d6dSopenharmony_ci     * @param theData       the rule data for the transliterator.
1272e5b6d6dSopenharmony_ci     * @param isDataAdopted determine who will own the 'data' object. True, the caller should not delete 'data'.
1282e5b6d6dSopenharmony_ci     */
1292e5b6d6dSopenharmony_ci    RuleBasedTransliterator(const UnicodeString& id,
1302e5b6d6dSopenharmony_ci                            TransliterationRuleData* data,
1312e5b6d6dSopenharmony_ci                            UBool isDataAdopted);
1322e5b6d6dSopenharmony_ci
1332e5b6d6dSopenharmony_cipublic:
1342e5b6d6dSopenharmony_ci
1352e5b6d6dSopenharmony_ci    /**
1362e5b6d6dSopenharmony_ci     * Copy constructor.
1372e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
1382e5b6d6dSopenharmony_ci     */
1392e5b6d6dSopenharmony_ci    RuleBasedTransliterator(const RuleBasedTransliterator&);
1402e5b6d6dSopenharmony_ci
1412e5b6d6dSopenharmony_ci    virtual ~RuleBasedTransliterator();
1422e5b6d6dSopenharmony_ci
1432e5b6d6dSopenharmony_ci    /**
1442e5b6d6dSopenharmony_ci     * Implement Transliterator API.
1452e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
1462e5b6d6dSopenharmony_ci     */
1472e5b6d6dSopenharmony_ci    virtual RuleBasedTransliterator* clone() const override;
1482e5b6d6dSopenharmony_ci
1492e5b6d6dSopenharmony_ciprotected:
1502e5b6d6dSopenharmony_ci    /**
1512e5b6d6dSopenharmony_ci     * Implements {@link Transliterator#handleTransliterate}.
1522e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
1532e5b6d6dSopenharmony_ci     */
1542e5b6d6dSopenharmony_ci    virtual void handleTransliterate(Replaceable& text, UTransPosition& offsets,
1552e5b6d6dSopenharmony_ci                                     UBool isIncremental) const override;
1562e5b6d6dSopenharmony_ci
1572e5b6d6dSopenharmony_cipublic:
1582e5b6d6dSopenharmony_ci    /**
1592e5b6d6dSopenharmony_ci     * Return a representation of this transliterator as source rules.
1602e5b6d6dSopenharmony_ci     * These rules will produce an equivalent transliterator if used
1612e5b6d6dSopenharmony_ci     * to construct a new transliterator.
1622e5b6d6dSopenharmony_ci     * @param result the string to receive the rules.  Previous
1632e5b6d6dSopenharmony_ci     * contents will be deleted.
1642e5b6d6dSopenharmony_ci     * @param escapeUnprintable if true then convert unprintable
1652e5b6d6dSopenharmony_ci     * character to their hex escape representations, \uxxxx or
1662e5b6d6dSopenharmony_ci     * \Uxxxxxxxx.  Unprintable characters are those other than
1672e5b6d6dSopenharmony_ci     * U+000A, U+0020..U+007E.
1682e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
1692e5b6d6dSopenharmony_ci     */
1702e5b6d6dSopenharmony_ci    virtual UnicodeString& toRules(UnicodeString& result,
1712e5b6d6dSopenharmony_ci                                   UBool escapeUnprintable) const override;
1722e5b6d6dSopenharmony_ci
1732e5b6d6dSopenharmony_ciprotected:
1742e5b6d6dSopenharmony_ci    /**
1752e5b6d6dSopenharmony_ci     * Implement Transliterator framework
1762e5b6d6dSopenharmony_ci     */
1772e5b6d6dSopenharmony_ci    virtual void handleGetSourceSet(UnicodeSet& result) const override;
1782e5b6d6dSopenharmony_ci
1792e5b6d6dSopenharmony_cipublic:
1802e5b6d6dSopenharmony_ci    /**
1812e5b6d6dSopenharmony_ci     * Override Transliterator framework
1822e5b6d6dSopenharmony_ci     */
1832e5b6d6dSopenharmony_ci    virtual UnicodeSet& getTargetSet(UnicodeSet& result) const override;
1842e5b6d6dSopenharmony_ci
1852e5b6d6dSopenharmony_ci    /**
1862e5b6d6dSopenharmony_ci     * Return the class ID for this class.  This is useful only for
1872e5b6d6dSopenharmony_ci     * comparing to a return value from getDynamicClassID().  For example:
1882e5b6d6dSopenharmony_ci     * <pre>
1892e5b6d6dSopenharmony_ci     * .      Base* polymorphic_pointer = createPolymorphicObject();
1902e5b6d6dSopenharmony_ci     * .      if (polymorphic_pointer->getDynamicClassID() ==
1912e5b6d6dSopenharmony_ci     * .          Derived::getStaticClassID()) ...
1922e5b6d6dSopenharmony_ci     * </pre>
1932e5b6d6dSopenharmony_ci     * @return          The class ID for all objects of this class.
1942e5b6d6dSopenharmony_ci     * @internal Use transliterator factory methods instead since this class will be removed in that release.
1952e5b6d6dSopenharmony_ci     */
1962e5b6d6dSopenharmony_ci    U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
1972e5b6d6dSopenharmony_ci
1982e5b6d6dSopenharmony_ci    /**
1992e5b6d6dSopenharmony_ci     * Returns a unique class ID <b>polymorphically</b>.  This method
2002e5b6d6dSopenharmony_ci     * is to implement a simple version of RTTI, since not all C++
2012e5b6d6dSopenharmony_ci     * compilers support genuine RTTI.  Polymorphic operator==() and
2022e5b6d6dSopenharmony_ci     * clone() methods call this method.
2032e5b6d6dSopenharmony_ci     *
2042e5b6d6dSopenharmony_ci     * @return The class ID for this object. All objects of a given
2052e5b6d6dSopenharmony_ci     * class have the same class ID.  Objects of other classes have
2062e5b6d6dSopenharmony_ci     * different class IDs.
2072e5b6d6dSopenharmony_ci     */
2082e5b6d6dSopenharmony_ci    virtual UClassID getDynamicClassID(void) const override;
2092e5b6d6dSopenharmony_ci
2102e5b6d6dSopenharmony_ciprivate:
2112e5b6d6dSopenharmony_ci
2122e5b6d6dSopenharmony_ci    void _construct(const UnicodeString& rules,
2132e5b6d6dSopenharmony_ci                    UTransDirection direction,
2142e5b6d6dSopenharmony_ci                    UParseError& parseError,
2152e5b6d6dSopenharmony_ci                    UErrorCode& status);
2162e5b6d6dSopenharmony_ci};
2172e5b6d6dSopenharmony_ci
2182e5b6d6dSopenharmony_ci
2192e5b6d6dSopenharmony_ciU_NAMESPACE_END
2202e5b6d6dSopenharmony_ci
2212e5b6d6dSopenharmony_ci#endif /* #if !UCONFIG_NO_TRANSLITERATION */
2222e5b6d6dSopenharmony_ci
2232e5b6d6dSopenharmony_ci#endif
224