symtable.h 4.2 KB

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