jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ********************************************************************** jpayne@69: * Copyright (c) 2000-2005, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ********************************************************************** jpayne@69: * Date Name Description jpayne@69: * 02/04/00 aliu Creation. jpayne@69: ********************************************************************** jpayne@69: */ jpayne@69: #ifndef SYMTABLE_H jpayne@69: #define SYMTABLE_H jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: jpayne@69: #if U_SHOW_CPLUSPLUS_API jpayne@69: jpayne@69: #include "unicode/uobject.h" jpayne@69: jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C++ API: An interface that defines both lookup protocol and parsing of jpayne@69: * symbolic names. jpayne@69: */ jpayne@69: jpayne@69: U_NAMESPACE_BEGIN jpayne@69: jpayne@69: class ParsePosition; jpayne@69: class UnicodeFunctor; jpayne@69: class UnicodeSet; jpayne@69: class UnicodeString; jpayne@69: jpayne@69: /** jpayne@69: * An interface that defines both lookup protocol and parsing of jpayne@69: * symbolic names. jpayne@69: * jpayne@69: *
A symbol table maintains two kinds of mappings. The first is jpayne@69: * between symbolic names and their values. For example, if the jpayne@69: * variable with the name "start" is set to the value "alpha" jpayne@69: * (perhaps, though not necessarily, through an expression such as jpayne@69: * "$start=alpha"), then the call lookup("start") will return the jpayne@69: * char[] array ['a', 'l', 'p', 'h', 'a']. jpayne@69: * jpayne@69: *
The second kind of mapping is between character values and jpayne@69: * UnicodeMatcher objects. This is used by RuleBasedTransliterator, jpayne@69: * which uses characters in the private use area to represent objects jpayne@69: * such as UnicodeSets. If U+E015 is mapped to the UnicodeSet [a-z], jpayne@69: * then lookupMatcher(0xE015) will return the UnicodeSet [a-z]. jpayne@69: * jpayne@69: *
Finally, a symbol table defines parsing behavior for symbolic jpayne@69: * names. All symbolic names start with the SYMBOL_REF character. jpayne@69: * When a parser encounters this character, it calls parseReference() jpayne@69: * with the position immediately following the SYMBOL_REF. The symbol jpayne@69: * table parses the name, if there is one, and returns it. jpayne@69: * jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: class U_COMMON_API SymbolTable /* not : public UObject because this is an interface/mixin class */ { jpayne@69: public: jpayne@69: jpayne@69: /** jpayne@69: * The character preceding a symbol reference name. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: enum { SYMBOL_REF = 0x0024 /*$*/ }; jpayne@69: jpayne@69: /** jpayne@69: * Destructor. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: virtual ~SymbolTable(); jpayne@69: jpayne@69: /** jpayne@69: * Lookup the characters associated with this string and return it. jpayne@69: * Return NULL if no such name exists. The resultant jpayne@69: * string may have length zero. jpayne@69: * @param s the symbolic name to lookup jpayne@69: * @return a string containing the name's value, or NULL if jpayne@69: * there is no mapping for s. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: virtual const UnicodeString* lookup(const UnicodeString& s) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Lookup the UnicodeMatcher associated with the given character, and jpayne@69: * return it. Return NULL if not found. jpayne@69: * @param ch a 32-bit code point from 0 to 0x10FFFF inclusive. jpayne@69: * @return the UnicodeMatcher object represented by the given jpayne@69: * character, or NULL if there is no mapping for ch. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: virtual const UnicodeFunctor* lookupMatcher(UChar32 ch) const = 0; jpayne@69: jpayne@69: /** jpayne@69: * Parse a symbol reference name from the given string, starting jpayne@69: * at the given position. If no valid symbol reference name is jpayne@69: * found, return the empty string and leave pos unchanged. That is, if the jpayne@69: * character at pos cannot start a name, or if pos is at or after jpayne@69: * text.length(), then return an empty string. This indicates an jpayne@69: * isolated SYMBOL_REF character. jpayne@69: * @param text the text to parse for the name jpayne@69: * @param pos on entry, the index of the first character to parse. jpayne@69: * This is the character following the SYMBOL_REF character. On jpayne@69: * exit, the index after the last parsed character. If the parse jpayne@69: * failed, pos is unchanged on exit. jpayne@69: * @param limit the index after the last character to be parsed. jpayne@69: * @return the parsed name, or an empty string if there is no jpayne@69: * valid symbolic name at the given position. jpayne@69: * @stable ICU 2.8 jpayne@69: */ jpayne@69: virtual UnicodeString parseReference(const UnicodeString& text, jpayne@69: ParsePosition& pos, int32_t limit) const = 0; jpayne@69: }; jpayne@69: U_NAMESPACE_END jpayne@69: jpayne@69: #endif /* U_SHOW_CPLUSPLUS_API */ jpayne@69: jpayne@69: #endif