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