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