Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ********************************************************************** |
michael@0 | 3 | * Copyright (c) 2000-2005, International Business Machines |
michael@0 | 4 | * Corporation and others. All Rights Reserved. |
michael@0 | 5 | ********************************************************************** |
michael@0 | 6 | * Date Name Description |
michael@0 | 7 | * 02/04/00 aliu Creation. |
michael@0 | 8 | ********************************************************************** |
michael@0 | 9 | */ |
michael@0 | 10 | #ifndef SYMTABLE_H |
michael@0 | 11 | #define SYMTABLE_H |
michael@0 | 12 | |
michael@0 | 13 | #include "unicode/utypes.h" |
michael@0 | 14 | #include "unicode/uobject.h" |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * \file |
michael@0 | 18 | * \brief C++ API: An interface that defines both lookup protocol and parsing of |
michael@0 | 19 | * symbolic names. |
michael@0 | 20 | */ |
michael@0 | 21 | |
michael@0 | 22 | U_NAMESPACE_BEGIN |
michael@0 | 23 | |
michael@0 | 24 | class ParsePosition; |
michael@0 | 25 | class UnicodeFunctor; |
michael@0 | 26 | class UnicodeSet; |
michael@0 | 27 | class UnicodeString; |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * An interface that defines both lookup protocol and parsing of |
michael@0 | 31 | * symbolic names. |
michael@0 | 32 | * |
michael@0 | 33 | * <p>A symbol table maintains two kinds of mappings. The first is |
michael@0 | 34 | * between symbolic names and their values. For example, if the |
michael@0 | 35 | * variable with the name "start" is set to the value "alpha" |
michael@0 | 36 | * (perhaps, though not necessarily, through an expression such as |
michael@0 | 37 | * "$start=alpha"), then the call lookup("start") will return the |
michael@0 | 38 | * char[] array ['a', 'l', 'p', 'h', 'a']. |
michael@0 | 39 | * |
michael@0 | 40 | * <p>The second kind of mapping is between character values and |
michael@0 | 41 | * UnicodeMatcher objects. This is used by RuleBasedTransliterator, |
michael@0 | 42 | * which uses characters in the private use area to represent objects |
michael@0 | 43 | * such as UnicodeSets. If U+E015 is mapped to the UnicodeSet [a-z], |
michael@0 | 44 | * then lookupMatcher(0xE015) will return the UnicodeSet [a-z]. |
michael@0 | 45 | * |
michael@0 | 46 | * <p>Finally, a symbol table defines parsing behavior for symbolic |
michael@0 | 47 | * names. All symbolic names start with the SYMBOL_REF character. |
michael@0 | 48 | * When a parser encounters this character, it calls parseReference() |
michael@0 | 49 | * with the position immediately following the SYMBOL_REF. The symbol |
michael@0 | 50 | * table parses the name, if there is one, and returns it. |
michael@0 | 51 | * |
michael@0 | 52 | * @stable ICU 2.8 |
michael@0 | 53 | */ |
michael@0 | 54 | class U_COMMON_API SymbolTable /* not : public UObject because this is an interface/mixin class */ { |
michael@0 | 55 | public: |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * The character preceding a symbol reference name. |
michael@0 | 59 | * @stable ICU 2.8 |
michael@0 | 60 | */ |
michael@0 | 61 | enum { SYMBOL_REF = 0x0024 /*$*/ }; |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * Destructor. |
michael@0 | 65 | * @stable ICU 2.8 |
michael@0 | 66 | */ |
michael@0 | 67 | virtual ~SymbolTable(); |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * Lookup the characters associated with this string and return it. |
michael@0 | 71 | * Return <tt>NULL</tt> if no such name exists. The resultant |
michael@0 | 72 | * string may have length zero. |
michael@0 | 73 | * @param s the symbolic name to lookup |
michael@0 | 74 | * @return a string containing the name's value, or <tt>NULL</tt> if |
michael@0 | 75 | * there is no mapping for s. |
michael@0 | 76 | * @stable ICU 2.8 |
michael@0 | 77 | */ |
michael@0 | 78 | virtual const UnicodeString* lookup(const UnicodeString& s) const = 0; |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Lookup the UnicodeMatcher associated with the given character, and |
michael@0 | 82 | * return it. Return <tt>NULL</tt> if not found. |
michael@0 | 83 | * @param ch a 32-bit code point from 0 to 0x10FFFF inclusive. |
michael@0 | 84 | * @return the UnicodeMatcher object represented by the given |
michael@0 | 85 | * character, or NULL if there is no mapping for ch. |
michael@0 | 86 | * @stable ICU 2.8 |
michael@0 | 87 | */ |
michael@0 | 88 | virtual const UnicodeFunctor* lookupMatcher(UChar32 ch) const = 0; |
michael@0 | 89 | |
michael@0 | 90 | /** |
michael@0 | 91 | * Parse a symbol reference name from the given string, starting |
michael@0 | 92 | * at the given position. If no valid symbol reference name is |
michael@0 | 93 | * found, return the empty string and leave pos unchanged. That is, if the |
michael@0 | 94 | * character at pos cannot start a name, or if pos is at or after |
michael@0 | 95 | * text.length(), then return an empty string. This indicates an |
michael@0 | 96 | * isolated SYMBOL_REF character. |
michael@0 | 97 | * @param text the text to parse for the name |
michael@0 | 98 | * @param pos on entry, the index of the first character to parse. |
michael@0 | 99 | * This is the character following the SYMBOL_REF character. On |
michael@0 | 100 | * exit, the index after the last parsed character. If the parse |
michael@0 | 101 | * failed, pos is unchanged on exit. |
michael@0 | 102 | * @param limit the index after the last character to be parsed. |
michael@0 | 103 | * @return the parsed name, or an empty string if there is no |
michael@0 | 104 | * valid symbolic name at the given position. |
michael@0 | 105 | * @stable ICU 2.8 |
michael@0 | 106 | */ |
michael@0 | 107 | virtual UnicodeString parseReference(const UnicodeString& text, |
michael@0 | 108 | ParsePosition& pos, int32_t limit) const = 0; |
michael@0 | 109 | }; |
michael@0 | 110 | U_NAMESPACE_END |
michael@0 | 111 | |
michael@0 | 112 | #endif |