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