1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/unicode/symtable.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,112 @@ 1.4 +/* 1.5 +********************************************************************** 1.6 +* Copyright (c) 2000-2005, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +********************************************************************** 1.9 +* Date Name Description 1.10 +* 02/04/00 aliu Creation. 1.11 +********************************************************************** 1.12 +*/ 1.13 +#ifndef SYMTABLE_H 1.14 +#define SYMTABLE_H 1.15 + 1.16 +#include "unicode/utypes.h" 1.17 +#include "unicode/uobject.h" 1.18 + 1.19 +/** 1.20 + * \file 1.21 + * \brief C++ API: An interface that defines both lookup protocol and parsing of 1.22 + * symbolic names. 1.23 + */ 1.24 + 1.25 +U_NAMESPACE_BEGIN 1.26 + 1.27 +class ParsePosition; 1.28 +class UnicodeFunctor; 1.29 +class UnicodeSet; 1.30 +class UnicodeString; 1.31 + 1.32 +/** 1.33 + * An interface that defines both lookup protocol and parsing of 1.34 + * symbolic names. 1.35 + * 1.36 + * <p>A symbol table maintains two kinds of mappings. The first is 1.37 + * between symbolic names and their values. For example, if the 1.38 + * variable with the name "start" is set to the value "alpha" 1.39 + * (perhaps, though not necessarily, through an expression such as 1.40 + * "$start=alpha"), then the call lookup("start") will return the 1.41 + * char[] array ['a', 'l', 'p', 'h', 'a']. 1.42 + * 1.43 + * <p>The second kind of mapping is between character values and 1.44 + * UnicodeMatcher objects. This is used by RuleBasedTransliterator, 1.45 + * which uses characters in the private use area to represent objects 1.46 + * such as UnicodeSets. If U+E015 is mapped to the UnicodeSet [a-z], 1.47 + * then lookupMatcher(0xE015) will return the UnicodeSet [a-z]. 1.48 + * 1.49 + * <p>Finally, a symbol table defines parsing behavior for symbolic 1.50 + * names. All symbolic names start with the SYMBOL_REF character. 1.51 + * When a parser encounters this character, it calls parseReference() 1.52 + * with the position immediately following the SYMBOL_REF. The symbol 1.53 + * table parses the name, if there is one, and returns it. 1.54 + * 1.55 + * @stable ICU 2.8 1.56 + */ 1.57 +class U_COMMON_API SymbolTable /* not : public UObject because this is an interface/mixin class */ { 1.58 +public: 1.59 + 1.60 + /** 1.61 + * The character preceding a symbol reference name. 1.62 + * @stable ICU 2.8 1.63 + */ 1.64 + enum { SYMBOL_REF = 0x0024 /*$*/ }; 1.65 + 1.66 + /** 1.67 + * Destructor. 1.68 + * @stable ICU 2.8 1.69 + */ 1.70 + virtual ~SymbolTable(); 1.71 + 1.72 + /** 1.73 + * Lookup the characters associated with this string and return it. 1.74 + * Return <tt>NULL</tt> if no such name exists. The resultant 1.75 + * string may have length zero. 1.76 + * @param s the symbolic name to lookup 1.77 + * @return a string containing the name's value, or <tt>NULL</tt> if 1.78 + * there is no mapping for s. 1.79 + * @stable ICU 2.8 1.80 + */ 1.81 + virtual const UnicodeString* lookup(const UnicodeString& s) const = 0; 1.82 + 1.83 + /** 1.84 + * Lookup the UnicodeMatcher associated with the given character, and 1.85 + * return it. Return <tt>NULL</tt> if not found. 1.86 + * @param ch a 32-bit code point from 0 to 0x10FFFF inclusive. 1.87 + * @return the UnicodeMatcher object represented by the given 1.88 + * character, or NULL if there is no mapping for ch. 1.89 + * @stable ICU 2.8 1.90 + */ 1.91 + virtual const UnicodeFunctor* lookupMatcher(UChar32 ch) const = 0; 1.92 + 1.93 + /** 1.94 + * Parse a symbol reference name from the given string, starting 1.95 + * at the given position. If no valid symbol reference name is 1.96 + * found, return the empty string and leave pos unchanged. That is, if the 1.97 + * character at pos cannot start a name, or if pos is at or after 1.98 + * text.length(), then return an empty string. This indicates an 1.99 + * isolated SYMBOL_REF character. 1.100 + * @param text the text to parse for the name 1.101 + * @param pos on entry, the index of the first character to parse. 1.102 + * This is the character following the SYMBOL_REF character. On 1.103 + * exit, the index after the last parsed character. If the parse 1.104 + * failed, pos is unchanged on exit. 1.105 + * @param limit the index after the last character to be parsed. 1.106 + * @return the parsed name, or an empty string if there is no 1.107 + * valid symbolic name at the given position. 1.108 + * @stable ICU 2.8 1.109 + */ 1.110 + virtual UnicodeString parseReference(const UnicodeString& text, 1.111 + ParsePosition& pos, int32_t limit) const = 0; 1.112 +}; 1.113 +U_NAMESPACE_END 1.114 + 1.115 +#endif