mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
98 lines
2.7 KiB
C
98 lines
2.7 KiB
C
/*
|
|
* CDE - Common Desktop Environment
|
|
*
|
|
* Copyright (c) 1993-2012, The Open Group. All rights reserved.
|
|
*
|
|
* These libraries and programs are free software; you can
|
|
* redistribute them and/or modify them under the terms of the GNU
|
|
* Lesser General Public License as published by the Free Software
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
* These libraries and programs are distributed in the hope that
|
|
* they will be useful, but WITHOUT ANY WARRANTY; without even the
|
|
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU Lesser General Public License for more
|
|
* details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with these libraries and programs; if not, write
|
|
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
|
* Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
/* $XConsortium: Recognizer.C /main/1 1996/07/29 17:02:40 cde-hp $ */
|
|
// Copyright (c) 1994 James Clark
|
|
// See the file COPYING for copying permission.
|
|
|
|
#ifdef __GNUG__
|
|
#pragma implementation
|
|
#endif
|
|
#include "splib.h"
|
|
#include "Resource.h"
|
|
#include "Trie.h"
|
|
#include "Owner.h"
|
|
#include "XcharMap.h"
|
|
#include "Recognizer.h"
|
|
#include "InputSource.h"
|
|
|
|
#ifdef SP_NAMESPACE
|
|
namespace SP_NAMESPACE {
|
|
#endif
|
|
|
|
Recognizer::Recognizer(Trie *trie, const XcharMap<EquivCode> &map)
|
|
: trie_(trie), map_(map), multicode_(0)
|
|
{
|
|
}
|
|
|
|
Recognizer::Recognizer(Trie *trie, const XcharMap<EquivCode> &map,
|
|
Vector<Token> &suppressTokens)
|
|
: trie_(trie), map_(map), multicode_(1)
|
|
{
|
|
suppressTokens.swap(suppressTokens_);
|
|
}
|
|
|
|
Token Recognizer::recognize(InputSource *in, Messenger &mgr) const
|
|
{
|
|
if (multicode_) {
|
|
in->startToken();
|
|
if (in->scanSuppress())
|
|
return suppressTokens_[map_[in->tokenChar(mgr)]];
|
|
}
|
|
else
|
|
in->startTokenNoMulticode();
|
|
const Trie *pos = trie_.pointer();
|
|
do {
|
|
pos = pos->next(map_[in->tokenChar(mgr)]);
|
|
} while (pos->hasNext());
|
|
if (!pos->blank()) {
|
|
in->endToken(pos->tokenLength());
|
|
return pos->token();
|
|
}
|
|
const BlankTrie *b = pos->blank();
|
|
const Trie *newPos = b;
|
|
size_t maxBlanks = b->maxBlanksToScan();
|
|
size_t nBlanks;
|
|
for (nBlanks = 0; nBlanks < maxBlanks; nBlanks++) {
|
|
EquivCode code = map_[in->tokenChar(mgr)];
|
|
if (!b->codeIsBlank(code)) {
|
|
if (newPos->hasNext())
|
|
newPos = newPos->next(code);
|
|
break;
|
|
}
|
|
}
|
|
while (newPos->hasNext())
|
|
newPos = newPos->next(map_[in->tokenChar(mgr)]);
|
|
if (newPos->token() != 0) {
|
|
in->endToken(newPos->tokenLength() + b->additionalLength() + nBlanks);
|
|
return newPos->token();
|
|
}
|
|
else {
|
|
in->endToken(pos->tokenLength() + (pos->includeBlanks() ? nBlanks : 0));
|
|
return pos->token();
|
|
}
|
|
}
|
|
|
|
|
|
#ifdef SP_NAMESPACE
|
|
}
|
|
#endif
|