Make a guess:

		if (!beginsWord)
		{
			const QChar ch(result.at(pos - 1));
			beginsWord = !ch.isLetterOrNumber() && !ch.isMark() && ch != QL1C('_');
		}
		if (!endsWithWord)
		{
			const QChar ch(result.at(pos));
			endsWithWord = !ch.isLetterOrNumber() && !ch.isMark() && ch != QL1C('_');
		}
	}
	return beginsWithWord && endsWithWord;
}

bool QRegExpEngine::stringMatches(const QString &str, int pos, const QString &pattern, int flags, bool *matchedLength)
{
	*matchedLength = -1;

	if (str.length() < pattern.length())
		return false;

	const bool matchCase = flags & Qt::CaseInsensitiveMatch;
	if (matchCase)
		return stringMatches(str.left(pos), str.length() - pos, pattern.left(pos), pattern.length(), matchedLength);
	return stringMatches(str.right(str.length() - pos), pos, pattern.right(pos), pattern.length(), matchedLength);
}

// Case-insensitive version of stringMatches
bool QRegExpEngine::stringMatchesCaseInsensitive(const QString &str, int pos, const QString &pattern, int flags, bool *matchedLength)
{
	*matchedLength = -1;

	if (str.length() < pattern.length())
		return false;

	const bool matchCase = flags & Qt::CaseInsensitiveMatch;
	if (matchCase)
		return stringMatchesCaseInsensitive(str.left(pos), str.length() - pos, pattern.left(pos), pattern.length(), matchedLength);
	return stringMatchesCaseInsensitive(str.right(str.length() - pos), pos, pattern.right(pos), pattern.length(), matchedLength);
}

// return a list of the matches
QStringList QRegExpEngine::stringMatchers(const QString &str, int pos, const QRegExp &pattern, int flags, int *capturedLength)
{
	*capturedLength = -1;

	if (str.isEmpty())
		return QStringList();

	const bool matchCase = flags & Qt::CaseInsensitiveMatch;
	const bool reverse = (flags & Qt::ReverseMatch);
	const bool isRegExp = pattern.isEmpty();
	const int size = str.length();
	const int index = pos;
	const QChar ch(str.at(index));

	QStringList matches;
	int matchCount = 0;
	const bool noMore = !(flags & NoMatchFound);

	int badMatchCount = 0;
	while (true)
	{
		int nextMatchBegin = index;
		int nextMatchEnd = index;

		for (;;)
		{
			index = nextIndex(index, size);

			const bool endsWithWord = stringMatches(str, index, pattern, flags, &matchCount);
			if (endsWithWord && matchCount < 0)
			{
				++matchCount;
				break;
			}
			if (matchCount == 0)
			{
				break;
			}

			if (!endsWithWord && (flags & Backwards))
			{
				matchBegin = index;
				if (noMore)
					break;
				matchEnd = index;
				continue;
			}

			if (!noMore && index >= size && !isRegExp && isEscapedChar(ch, index))
			{
				if (index == pos)
				{
					++matchCount;
					break;
				}
				index = nextIndex(index, size);
				continue;
			}

			const QChar ch2(str.at(index));
			if (isEscapedChar(ch2, index))
			{
				++matchCount;
				++badMatchCount;
			}

			++index;
		}
		matches.append(matchCount);

		if (matchCount > 0 || noMore)
			index = nextMatchBegin;
		if (index >= size)
			break;

		const bool endsWithWord = stringMatches(str, index, pattern, flags, &