2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: Recognizer.C /main/1 1996/07/29 17:02:40 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
35 #include "Recognizer.h"
36 #include "InputSource.h"
39 namespace SP_NAMESPACE {
42 Recognizer::Recognizer(Trie *trie, const XcharMap<EquivCode> &map)
43 : trie_(trie), map_(map), multicode_(0)
47 Recognizer::Recognizer(Trie *trie, const XcharMap<EquivCode> &map,
48 Vector<Token> &suppressTokens)
49 : trie_(trie), map_(map), multicode_(1)
51 suppressTokens.swap(suppressTokens_);
54 Token Recognizer::recognize(InputSource *in, Messenger &mgr) const
58 if (in->scanSuppress())
59 return suppressTokens_[map_[in->tokenChar(mgr)]];
62 in->startTokenNoMulticode();
63 register const Trie *pos = trie_.pointer();
65 pos = pos->next(map_[in->tokenChar(mgr)]);
66 } while (pos->hasNext());
68 in->endToken(pos->tokenLength());
71 const BlankTrie *b = pos->blank();
72 const Trie *newPos = b;
73 size_t maxBlanks = b->maxBlanksToScan();
75 for (nBlanks = 0; nBlanks < maxBlanks; nBlanks++) {
76 EquivCode code = map_[in->tokenChar(mgr)];
77 if (!b->codeIsBlank(code)) {
78 if (newPos->hasNext())
79 newPos = newPos->next(code);
83 while (newPos->hasNext())
84 newPos = newPos->next(map_[in->tokenChar(mgr)]);
85 if (newPos->token() != 0) {
86 in->endToken(newPos->tokenLength() + b->additionalLength() + nBlanks);
87 return newPos->token();
90 in->endToken(pos->tokenLength() + (pos->includeBlanks() ? nBlanks : 0));