sl@0: /* sl@0: ********************************************************************** sl@0: * Copyright (c) 2000-2005, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: ********************************************************************** sl@0: * Date Name Description sl@0: * 02/04/00 aliu Creation. sl@0: ********************************************************************** sl@0: */ sl@0: #ifndef SYMTABLE_H sl@0: #define SYMTABLE_H sl@0: sl@0: #include "unicode/utypes.h" sl@0: #include "unicode/uobject.h" sl@0: sl@0: /** sl@0: * \file sl@0: * \brief C++ API: An interface that defines both lookup protocol and parsing of sl@0: * symbolic names. sl@0: */ sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: class ParsePosition; sl@0: class UnicodeFunctor; sl@0: class UnicodeSet; sl@0: class UnicodeString; sl@0: sl@0: /** sl@0: * An interface that defines both lookup protocol and parsing of sl@0: * symbolic names. sl@0: * sl@0: *

A symbol table maintains two kinds of mappings. The first is sl@0: * between symbolic names and their values. For example, if the sl@0: * variable with the name "start" is set to the value "alpha" sl@0: * (perhaps, though not necessarily, through an expression such as sl@0: * "$start=alpha"), then the call lookup("start") will return the sl@0: * char[] array ['a', 'l', 'p', 'h', 'a']. sl@0: * sl@0: *

The second kind of mapping is between character values and sl@0: * UnicodeMatcher objects. This is used by RuleBasedTransliterator, sl@0: * which uses characters in the private use area to represent objects sl@0: * such as UnicodeSets. If U+E015 is mapped to the UnicodeSet [a-z], sl@0: * then lookupMatcher(0xE015) will return the UnicodeSet [a-z]. sl@0: * sl@0: *

Finally, a symbol table defines parsing behavior for symbolic sl@0: * names. All symbolic names start with the SYMBOL_REF character. sl@0: * When a parser encounters this character, it calls parseReference() sl@0: * with the position immediately following the SYMBOL_REF. The symbol sl@0: * table parses the name, if there is one, and returns it. sl@0: * sl@0: * @stable ICU 2.8 sl@0: */ sl@0: class U_COMMON_API SymbolTable /* not : public UObject because this is an interface/mixin class */ { sl@0: public: sl@0: sl@0: /** sl@0: * The character preceding a symbol reference name. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: enum { SYMBOL_REF = 0x0024 /*$*/ }; sl@0: sl@0: /** sl@0: * Destructor. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: virtual ~SymbolTable(); sl@0: sl@0: /** sl@0: * Lookup the characters associated with this string and return it. sl@0: * Return NULL if no such name exists. The resultant sl@0: * string may have length zero. sl@0: * @param s the symbolic name to lookup sl@0: * @return a string containing the name's value, or NULL if sl@0: * there is no mapping for s. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: virtual const UnicodeString* lookup(const UnicodeString& s) const = 0; sl@0: sl@0: /** sl@0: * Lookup the UnicodeMatcher associated with the given character, and sl@0: * return it. Return NULL if not found. sl@0: * @param ch a 32-bit code point from 0 to 0x10FFFF inclusive. sl@0: * @return the UnicodeMatcher object represented by the given sl@0: * character, or NULL if there is no mapping for ch. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: virtual const UnicodeFunctor* lookupMatcher(UChar32 ch) const = 0; sl@0: sl@0: /** sl@0: * Parse a symbol reference name from the given string, starting sl@0: * at the given position. If no valid symbol reference name is sl@0: * found, return the empty string and leave pos unchanged. That is, if the sl@0: * character at pos cannot start a name, or if pos is at or after sl@0: * text.length(), then return an empty string. This indicates an sl@0: * isolated SYMBOL_REF character. sl@0: * @param text the text to parse for the name sl@0: * @param pos on entry, the index of the first character to parse. sl@0: * This is the character following the SYMBOL_REF character. On sl@0: * exit, the index after the last parsed character. If the parse sl@0: * failed, pos is unchanged on exit. sl@0: * @param limit the index after the last character to be parsed. sl@0: * @return the parsed name, or an empty string if there is no sl@0: * valid symbolic name at the given position. sl@0: * @stable ICU 2.8 sl@0: */ sl@0: virtual UnicodeString parseReference(const UnicodeString& text, sl@0: ParsePosition& pos, int32_t limit) const = 0; sl@0: }; sl@0: U_NAMESPACE_END sl@0: sl@0: #endif