Ejemplo n.º 1
0
QStringList InputMatcher::choices(bool allowpartial, bool allowpredicted, const QString &prefix, const QString &suffix) const
{
    if (nsets.size() == 0)
	return QStringList();

    if (mLookup) {
	QStringList ch;
	uint minError;
	int pl = prefixLength(prefix);
	int sl = suffixLength(suffix);
	if (pl == -1 || sl == -1 || (pl + sl >= (int)nsets.size()))
	    return QStringList();
	ch = searchDict(allowpartial, allowpredicted, dict, extradict,
		pl, nsets.size()-sl, &minError);
	if ( lowerdict ) {
	    for (QStringList::Iterator i=ch.begin(); i!=ch.end(); ++i)
		*i = (*i).toLower();
	}
	QStringList::Iterator it;
	for (it = ch.begin(); it != ch.end(); ++it) {
	    *it = prefix + *it + suffix;
	}
	return ch;
    } else {
	return findAll(nsets.size()-longestEnd, nsets.size(), QString() );
    }
}
Ejemplo n.º 2
0
QString InputMatcher::findBest(const QString &prefix, const QString &suffix, bool isDigit) const
{
    int pl = prefixLength(prefix);
    int sl = suffixLength(suffix);
    if (pl == -1 || sl == -1 || (pl + sl >= (int)nsets.size()))
	return QString();
    QString nword = findBest(pl, nsets.size()-sl, isDigit);
    if (nword.isEmpty())
	return QString();
    else
	return prefix+nword+suffix;
}
Ejemplo n.º 3
0
/**
* Makes the jump table based on the scan offset which mismatch occurs.
*/
void BMStringMatch::makeOffsetTable(std::string& needle) {
  offsetTable.resize(needle.length(), 0);
  int lastPrefixPosition = needle.length();
  for (int i = needle.length() - 1; i >= 0; --i) {
    if (isPrefix(needle, i + 1)) {
      lastPrefixPosition = i + 1;
    }
    offsetTable[needle.length() - 1 - i] = lastPrefixPosition - i + needle.length() - 1;
  }
  for (int i = 0; i < (int)needle.length() - 1; ++i) {
    int slen = suffixLength(needle, i);
    offsetTable[slen] = needle.length() - 1 - i + slen;
  }
}
Ejemplo n.º 4
0
QStringList InputMatcher::findAll(const QString &prefix, const QString &suffix) const
{
    int pl = prefixLength(prefix);
    int sl = suffixLength(suffix); 
    QStringList ch;
    if (pl != -1 && sl != -1 && (pl + sl < (int)nsets.size())) {
	ch = findAll(pl, nsets.size()-sl, QString());
    }
    QStringList::Iterator it;
    for (it = ch.begin(); it != ch.end(); ++it) {
	*it = prefix + *it + suffix;
    }
    return ch;
}
Ejemplo n.º 5
0
int InputMatcher::suffixLength(const QString &p, int from) const
{
    if (from >= (int)nsets.size())
	return -1;
    if (p.isEmpty())
	return from;

    QChar c = p[p.length()-1];

    int i;
    for (i = (int)nsets.size()-1; i >= 0; --i) {
	const InputMatcherGuessList *g = nsets[i];
	InputMatcherGuessList::ConstIterator it = g->begin();
	while(it != g->end()) {
	    IMIGuess guess = *it;
	    if ((guess.length + i == (int)nsets.size() - from  )
		    && QChar(guess.c) == c && guess.length != 0)
		return suffixLength(p.left(p.length()-1),
			from + guess.length);
	    ++it;
	}
    }
    return -1;
}