Ejemplo n.º 1
0
void BlockStats::update(const QString& text, Dictionary* dictionary)
{
	// Calculate stats
	m_characters = text.length();
	m_spaces = 0;
	m_words = 0;
	bool word = false;
	QString::const_iterator end = text.constEnd();
	for (QString::const_iterator i = text.constBegin(); i != end; ++i) {
		if (i->isLetterOrNumber() || i->category() == QChar::Punctuation_Dash) {
			if (word == false) {
				word = true;
				m_words++;
			}
		} else if (i->isSpace()) {
			word = false;
			m_spaces++;
		} else if (*i != 0x2019 && *i != 0x0027) {
			word = false;
		}
	}

	// Update stored list of misspelled words
	checkSpelling(text, dictionary);
}
Ejemplo n.º 2
0
bool todosAscii(const QString& s)
{
    for (QString::const_iterator it = s.begin(); it != s.end(); ++it)
        if (it->unicode() > 127)
            return false;
    return true;
}
Ejemplo n.º 3
0
AnimExpression::Token AnimExpression::consumeNumber(const QString& str, QString::const_iterator& iter) const {
    assert(iter != str.end());
    assert(iter->isDigit());
    auto begin = iter;
    while (iter->isDigit() && iter != str.end()) {
        ++iter;
    }

    // parse whole integer part
    int pos = (int)(begin - str.begin());
    int len = (int)(iter - begin);
    QString sub = QStringRef(const_cast<const QString*>(&str), pos, len).toString();
    int whole = sub.toInt();

    // parse optional fractional part
    if (iter->unicode() == '.') {
        iter++;
        auto begin = iter;
        while (iter->isDigit() && iter != str.end()) {
            ++iter;
        }

        int pos = (int)(begin - str.begin());
        int len = (int)(iter - begin);
        QString sub = QStringRef(const_cast<const QString*>(&str), pos, len).toString();
        int fraction = sub.toInt();

        return Token(computeFloat(whole, fraction));

    } else {
        return Token(whole);
    }
}
Ejemplo n.º 4
0
bool isCorrectRules(const RulesMap &rules)
{
    QString key, val;
    //Для каждого правила
    for (RulesMap::const_iterator i = rules.constBegin(); i != rules.constEnd(); ++i){
        key = i.key();
        val = i.value();
        //Для каждого символа ключа
        for (QString::const_iterator j = key.constBegin(); j != key.constEnd(); ++j){
            if (j->isLetter()||*j == '`'){
                if (!((*j >= QChar('a') && *j <= QChar('z')) || *j == '`' || (*j >= QChar('A') && *j <= QChar('Z')))){
                    return false;
                }
            }
            else{
                return false;
            }
        }
        //Для каждого символа значения
        for (QString::const_iterator j = val.constBegin(); j != val.constEnd(); ++j){
            if (j->isLetter()){
                if (!((*j >= QChar(1040) && *j <= (1105)))){
                    return false;
                }
            }
            else{
                return false;
            }
        }
    }
    return true;
}
Ejemplo n.º 5
0
// Finds how many spaces the given string has at one end.
// direction=+1 -> left end of the string, -1 for right end.
int spacesAtCorner(const QString& string, int direction = +1) {
    int spaces = 0;
    QString::const_iterator it;
    for ( it = direction == 1 ? string.begin() : string.end()-1 ; it != string.end(); it += direction ) {
        if ( ! it->isSpace() ) break;
        spaces += 1;
    }
    return spaces;
}
Ejemplo n.º 6
0
bool isCorrectText(const QString &text)
{
    for (QString::const_iterator i = text.constBegin(); i != text.constEnd(); ++i){
        if (i->isLetter()){
            if (!((*i >= 'a' && *i <= 'z') || (*i >= 'A' && *i <= 'Z'))){
                return false;
            }
        }
    }
    return true;
}
Ejemplo n.º 7
0
AnimExpression::Token AnimExpression::consumeNot(const QString& str, QString::const_iterator& iter) const {
    assert(iter != str.end());
    assert(iter->unicode() == '!');
    iter++;
    if (iter->unicode() == '=') {
        iter++;
        return Token(Token::NotEqual);
    } else {
        return Token(Token::Not);
    }
}
Ejemplo n.º 8
0
AnimExpression::Token AnimExpression::consumeOr(const QString& str, QString::const_iterator& iter) const {
    assert(iter != str.end());
    assert(iter->unicode() == '|');
    iter++;
    if (iter->unicode() == '|') {
        iter++;
        return Token(Token::Or);
    } else {
        qCCritical(animation) << "AnimExpression: unexpected char" << *iter << "at index " << (int)(iter - str.begin());
        return Token(Token::Error);
    }
}
Ejemplo n.º 9
0
QByteArray RTF::Writer::fromUnicode(const QString& string) const
{
	QByteArray text;

	QByteArray encoded;
	QTextCodec::ConverterState state;
	state.flags = QTextCodec::ConvertInvalidToNull;

	QString::const_iterator end = string.constEnd();
	for (QString::const_iterator i = string.constBegin(); i != end; ++i) {
		switch (i->unicode()) {
		case '\t': text += "\\tab "; break;
		case '\\': text += "\\'5C"; break;
		case '{': text += "\\'7B"; break;
		case '}': text += "\\'7D"; break;
		case 0x00a0: text += "\\~"; break;
		case 0x00ad: text += "\\-"; break;
		case 0x00b7: text += "\\|"; break;
		case 0x2002: text += "\\enspace "; break;
		case 0x2003: text += "\\emspace "; break;
		case 0x2004: text += "\\qmspace "; break;
		case 0x200c: text += "\\zwnj "; break;
		case 0x200d: text += "\\zwj "; break;
		case 0x200e: text += "\\ltrmark "; break;
		case 0x200f: text += "\\rtlmark "; break;
		case 0x2011: text += "\\_"; break;
		case 0x2013: text += "\\endash "; break;
		case 0x2014: text += "\\emdash "; break;
		case 0x2018: text += "\\lquote "; break;
		case 0x2019: text += "\\rquote "; break;
		case 0x201c: text += "\\ldblquote "; break;
		case 0x201d: text += "\\rdblquote "; break;
		case 0x2022: text += "\\bullet "; break;
		default:
			encoded = m_codec->fromUnicode(i, 1, &state);
			if (state.invalidChars == 0) {
				if (encoded.count() == 1 && encoded.at(0) >= 0x20) {
					text += encoded;
				} else {
					for (int j = 0; j < encoded.count(); ++j) {
						text += "\\'" + QByteArray::number(static_cast<unsigned char>(encoded.at(j)), 16).toUpper();
					}
				}
			} else {
				text += "\\u" + QByteArray::number(i->unicode()) + "?";
			}
		}
	}

	return text;
}
Ejemplo n.º 10
0
QString GluonObject::nameToObjectName( const QString& name )
{
    // Sanitize the object name to be an acceptable javascript object name.
    // While this is also done by the scripting engine, we use the object name for other things
    // as well, such as filenames etc
    QString theObjectName;
    QString::const_iterator i;
    for( i = name.constBegin(); i != name.constEnd(); ++i )
    {
        if( i->isLetterOrNumber() || *i == '_' )
            theObjectName.append( *i );
    }
    return theObjectName;
}
Ejemplo n.º 11
0
            QDate fromYYYYMMDD (const QString& yyyymmdd) {
                if (yyyymmdd.length() != YYYYMMDD_FORMAT.length())
                    throw "Invalid input. Provide date as yyyyMMdd (e.g. June 2, 2016 = '20160602')";

                for (QString::const_iterator chr (yyyymmdd.begin()); chr != yyyymmdd.end(); chr++) {
                    if (!chr->isDigit())
                        throw "Non digit character in input string.";
                }

                const QDate result = QDate::fromString(yyyymmdd, YYYYMMDD_FORMAT);

                if (!result.isValid())
                    throw "Invalid date input";

                return result;
            }
