symtable.h 4.1 KB

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