예제 #1
0
/** @short Take the initial text and mark it as a quotation */
QStringList quoteText(QStringList inputLines)
{
    QStringList quote;
    for (QStringList::iterator line = inputLines.begin(); line != inputLines.end(); ++line) {
        if (UiUtils::signatureSeparator().match(*line).hasMatch()) {
            // This is the signature separator, we should not include anything below that in the quote
            break;
        }
        // rewrap - we need to keep the quotes at < 79 chars, yet the grow with every level
        if (line->length() < 79-2) {
            // this line is short enough, prepend quote mark and continue
            if (line->isEmpty() || line->at(0) == QLatin1Char('>'))
                line->prepend(QLatin1Char('>'));
            else
                line->prepend(QLatin1String("> "));
            quote << *line;
            continue;
        }
        // long line -> needs to be wrapped
        // 1st, detect the quote depth and eventually stript the quotes from the line
        int quoteLevel = 0;
        int contentStart = 0;
        if (line->at(0) == QLatin1Char('>')) {
            quoteLevel = 1;
            while (quoteLevel < line->length() && line->at(quoteLevel) == QLatin1Char('>'))
                ++quoteLevel;
            contentStart = quoteLevel;
            if (quoteLevel < line->length() && line->at(quoteLevel) == QLatin1Char(' '))
                ++contentStart;
        }

        // 2nd, build a quote string
        QString quotemarks;
        for (int i = 0; i < quoteLevel; ++i)
            quotemarks += QLatin1Char('>');
        quotemarks += QLatin1String("> ");

        // 3rd, wrap the line, prepend the quotemarks to each line and add it to the quote text
        int space(contentStart), lastSpace(contentStart), pos(contentStart), length(0);
        while (pos < line->length()) {
            if (line->at(pos) == QLatin1Char(' '))
                space = pos+1;
            ++length;
            if (length > 65-quotemarks.length() && space != lastSpace) {
                // wrap
                quote << quotemarks + line->mid(lastSpace, space - lastSpace);
                lastSpace = space;
                length = pos - space;
            }
            ++pos;
        }
        quote << quotemarks + line->mid(lastSpace);
    }
    return quote;
}
예제 #2
0
QStringList::iterator
CLArgsPrivate::hasOutputToken(QString& indexStr)
{
    QString outputLong( QString::fromUtf8("--output") );
    QString outputShort( QString::fromUtf8("-o") );

    for (QStringList::iterator it = args.begin(); it != args.end(); ++it) {
        int indexOf = it->indexOf(outputLong);
        if (indexOf != -1) {
            indexOf += outputLong.size();
            if ( indexOf < it->size() ) {
                indexStr = it->mid(indexOf);
                bool ok;
                indexStr.toInt(&ok);
                if (!ok) {
                    error = 1;
                    std::cout << QObject::tr("Wrong formating for the -o option").toStdString() << std::endl;

                    return args.end();
                }
            } else {
                indexStr = QChar::fromLatin1('1');
            }

            return it;
        } else {
            indexOf = it->indexOf(outputShort);
            if (indexOf != -1) {
                if ( (it->size() > 2) && !it->at(2).isDigit() ) {
                    //This is probably the --onload option
                    return args.end();
                }
                indexOf += outputShort.size();
                if ( indexOf < it->size() ) {
                    indexStr = it->mid(indexOf);
                    bool ok;
                    indexStr.toInt(&ok);
                    if (!ok) {
                        error = 1;
                        std::cout << QObject::tr("Wrong formating for the -o option").toStdString() << std::endl;

                        return args.end();
                    }
                } else {
                    indexStr = QChar::fromLatin1('1');
                }

                return it;
            }
        }
    }

    return args.end();
} // CLArgsPrivate::hasOutputToken
bool PathManager::CheckSysEnvironment()
{
	QString javaHome = QString("");
	QStringList environment = QProcess::systemEnvironment();

	for (QStringList::iterator ite = environment.begin(); ite != environment.end(); ite++)
	{
		if (ite->toLower().startsWith("path=")){
			QStringList pathValueList = ite->mid(QString("path=").length()).split(";");
			for (QStringList::iterator ite = pathValueList.begin(); ite != pathValueList.end(); ite++)
			{
				QString path = ite->toLower();
				if (path.contains("java") && path.contains("bin")){
					SetJdkPath(ite->replace("\\", "/"));
					break;
				}
			}
			continue;
		}
		else if (ite->toLower().startsWith("java_home")){
			javaHome = *ite;
		}
	}

	if (JDKPATH.isEmpty()){
		BjMessageBox::warning(NULL, QStringLiteral("jdk环境变量错误"), QStringLiteral("在系统环境变量中未发现jdk路径,请先设置jdk环境变量,如果已经设置jdk环境变量,请在设置中指定其位置!"), QMessageBox::Ok, QMessageBox::NoButton);
		return false;
	}
	else if (javaHome.isEmpty()){
		BjMessageBox::warning(NULL, QStringLiteral("java_home环境变量错误"), QStringLiteral("在系统环境变量中未发现java_home环境变量,请先设置java_home环境变量!"), QMessageBox::Ok, QMessageBox::NoButton);
		return false;
	}
	return true;
}
예제 #4
0
std::vector<size_t> LineEditDialog::getSelectedIndeces(QStringList list)
{
	std::vector<size_t> indexList;
	for (QStringList::iterator it = list.begin(); it != list.end(); ++it)
	{
		QString s = it->mid(5, it->indexOf("  ") - 5);
		indexList.push_back(atoi(s.toStdString().c_str()));
	}
	return indexList;
}
static QString takeProgIdArgument(QStringList &args)
{
    // if the arguments contain an option in the form "ProgId=...", find it and consume it
    QStringList::iterator it = std::find_if (args.begin(), args.end(), StartsWithProgId());
    if (it == args.end())
        return QString();

    const QString progId = it->mid(QString::fromLatin1("ProgId=").size());
    args.erase(it);
    return progId;
}
예제 #6
0
bool MercurialClient::parentRevisionsSync(const QString &workingDirectory,
                                          const QString &file /* = QString() */,
                                          const QString &revision,
                                          QStringList *parents)
{
    parents->clear();
    QStringList args;
    args << QLatin1String("parents") <<  QLatin1String("-r") <<revision;
    if (!file.isEmpty())
        args << file;
    QByteArray outputData;
    if (!vcsFullySynchronousExec(workingDirectory, args, &outputData))
        return false;
    QString output = QString::fromLocal8Bit(outputData);
    output.remove(QLatin1Char('\r'));
    /* Looks like: \code
changeset:   0:031a48610fba
user: ...
\endcode   */
    // Obtain first line and split by blank-delimited tokens
    VCSBase::VCSBaseOutputWindow *outputWindow = VCSBase::VCSBaseOutputWindow::instance();
    const QStringList lines = output.split(QLatin1Char('\n'));
    if (lines.size() < 1) {
        outputWindow->appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(output)));
        return false;
    }
    QStringList changeSets = lines.front().simplified().split(QLatin1Char(' '));
    if (changeSets.size() < 2) {
        outputWindow->appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(output)));
        return false;
    }
    // Remove revision numbers
    const QChar colon = QLatin1Char(':');
    const QStringList::iterator end = changeSets.end();
    QStringList::iterator it = changeSets.begin();
    for (++it; it != end; ++it) {
        const int colonIndex = it->indexOf(colon);
        if (colonIndex != -1)
            parents->push_back(it->mid(colonIndex + 1));
    }
    return true;
}
예제 #7
0
QString CallTipsList::stripWhiteSpace(const QString& str) const
{
    QString stripped = str;
    QStringList lines = str.split(QLatin1String("\n"));
    int minspace=INT_MAX;
    int line=0;
    for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) {
        if (it->count() > 0 && line > 0) {
            int space = 0;
            for (int i=0; i<it->count(); i++) {
                if ((*it)[i] == QLatin1Char('\t'))
                    space++;
                else
                    break;
            }

            if (it->count() > space)
                minspace = std::min<int>(minspace, space);
        }
    }

    // remove all leading tabs from each line
    if (minspace > 0 && minspace < INT_MAX) {
        int line=0;
        QStringList strippedlines;
        for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) {
            if (line == 0 && !it->isEmpty()) {
                strippedlines << *it;
            }
            else if (it->count() > 0 && line > 0) {
                strippedlines << it->mid(minspace);
            }
        }

        stripped = strippedlines.join(QLatin1String("\n"));
    }

    return stripped;
}
예제 #8
0
QStringList MercurialClient::parentRevisionsSync(const QString &workingDirectory,
                                          const QString &file /* = QString() */,
                                          const QString &revision)
{
    QStringList parents;
    QStringList args;
    args << QLatin1String("parents") <<  QLatin1String("-r") <<revision;
    if (!file.isEmpty())
        args << file;
    const SynchronousProcessResponse resp = vcsFullySynchronousExec(workingDirectory, args);
    if (resp.result != SynchronousProcessResponse::Finished)
        return QStringList();
    /* Looks like: \code
changeset:   0:031a48610fba
user: ...
\endcode   */
    // Obtain first line and split by blank-delimited tokens
    const QStringList lines = resp.stdOut().split(QLatin1Char('\n'));
    if (lines.size() < 1) {
        VcsOutputWindow::appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(resp.stdOut())));
        return QStringList();
    }
    QStringList changeSets = lines.front().simplified().split(QLatin1Char(' '));
    if (changeSets.size() < 2) {
        VcsOutputWindow::appendSilently(msgParentRevisionFailed(workingDirectory, revision, msgParseParentsOutputFailed(resp.stdOut())));
        return QStringList();
    }
    // Remove revision numbers
    const QChar colon = QLatin1Char(':');
    const QStringList::iterator end = changeSets.end();
    QStringList::iterator it = changeSets.begin();
    for (++it; it != end; ++it) {
        const int colonIndex = it->indexOf(colon);
        if (colonIndex != -1)
            parents.push_back(it->mid(colonIndex + 1));
    }
    return parents;
}
예제 #9
0
void synaxErrorJudger::generateCondition()
{
	int begin = sqlExp.indexOf("where") + 5;
	int end = sqlExp.indexOf(QRegExp(";$")) - 1;
	QStringList conditions = sqlExp.mid(begin, end - begin + 1).split("and");
	QStringList::iterator it;
	pair<int, size_t> dataType;
	int logicType;
	string rightSide, leftSide;
	for (it = conditions.begin(); it != conditions.end(); ++it) {	
		*it = it->trimmed();
		if (*it == "") {
			throw QString("Synax Error: Conditions' format is incorrect.");
		}
		int begin = 0;
		int end = it->indexOf(QRegExp("[=><]"))-1;
		rightSide = it->mid(begin, end - begin + 1).trimmed().toStdString();
		begin = end + 1;
		end = it->indexOf(QRegExp("[=><]"), begin + 1);
		if (end - begin > 1 || end == -1) { //如果下一个"=",">","<"号出现在较远处
			end = begin; //说明这个逻辑关系是"=",">","<"而非">=", "<=", "<>" 
		}
		logicType = condition::getLogicTypeFromStr(it->mid(begin, end - begin + 1).toStdString());
		if (logicType == _ERROR) {
			throw QString("Synax Error: The logic arithemtic is invalid.");
		}
		bool ok;
		*it = it->mid(end + 1).trimmed();
		if (it->indexOf(QRegExp("^'")) != -1) { //引号'应该是字符或字符串
			it->remove(0, 1).remove(QRegExp("'$"));
			size_t len = it->size();
			pair<int, size_t> dType;
			Api::cManager.getAttributeDataType(*tblName, rightSide, dType);
			if (len < 1 || len > 255 || len > dType.second) {
				throw QString("Synax Error: The length of string is overflow.");
			}
			else if (len == 1) {
				dataType = pair<int, size_t>(_CHAR, sizeof(char));
			}
			else {
				dataType = pair<int, size_t>(_STRING, dType.second * sizeof(char));
			}
		}
		else if (it->indexOf('.') != -1) { //有小数点且不是字符串,应该是float
			it->toFloat(&ok);
			if (!ok) {
				;
			}
			else {
				dataType = pair<int, size_t>(_FLOAT, sizeof(float));
			}
		}
		else { //剩下的应该是int类型
			it->toInt(&ok);
			if (!ok) {
				;
			}
			else {
				dataType = pair<int, size_t>(_INT, sizeof(int));
			}
		}
		leftSide = it->toStdString();
		if (cond == 0) {
			cond = new vector<condition>;
		}
		cond->push_back(condition(rightSide, logicType, dataType, leftSide));
	}
}
예제 #10
0
QString MessageView::quoteText() const
{
    if (const AbstractPartWidget *w = dynamic_cast<const AbstractPartWidget *>(viewer)) {
        QStringList quote;
        QStringList lines = w->quoteMe().split('\n');
        for (QStringList::iterator line = lines.begin(); line != lines.end(); ++line) {
            if (Composer::Util::signatureSeparator().exactMatch(*line)) {
                // This is the signature separator, we should not include anything below that in the quote
                break;
            }
            // rewrap - we need to keep the quotes at < 79 chars, yet the grow with every level
            if (line->length() < 79-2) {
                // this line is short enough, prepend quote mark and continue
                if (line->isEmpty() || line->at(0) == '>')
                    line->prepend(">");
                else
                    line->prepend("> ");
                quote << *line;
                continue;
            }
            // long line -> needs to be wrapped
            // 1st, detect the quote depth and eventually stript the quotes from the line
            int quoteLevel = 0;
            int contentStart = 0;
            if (line->at(0) == '>') {
                quoteLevel = 1;
                while (quoteLevel < line->length() && line->at(quoteLevel) == '>')
                    ++quoteLevel;
                contentStart = quoteLevel;
                if (quoteLevel < line->length() && line->at(quoteLevel) == ' ')
                    ++contentStart;
            }

            // 2nd, build a qute string
            QString quotemarks;
            for (int i = 0; i < quoteLevel; ++i)
                quotemarks += ">";
            quotemarks += "> ";

            // 3rd, wrap the line, prepend the quotemarks to each line and add it to the quote text
            int space(contentStart), lastSpace(contentStart), pos(contentStart), length(0);
            while (pos < line->length()) {
                if (line->at(pos) == ' ')
                    space = pos+1;
                ++length;
                if (length > 65-quotemarks.length() && space != lastSpace) {
                    // wrap
                    quote << quotemarks + line->mid(lastSpace, space - lastSpace);
                    lastSpace = space;
                    length = pos - space;
                }
                ++pos;
            }
            quote << quotemarks + line->mid(lastSpace);
        }
        const Imap::Message::Envelope &e = message.data(Imap::Mailbox::RoleMessageEnvelope).value<Imap::Message::Envelope>();
        QString sender;
        if (!e.from.isEmpty())
            sender = e.from[0].prettyName(Imap::Message::MailAddress::FORMAT_JUST_NAME);
        if (e.from.isEmpty())
            sender = tr("you");

        // One extra newline at the end of the quoted text to separate the response
        quote << QString();

        return tr("On %1, %2 wrote:\n").arg(e.date.toLocalTime().toString(Qt::SystemLocaleLongDate)).arg(sender) + quote.join("\n");
    }
    return QString();
}
예제 #11
0
bool TWScript::doParseHeader(const QString& beginComment, const QString& endComment,
							 const QString& Comment, bool skipEmpty /* = true */)
{
	QFile file(m_Filename);
	QStringList lines;
	QString line;
	bool codecChanged = true;
	bool success = false;
	QTextCodec* codec;

	if (!file.exists() || !file.open(QIODevice::ReadOnly))
		return false;
	
	m_Codec = QTextCodec::codecForName("UTF-8");
	if (!m_Codec)
		m_Codec = QTextCodec::codecForLocale();

	while (codecChanged) {
		codec = m_Codec;
		file.seek(0);
		lines = codec->toUnicode(file.readAll()).split(QRegExp("\r\n|[\n\r]"));
	
		// skip any empty lines
		if (skipEmpty) {
			while (!lines.isEmpty() && lines.first().isEmpty())
				lines.removeFirst();
		}
		if (lines.isEmpty())
			break;
	
		// is this a valid TW script?
		line = lines.takeFirst();
		if (!beginComment.isEmpty()) {
			if (!line.startsWith(beginComment))
				break;
			line = line.mid(beginComment.size()).trimmed();
		}
		else if (!Comment.isEmpty()) {
			if (!line.startsWith(Comment))
				break;
			line = line.mid(Comment.size()).trimmed();
		}
		if (!line.startsWith("TeXworksScript"))
			break;
	
		// scan to find the extent of the header lines
		QStringList::iterator i;
		for (i = lines.begin(); i != lines.end(); ++i) {
			// have we reached the end?
			if (skipEmpty && i->isEmpty()) {
				i = lines.erase(i);
				--i;
				continue;
			}
			if (!endComment.isEmpty()) {
				if (i->startsWith(endComment))
					break;
			}
			if (!i->startsWith(Comment))
				break;
			*i = i->mid(Comment.size()).trimmed();
		}
		lines.erase(i, lines.end());
		
		codecChanged = false;
		switch (doParseHeader(lines)) {
			case ParseHeader_OK:
				success = true;
				break;
			case ParseHeader_Failed:
				success = false;
				break;
			case ParseHeader_CodecChanged:
				codecChanged = true;
				break;
		}
	}
	
	file.close();
	return success;
}