Ejemplo n.º 12
0
static
ParseResult ParseDecimalPart(ParseResult const& begin, QString::const_iterator end)
{
	Amount multiplier ("0.1"); //exactly 1 tenth
	Amount decrement ("0.1"); //exactly 1 tenth
	Amount a = ResultAmount(begin);
	QString::const_iterator iter;
	for (iter = ResultIter(begin); iter != end; iter++) {
		if (iter->isDigit()) {
			a += Amount(iter->digitValue())*multiplier;
			multiplier *= decrement;
		} else {
			throw std::runtime_error("Invalid currency string");
		}
	}
	return ParseResult(a,iter);
}
Ejemplo n.º 13
0
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void elMundo::setRules (QString ruleString)
{
    QString::const_iterator it;
    int B_bitmask = 0, S_bitmask = 0;
    QString digits;
    if (reBrule.indexIn(ruleString) >= 0) {
        digits = reBrule.cap(1);
        for (it = digits.constBegin(); it != digits.constEnd(); it++)
            B_bitmask |= (1 << it->digitValue());
    }
    if (reSrule.indexIn(ruleString) >= 0) {
        digits = reSrule.cap(1);
        for (it = digits.constBegin(); it != digits.constEnd(); it++)
            S_bitmask |= (1 << it->digitValue());
    }
    fprintf(stderr,"Rules(%s=+%x:%x)\n", ruleString.cStr(), B_bitmask,S_bitmask);
    setRules(B_bitmask, S_bitmask);
}
Ejemplo n.º 14
0
AnimExpression::Token AnimExpression::consumeIdentifier(const QString& str, QString::const_iterator& iter) const {
    assert(iter != str.end());
    assert(iter->isLetter());
    auto begin = iter;
    while ((iter->isLetter() || iter->isDigit()) && iter != str.end()) {
        ++iter;
    }
    int pos = (int)(begin - str.begin());
    int len = (int)(iter - begin);

    QStringRef stringRef(const_cast<const QString*>(&str), pos, len);
    if (stringRef == "true") {
        return Token(true);
    } else if (stringRef == "false") {
        return Token(false);
    } else {
        return Token(stringRef);
    }
}
Ejemplo n.º 15
0
static
ParseResult ParseWholePart(QString::const_iterator begin, QString::const_iterator end)
{
	Amount a (0);
	QString::const_iterator iter;
	for (iter = begin; iter != end; iter++) {
		if (iter->isDigit()) {
			a *= Amount(10);					//scale up
			a = a + Amount(iter->digitValue()); //add
		} else if (*iter == QLocale().groupSeparator()) {
			//eat it
		} else if (*iter == QLocale().decimalPoint()) {
			iter++; //skip the decimal point
			return ParseResult(a, iter);
		} else {
			throw std::runtime_error("Invalid currency string");
		}
	}
	return ParseResult(a,iter);
}
Ejemplo n.º 16
0
void BlockStats::update(const QString& text)
{
	m_checked = Unchecked;
	m_characters = text.length();
	m_spaces = 0;
	m_words = 0;
	bool word = false;
	QString::const_iterator end = text.constEnd();
	for (QString::const_iterator i = text.constBegin(); i != end; ++i) {
		if (i->isLetterOrNumber() || i->category() == QChar::Punctuation_Dash) {
			if (word == false) {
				word = true;
				m_words++;
			}
		} else if (i->isSpace()) {
			word = false;
			m_spaces++;
		} else if (*i != 0x2019 && *i != 0x0027) {
			word = false;
		}
	}
}
Ejemplo n.º 17
0
AnimExpression::Token AnimExpression::consumeToken(const QString& str, QString::const_iterator& iter) const {
    if (!_tokenStack.empty()) {
        Token top = _tokenStack.top();
        _tokenStack.pop();
        return top;
    } else {
        while (iter != str.end()) {
            if (iter->isSpace()) {
                ++iter;
            } else if (iter->isLetter()) {
                return consumeIdentifier(str, iter);
            } else if (iter->isDigit()) {
                return consumeNumber(str, iter);
            } else {
                switch (iter->unicode()) {
                case '&': return consumeAnd(str, iter);
                case '|': return consumeOr(str, iter);
                case '>': return consumeGreaterThan(str, iter);
                case '<': return consumeLessThan(str, iter);
                case '(': ++iter; return Token(Token::LeftParen);
                case ')': ++iter; return Token(Token::RightParen);
                case '!': return consumeNot(str, iter);
                case '-': ++iter; return Token(Token::Minus);
                case '+': ++iter; return Token(Token::Plus);
                case '*': ++iter; return Token(Token::Multiply);
                case '/': ++iter; return Token(Token::Divide);
                case '%': ++iter; return Token(Token::Modulus);
                case ',': ++iter; return Token(Token::Comma);
                default:
                    qCCritical(animation) << "AnimExpression: unexpected char" << *iter << "at index " << (int)(iter - str.begin());
                    return Token(Token::Error);
                }
            }
        }
        return Token(Token::End);
    }
}
Ejemplo n.º 18
0
Arguments::Arguments( const QString &a ) 
{
    _arguments.clear();
    QString current_arg;
    bool between_arguments = false;
    bool quoted_argument = false;
    bool escape = false;
    for( QString::const_iterator itChar = a.begin(); itChar != a.end(); ++itChar )
    {
        if ( between_arguments )
        {
            switch ( itChar->toLatin1() )
            {
                case '"':
                    quoted_argument = true;
                    between_arguments = false;
                    current_arg.clear();
                    break;
                case ' ':
                case '\r':
                case '\n':
                case '\t':
                    break;
                default:
                    quoted_argument = false;
                    between_arguments = false;
                    current_arg = *itChar;
                    break;
            }
        }
        else
        {
            if ( escape )
            {
                escape = false;
                current_arg += *itChar;
            }
            else
            {
                switch ( itChar->toLatin1() )
                {
                    case '"':
                        quoted_argument = !quoted_argument;
                        break;
                    case ' ':
                    case '\r':
                    case '\n':
                    case '\t':
                        if ( quoted_argument )
                            current_arg += *itChar;
                        else
                        {
                            _arguments << current_arg;
                            between_arguments = true;
                        }
                        break;
                    case '\\':
                        escape = true ;
                        break;
                    default:
                        current_arg += *itChar;
                        break;
                }

            }
        }
    }
    if ( !between_arguments )
        _arguments << current_arg;
    calcArguments();
}
Ejemplo n.º 19
0
void SearchWorker::run() {
	while (1) {
		bar->search_mutex.lock();
		stop = false;
		if (die) {
			break;
		}
		// always clear results -> empty search == stop search
		emit clear_hits();

		// get search string
		bar->term_mutex.lock();
		if (bar->term.isEmpty()) {
			bar->term_mutex.unlock();
			emit update_label_text("done.");
			continue;
		}
		int start = bar->start_page;
		QString search_term = bar->term;
		forward = bar->forward;
		bar->term_mutex.unlock();

		// check if term contains upper case letters; if so, do case sensitive search (smartcase)
		bool has_upper_case = false;
		for (QString::const_iterator it = search_term.begin(); it != search_term.end(); ++it) {
			if (it->isUpper()) {
				has_upper_case = true;
				break;
			}
		}

#ifdef DEBUG
		cerr << "'" << search_term.toUtf8().constData() << "'" << endl;
#endif
		emit update_label_text(QString("[%1] 0\% searched, 0 hits")
			.arg(has_upper_case ? "Case" : "no case"));

		// search all pages
		int hit_count = 0;
		int page = start;
		do {
			Poppler::Page *p = bar->doc->page(page);
			if (p == NULL) {
				cerr << "failed to load page " << page << endl;
				continue;
			}

			// collect all occurrences
			QList<QRectF> *hits = new QList<QRectF>;
#if POPPLER_VERSION < POPPLER_VERSION_CHECK(0, 22, 0)
			// old search interface, slow for many hits per page
			double x = 0, y = 0, x2 = 0, y2 = 0;
			while (!stop && !die &&
					p->search(search_term, x, y, x2, y2, Poppler::Page::NextResult,
						has_upper_case ? Poppler::Page::CaseSensitive : Poppler::Page::CaseInsensitive)) {
				hits->push_back(QRectF(x, y, x2 - x, y2 - y));
			}
#elif POPPLER_VERSION < POPPLER_VERSION_CHECK(0, 31, 0)
			// new search interface
			QList<QRectF> tmp = p->search(search_term,
					has_upper_case ? Poppler::Page::CaseSensitive : Poppler::Page::CaseInsensitive);
			hits->swap(tmp);
#else
			// even newer interface
			QList<QRectF> tmp = p->search(search_term,
					has_upper_case ? (Poppler::Page::SearchFlags) 0 : Poppler::Page::IgnoreCase);
			// TODO support Poppler::Page::WholeWords
			hits->swap(tmp);
#endif
#ifdef DEBUG
			if (hits->size() > 0) {
				cerr << hits->size() << " hits on page " << page << endl;
			}
#endif
			delete p;

			// clean up when interrupted
			if (stop || die) {
				delete hits;
				break;
			}

			if (hits->size() > 0) {
				hit_count += hits->size();
				emit search_done(page, hits);
			} else {
				delete hits;
			}

			// update progress label next to the search bar
			int percent;
			if (forward) {
				percent = page + bar->doc->numPages() - start;
			} else {
				percent = start + bar->doc->numPages() - page;
			}
			percent = (percent % bar->doc->numPages()) * 100 / bar->doc->numPages();
			QString progress = QString("[%1] %2\% searched, %3 hits")
				.arg(has_upper_case ? "Case" : "no case")
				.arg(percent)
				.arg(hit_count);
			emit update_label_text(progress);

			if (forward) {
				if (++page == bar->doc->numPages()) {
					page = 0;
				}
			} else {
				if (--page == -1) {
					page = bar->doc->numPages() - 1;
				}
			}
		} while (page != start);
#ifdef DEBUG
		cerr << "done!" << endl;
#endif
		emit update_label_text(QString("[%1] done, %2 hits")
				.arg(has_upper_case ? "Case" : "no case")
				.arg(hit_count));
	}
}
static void skipSpaces( QString::const_iterator& itr, const QString::const_iterator& end)
{
	for (; itr != end && itr->isSpace(); ++itr) {}
}
Ejemplo n.º 21
0
// static
ChromaticKey KeyUtils::guessKeyFromText(const QString& text) {
    QString trimmed = text.trimmed();

    // Try using the user's custom notation.
    {
        QMutexLocker locker(&s_notationMutex);
        QMap<QString, ChromaticKey>::const_iterator it = s_reverseNotation.find(text);
        if (it != s_reverseNotation.end()) {
            return it.value();
        }
    }

    QRegExp openKeyMatcher(s_openKeyPattern, Qt::CaseInsensitive);
    if (openKeyMatcher.exactMatch(trimmed)) {
        bool ok = false;
        int openKeyNumber = openKeyMatcher.cap(1).toInt(&ok);

        // Regex should mean this never happens.
        if (!ok || openKeyNumber < 1 || openKeyNumber > 12) {
            return mixxx::track::io::key::INVALID;
        }

        bool major = openKeyMatcher.cap(2)
                .compare("d", Qt::CaseInsensitive) == 0;

        return openKeyNumberToKey(openKeyNumber, major);
    }

    QRegExp lancelotKeyMatcher(s_lancelotKeyPattern, Qt::CaseInsensitive);
    if (lancelotKeyMatcher.exactMatch(trimmed)) {
        bool ok = false;
        int lancelotNumber = lancelotKeyMatcher.cap(1).toInt(&ok);

        // Regex should mean this never happens.
        if (!ok || lancelotNumber < 1 || lancelotNumber > 12) {
            return mixxx::track::io::key::INVALID;
        }

        int openKeyNumber = lancelotNumberToOpenKeyNumber(lancelotNumber);

        bool major = lancelotKeyMatcher.cap(2)
                .compare("b", Qt::CaseInsensitive) == 0;

        return openKeyNumberToKey(openKeyNumber, major);
    }

    QRegExp keyMatcher(s_keyPattern, Qt::CaseInsensitive);
    if (keyMatcher.exactMatch(trimmed)) {
        // Take the first letter, lowercase it and subtract 'a' and we get a
        // number between 0-6. Look up the major key associated with that letter
        // from s_letterToMajorKey. Upper-case means major, lower-case means
        // minor. Then apply the sharps or flats to the key.
        QChar letter = keyMatcher.cap(1).at(0);
        int letterIndex = letter.toLower().toAscii() - 'a';
        bool major = letter.isUpper();

        // Now apply sharps and flats to the letter key.
        QString adjustments = keyMatcher.cap(2);
        int steps = 0;
        for (QString::const_iterator it = adjustments.begin();
             it != adjustments.end(); ++it) {
            // An m only comes at the end and
            if (it->toLower() == 'm') {
                major = false;
                break;
            }
            steps += (*it == '#' || *it == s_sharpSymbol[0]) ? 1 : -1;
        }

        ChromaticKey letterKey = static_cast<ChromaticKey>(
            s_letterToMajorKey[letterIndex] + (major ? 0 : 12));
        return scaleKeySteps(letterKey, steps);
    }

    // We didn't figure out the key. Womp womp.
    return mixxx::track::io::key::INVALID;
}
Ejemplo n.º 22
0
QString VisualLog::MessageInfo::expand(const QString &pattern) const{

    QString base = "";
    QDateTime dt = stamp();

    QString::const_iterator it = pattern.begin();
    while ( it != pattern.end() ){
        if ( *it == QChar('%') ){
            ++it;
            if ( it != pattern.end() ){
                char c = it->toLatin1();
                switch(c){
                case 'p': {
                    if ( m_location && !m_location->remote.isEmpty() )
                        base += m_location->remote + "> ";
                    base += QString().sprintf(
                        "%0*d-%0*d-%0*d %0*d:%0*d:%0*d.%0*d %s %s@%d: ",
                        4, dt.date().year(),
                        2, dt.date().month(),
                        2, dt.date().day(),
                        2, dt.time().hour(),
                        2, dt.time().minute(),
                        2, dt.time().second(),
                        3, dt.time().msec(),
                        qPrintable(levelToString(m_level).toLower()),
                        qPrintable(sourceFunctionName()),
                        sourceLineNumber()
                    );
                    break;
                }
                case 'r': base += sourceRemoteLocation(); break;
                case 'F': base += sourceFileName(); break;
                case 'N': base += extractFileNameSegment(sourceFileName()); break;
                case 'U': base += sourceFunctionName(); break;
                case 'L': base += QString::number(sourceLineNumber()); break;
                case 'V': base += levelToString(m_level); break;
                case 'v': base += levelToString(m_level).toLower(); break;
                case 'w': base += QDate::shortDayName(dt.date().dayOfWeek()); break;
                case 'W': base += QDate::longDayName(dt.date().dayOfWeek()); break;
                case 'b': base += QDate::shortMonthName(dt.date().month()); break;
                case 'B': base += QDate::longMonthName(dt.date().month()); break;
                case 'd': base += QString().sprintf("%0*d", 2, dt.date().day() ); break;
                case 'e': base += QString().sprintf("%d",      dt.date().day() ); break;
                case 'f': base += QString().sprintf("%*d",  2, dt.date().day() ); break;
                case 'm': base += QString().sprintf("%0*d", 2, dt.date().month() ); break;
                case 'n': base += QString().sprintf("%d",      dt.date().month() ); break;
                case 'o': base += QString().sprintf("%*d",  2, dt.date().month() ); break;
                case 'y': base += QString().sprintf("%0*d", 2, dt.date().year() % 100 ); break;
                case 'Y': base += QString().sprintf("%0*d", 4, dt.date().year() ); break;
                case 'H': base += QString().sprintf("%0*d", 2, dt.time().hour() ); break;
                case 'I': {
                    int hour = dt.time().hour();
                    base += QString().sprintf("%0*d", 2, (hour < 1 ? 12 : (hour > 12 ? hour - 12  : hour)));
                    break;
                }
                case 'a': base += QString().sprintf(dt.time().hour() < 12  ? "am" : "pm" ); break;
                case 'A': base += QString().sprintf(dt.time().hour() < 12  ? "AM" : "PM" ); break;
                case 'M': base += QString().sprintf("%0*d", 2, dt.time().minute()); break;
                case 'S': base += QString().sprintf("%0*d", 2, dt.time().second() ); break;
                case 's': base += QString().sprintf("%0*d.%0*d", 2, dt.time().second(), 3, dt.time().msec() ); break;
                case 'i': base += QString().sprintf("%0*d", 3, dt.time().msec() ); break;
                case 'c': base += QString().sprintf("%d",      dt.time().msec() / 100 ); break;
                default: base += *it;
                }
            }
        } else {
            base += *it;
        }
        ++it;
    }

    return base;
}
Ejemplo n.º 23
0
std::pair<TrieNode::Ptr,int> TrieNode::intersectF(
    const TrieNode::Ptr &v1, const TrieNode::Ptr &v2, int index1)
{
    typedef TrieNode::Ptr P;
    typedef QMap<QString,int>::const_iterator MapIterator;
    if (v1.isNull() || v2.isNull())
        return std::make_pair(P(0), ((v1.isNull()) ? 1 : 0) | ((v2.isNull()) ? 2 : 0));
    QString::const_iterator i = v1->prefix.constBegin()+index1, iEnd = v1->prefix.constEnd();
    QString::const_iterator j = v2->prefix.constBegin(), jEnd = v2->prefix.constEnd();
    while (i != iEnd && j != jEnd) {
        if (i->isSpace()) {
            if (! j->isSpace())
                break;
            do {
                ++j;
            } while (j != jEnd && j->isSpace());
            do {
                ++i;
            } while (i != iEnd && i->isSpace());
        } else {
            if (*i != *j)
                break;
            ++i;
            ++j;
        }
    }
    if (i == iEnd) {
        if (j == jEnd) {
            if (v1->postfixes.isEmpty() || v2->postfixes.isEmpty()) {
                if (v1->postfixes.isEmpty() && v2->postfixes.isEmpty())
                    return std::make_pair(v1, 3);
                foreach (P t1, v1->postfixes)
                    if (t1->prefix.isEmpty()) {
                        if (index1 == 0)
                            return std::make_pair(v2, 2);
                        else
                            return std::make_pair(TrieNode::create(
                                v1->prefix.left(index1).append(v2->prefix), v2->postfixes),0);
                    }
                foreach (P t2, v2->postfixes)
                    if (t2->prefix.isEmpty())
                        return std::make_pair(v1,1);
                return std::make_pair(P(0), 0);
            }
            QMap<QString,int> p1, p2;
            QList<P> p3;
            int ii = 0;
            foreach (P t1, v1->postfixes)
                p1[t1->prefix] = ii++;
            ii = 0;
            foreach (P t2, v2->postfixes)
                p2[t2->prefix] = ii++;
            MapIterator p1Ptr = p1.constBegin(), p2Ptr = p2.constBegin(),
                p1End = p1.constEnd(), p2End = p2.constEnd();
            int sameV1V2 = 3;
            while (p1Ptr != p1End && p2Ptr != p2End) {
                if (p1Ptr.key().isEmpty()) {
                    if (p2Ptr.key().isEmpty()) {
                        if (sameV1V2 == 0)
                            p3.append(v1->postfixes.at(p1Ptr.value()));
                        ++p1Ptr;
                        ++p2Ptr;
                    } else {
                        if (sameV1V2 == 1)
                            for (MapIterator p1I = p1.constBegin();p1I != p1Ptr; ++p1I)
                                p3.append(v1->postfixes.at(p1I.value()));
                        ++p1Ptr;
                        sameV1V2 &= 2;
                    }
                } else if (p2Ptr.key().isEmpty()) {
                    if (sameV1V2 == 2)
                        for (MapIterator p2I = p2.constBegin(); p2I != p2Ptr; ++p2I)
                                p3.append(v2->postfixes.at(p2I.value()));
                    ++p2Ptr;
                    sameV1V2 &= 1;
                } else {
                    QChar c1 = p1Ptr.key().at(0);
                    QChar c2 = p2Ptr.key().at(0);
                    if (c1 < c2) {
                        if (sameV1V2 == 1)
                            for (MapIterator p1I = p1.constBegin(); p1I != p1Ptr; ++p1I)
                                p3.append(v1->postfixes.at(p1I.value()));
                        ++p1Ptr;
                        sameV1V2 &= 2;
                    } else if (c1 > c2) {
                        if (sameV1V2 == 2)
                            for (MapIterator  p2I = p2.constBegin(); p2I != p2Ptr; ++p2I)
                                    p3.append(v2->postfixes.at(p2I. value()));
                        ++p2Ptr;
                        sameV1V2 &= 1;
                    } else {
                        std::pair<P,int> res = intersectF(v1->postfixes.at(p1Ptr.value()),
                            v2->postfixes.at(p2Ptr.value()));
                        if (sameV1V2 !=0 && (sameV1V2 & res.second) == 0) {
                            if ((sameV1V2 & 1) == 1)
                                for (MapIterator p1I = p1.constBegin(); p1I != p1Ptr; ++p1I)
                                    p3.append(v1->postfixes.at(p1I.value()));
                            if (sameV1V2 == 2)
                                for (MapIterator p2I = p2.constBegin(); p2I != p2Ptr; ++p2I)
                                    p3.append(v2->postfixes.at(p2I.value()));
                        }
                        sameV1V2 &= res.second;
                        if (sameV1V2 == 0 && !res.first.isNull())
                            p3.append(res.first);
                        ++p1Ptr;
                        ++p2Ptr;
                    }
                }
            }
            if (p1Ptr != p1End) {
                if (sameV1V2 == 1)
                    for (MapIterator p1I = p1.constBegin(); p1I != p1Ptr; ++p1I)
                        p3.append(v1->postfixes.at(p1I.value()));
                sameV1V2 &= 2;
            } else if (p2Ptr != p2End) {
                if (sameV1V2 == 2) {
                    for (MapIterator  p2I = p2.constBegin(); p2I != p2Ptr; ++p2I)
                        p3.append(v2->postfixes.at(p2I. value()));
                }
                sameV1V2 &= 1;
            }
            switch (sameV1V2) {
            case 0:
                if (p3.isEmpty())
                   return std::make_pair(P(0),0);
                else
                    return std::make_pair(TrieNode::create(v1->prefix,p3),0);
            case 2:
                if (index1 == 0)
                    return std::make_pair(v2,2);
                else
                    return std::make_pair(TrieNode::create(
                            v1->prefix.left(index1).append(v2->prefix), v2->postfixes), 0);
            default:
                return std::make_pair(v1,sameV1V2);
            }
        }
       // i == iEnd && j != jEnd
        foreach (const P &t1, v1->postfixes)
            if ((!t1->prefix.isEmpty()) && t1->prefix.at(0) == *j) {
                std::pair<P,int> res = intersectF(v2,t1,j-v2->prefix.constBegin());
                if (index1 == 0)
                    return std::make_pair(res.first, (((res.second & 1)==1) ? 2 : 0));
                else
                    return std::make_pair(TrieNode::create(
                        v1->prefix.left(index1).append(res.first->prefix),
                        res.first->postfixes), 0);
            }
        return std::make_pair(P(0), 0);
    } else {