TrieBuilder.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: TrieBuilder.h /main/1 1996/07/29 17:06:48 cde-hp $ */
  24. // Copyright (c) 1994 James Clark
  25. // See the file COPYING for copying permission.
  26. #ifndef TrieBuilder_INCLUDED
  27. #define TrieBuilder_INCLUDED 1
  28. #ifdef __GNUG__
  29. #pragma interface
  30. #endif
  31. #include "types.h"
  32. #include "StringOf.h"
  33. #include "Owner.h"
  34. #include "Trie.h"
  35. #include "Vector.h"
  36. #ifdef SP_NAMESPACE
  37. namespace SP_NAMESPACE {
  38. #endif
  39. class TrieBuilder {
  40. public:
  41. typedef Vector<Token> TokenVector;
  42. TrieBuilder(int nCodes);
  43. void recognize(const String<EquivCode> &chars,
  44. Token t,
  45. Priority::Type pri,
  46. TokenVector &ambiguities);
  47. void recognize(const String<EquivCode> &chars,
  48. const String<EquivCode> &set,
  49. Token t,
  50. Priority::Type pri,
  51. TokenVector &ambiguities);
  52. // recognize a delimiter with a blank sequence
  53. void recognizeB(const String<EquivCode> &chars,
  54. int bSequenceLength, // >= 1
  55. size_t maxBlankSequenceLength,
  56. const String<EquivCode> &blankCodes,
  57. const String<EquivCode> &chars2,
  58. Token t,
  59. TokenVector &ambiguities);
  60. void recognizeEE(EquivCode code, Token t);
  61. Trie *extractTrie() { return root_.extract(); }
  62. private:
  63. TrieBuilder(const TrieBuilder &); // undefined
  64. void operator=(const TrieBuilder &); // undefined
  65. void doB(Trie *trie,
  66. int tokenLength,
  67. int minBLength,
  68. size_t maxLength,
  69. const String<EquivCode> &blankCodes,
  70. const String<EquivCode> &chars2,
  71. Token token,
  72. Priority::Type pri,
  73. TokenVector &ambiguities);
  74. Trie *extendTrie(Trie *, const String<EquivCode> &);
  75. void setToken(Trie *trie, int tokenLength, Token token, Priority::Type pri,
  76. TokenVector &ambiguities);
  77. Trie *forceNext(Trie *trie, EquivCode);
  78. void copyInto(Trie *, const Trie *, int);
  79. int nCodes_;
  80. Owner<Trie> root_;
  81. };
  82. #ifdef SP_NAMESPACE
  83. }
  84. #endif
  85. #endif /* not TrieBuilder_INCLUDED */