symtable.h 4.3 KB

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