Ejemplo n.º 1
0
inline void qx_save(Archive & ar, const QRegExp & t, const unsigned int file_version)
{
   Q_UNUSED(file_version);
   QString sPattern = t.pattern();
   int iCaseSensitivity = static_cast<int>(t.caseSensitivity());
   int iPatternSyntax = static_cast<int>(t.patternSyntax());
   bool bMinimal = t.isMinimal();

   ar << boost::serialization::make_nvp("pattern", sPattern);
   ar << boost::serialization::make_nvp("caseSensitivity", iCaseSensitivity);
   ar << boost::serialization::make_nvp("patternSyntax", iPatternSyntax);
   ar << boost::serialization::make_nvp("minimal", bMinimal);
}
Ejemplo n.º 2
0
void XMLUtility::write(QXmlStreamWriter& writer, const QRegExp& regExp, const QString& name)
{
  if (regExp.isEmpty() || !regExp.isValid() || name.length() == 0)
  {
    return;
  }

  writer.writeStartElement(name);
  writer.writeAttribute("IsMinimal", booleanToString(regExp.isMinimal()));
  writer.writeAttribute("CaseSensitive", caseToString(regExp.caseSensitivity()));
  writer.writeAttribute("PatternSyntax", getEnumMapper().PatternSyntaxToString(regExp.patternSyntax()));
  writer.writeCharacters(regExp.pattern());
  writer.writeEndElement();
}
Ejemplo n.º 3
0
// Converts a QRegExp to a JS RegExp.
// The conversion is not 100% exact since ECMA regexp and QRegExp
// have different semantics/flags, but we try to do our best.
Heap::RegExpObject::RegExpObject(const QRegExp &re)
{
    global = false;

    // Convert the pattern to a ECMAScript pattern.
    QString pattern = QT_PREPEND_NAMESPACE(qt_regexp_toCanonical)(re.pattern(), re.patternSyntax());
    if (re.isMinimal()) {
        QString ecmaPattern;
        int len = pattern.length();
        ecmaPattern.reserve(len);
        int i = 0;
        const QChar *wc = pattern.unicode();
        bool inBracket = false;
        while (i < len) {
            QChar c = wc[i++];
            ecmaPattern += c;
            switch (c.unicode()) {
            case '?':
            case '+':
            case '*':
            case '}':
                if (!inBracket)
                    ecmaPattern += QLatin1Char('?');
                break;
            case '\\':
                if (i < len)
                    ecmaPattern += wc[i++];
                break;
            case '[':
                inBracket = true;
                break;
            case ']':
                inBracket = false;
                break;
            default:
                break;
            }
        }
        pattern = ecmaPattern;
    }

    Scope scope(internalClass->engine);
    Scoped<QV4::RegExpObject> o(scope, this);

    o->d()->value = QV4::RegExp::create(scope.engine, pattern, re.caseSensitivity() == Qt::CaseInsensitive, false);

    o->initProperties();
}
Ejemplo n.º 4
0
void RegExp::newRegExp(QScriptValueImpl *result, const QRegExp &rx, int flags)
{
    Q_ASSERT(!(flags & IgnoreCase) || (rx.caseSensitivity() == Qt::CaseInsensitive));
    newRegExp_helper(result, rx, flags);
}
Ejemplo n.º 5
0
QString SyntaxHighlighter::identifyWordGroup(const QString &word, const QChar &lookahead_chr, int idx, int &match_idx, int &match_len)
{
	QRegExp expr;
	vector<QString>::iterator itr, itr_end;
	vector<QRegExp>::iterator itr_exp, itr_exp_end;
	vector<QRegExp> *vet_expr=nullptr;
	QString group;
	bool match=false, part_mach=false;
	MultiLineInfo *info=nullptr;

	//Try to get the multiline info for the current block
	info=getMultiLineInfo(idx, idx, current_block);

	/* Case the highlighter is in the middle of a multiline code block,
		 a different action is executed: check if the current word does not
		 matches with one of final expresion of the group indicating that the
		 group highlighting must be interrupted after the current word */
	if(info)
	{
		group=info->group;

		//Checking if the word is not a highlight ending for the group
		itr_exp=final_exprs[group].begin();
		itr_exp_end=final_exprs[group].end();
		part_mach=partial_match[group];

		while(itr_exp!=itr_exp_end && !match)
		{
			expr=(*itr_exp);

			if(part_mach)
			{
				match_idx=word.indexOf(expr);
				match_len=expr.matchedLength();
				match=(match_idx >= 0);
			}
			else
			{
				if(expr.patternSyntax()==QRegExp::FixedString)
					match=((expr.pattern().compare(word, expr.caseSensitivity())==0));
				else
					match=expr.exactMatch(word);

				if(match)
				{
					match_idx=0;
					match_len=word.length();
				}
			}

			if(match && lookahead_char.count(group) > 0 && lookahead_chr!=lookahead_char.at(group))
				match=false;

			itr_exp++;
		}

		/* If the word matches configures a multiline info with the
			 values retrieved from the regexp matching */
		if(match)
		{
			info->end_col=idx + match_idx + match_len-1;
			info->end_block=current_block;
		}
		else
		{
			match_idx=0;
			match_len=word.length();
		}

		return(group);
	}
	else
	{
		itr=groups_order.begin();
		itr_end=groups_order.end();

		while(itr!=itr_end && !match)
		{
			group=(*itr);
			vet_expr=&initial_exprs[group];
			itr++;

			itr_exp=vet_expr->begin();
			itr_exp_end=vet_expr->end();
			part_mach=partial_match[group];

			while(itr_exp!=itr_exp_end && !match)
			{
				expr=(*itr_exp);

				if(part_mach)
				{
					match_idx=word.indexOf(expr);
					match_len=expr.matchedLength();
					match=(match_idx >= 0);
				}
				else
				{
					if(expr.patternSyntax()==QRegExp::FixedString)
						match=((expr.pattern().compare(word, expr.caseSensitivity())==0));
					else
						match=expr.exactMatch(word);

					if(match)
					{
						match_idx=0;
						match_len=word.length();
					}
				}

				if(match && lookahead_char.count(group) > 0 && lookahead_chr!=lookahead_char.at(group))
					match=false;

				itr_exp++;
			}

			/* Case the word matches with one of group regexp check if this latter
				 has final expressions which indicates that the group treats multiline blocks.
				 This way alocates a info with the initial configurations */
			if(match && final_exprs.count(group))
			{
				if(!info)
				{
					info=new MultiLineInfo;
					info->group=group;
					info->start_col=idx + match_idx + match_len;
					info->start_block=current_block;
					multi_line_infos.push_back(info);
				}
			}
		}

		if(!match) group="";
		return(group);
	}
}
Ejemplo n.º 6
0
void MyMoneyReport::write(QDomElement& e, QDomDocument *doc, bool anonymous) const
{
  // No matter what changes, be sure to have a 'type' attribute.  Only change
  // the major type if it becomes impossible to maintain compatibility with
  // older versions of the program as new features are added to the reports.
  // Feel free to change the minor type every time a change is made here.

  writeBaseXML(*doc, e);

  if (anonymous) {
    e.setAttribute("name", m_id);
    e.setAttribute("comment", QString(m_comment).fill('x'));
  } else {
    e.setAttribute("name", m_name);
    e.setAttribute("comment", m_comment);
  }
  e.setAttribute("group", m_group);
  e.setAttribute("convertcurrency", m_convertCurrency);
  e.setAttribute("favorite", m_favorite);
  e.setAttribute("tax", m_tax);
  e.setAttribute("investments", m_investments);
  e.setAttribute("loans", m_loans);
  e.setAttribute("rowtype", kRowTypeText[m_rowType]);
  e.setAttribute("datelock", kDateLockText[m_dateLock]);
  e.setAttribute("includeschedules", m_includeSchedules);
  e.setAttribute("columnsaredays", m_columnsAreDays);
  e.setAttribute("includestransfers", m_includeTransfers);
  if (!m_budgetId.isEmpty())
    e.setAttribute("budget", m_budgetId);
  e.setAttribute("includesactuals", m_includeBudgetActuals);
  e.setAttribute("includeunused", m_includeUnusedAccounts);
  e.setAttribute("includesforecast", m_includeForecast);
  e.setAttribute("includesprice", m_includePrice);
  e.setAttribute("includesaverageprice", m_includeAveragePrice);
  e.setAttribute("mixedtime", m_mixedTime);
  e.setAttribute("includesmovingaverage", m_includeMovingAverage);
  if (m_includeMovingAverage)
    e.setAttribute("movingaveragedays", m_movingAverageDays);

  if (m_chartType < 0 || m_chartType >= kChartTypeText.size()) {
    qDebug("m_chartType out of bounds with %d on report of type %d. Default to none.", m_chartType, m_reportType);
    e.setAttribute("charttype", kChartTypeText[0]);
  } else {
    e.setAttribute("charttype", kChartTypeText[m_chartType]);
  }
  e.setAttribute("chartdatalabels", m_chartDataLabels);
  e.setAttribute("chartgridlines", m_chartGridLines);
  e.setAttribute("chartbydefault", m_chartByDefault);
  e.setAttribute("chartlinewidth", m_chartLineWidth);
  e.setAttribute("skipZero", m_skipZero);

  if (m_reportType == ePivotTable) {
    e.setAttribute("type", "pivottable 1.15");
    e.setAttribute("detail", kDetailLevelText[m_detailLevel]);
    e.setAttribute("columntype", kColumnTypeText[m_columnType]);
    e.setAttribute("showrowtotals", m_showRowTotals);
  } else if (m_reportType == eQueryTable) {
    e.setAttribute("type", "querytable 1.14");

    QStringList columns;
    unsigned qc = m_queryColumns;
    unsigned it_qc = eQCbegin;
    unsigned index = 1;
    while (it_qc != eQCend) {
      if (qc & it_qc)
        columns += kQueryColumnsText[index];
      it_qc *= 2;
      index++;
    }
    e.setAttribute("querycolumns", columns.join(","));
  } else if (m_reportType == eInfoTable) {
    e.setAttribute("type", "infotable 1.0");
    e.setAttribute("detail", kDetailLevelText[m_detailLevel]);
    e.setAttribute("showrowtotals", m_showRowTotals);
  }

  //
  // Text Filter
  //

  QRegExp textfilter;
  if (textFilter(textfilter)) {
    QDomElement f = doc->createElement("TEXT");
    f.setAttribute("pattern", textfilter.pattern());
    f.setAttribute("casesensitive", (textfilter.caseSensitivity() == Qt::CaseSensitive) ? 1 : 0);
    f.setAttribute("regex", (textfilter.patternSyntax() == QRegExp::Wildcard) ? 1 : 0);
    f.setAttribute("inverttext", m_invertText);
    e.appendChild(f);
  }

  //
  // Type & State Filters
  //
  QList<int> typelist;
  if (types(typelist) && ! typelist.empty()) {
    // iterate over payees, and add each one
    QList<int>::const_iterator it_type = typelist.constBegin();
    while (it_type != typelist.constEnd()) {
      QDomElement p = doc->createElement("TYPE");
      p.setAttribute("type", kTypeText[*it_type]);
      e.appendChild(p);

      ++it_type;
    }
  }

  QList<int> statelist;
  if (states(statelist) && ! statelist.empty()) {
    // iterate over payees, and add each one
    QList<int>::const_iterator it_state = statelist.constBegin();
    while (it_state != statelist.constEnd()) {
      QDomElement p = doc->createElement("STATE");
      p.setAttribute("state", kStateText[*it_state]);
      e.appendChild(p);

      ++it_state;
    }
  }
  //
  // Number Filter
  //

  QString nrFrom, nrTo;
  if (numberFilter(nrFrom, nrTo)) {
    QDomElement f = doc->createElement("NUMBER");
    f.setAttribute("from", nrFrom);
    f.setAttribute("to", nrTo);
    e.appendChild(f);
  }

  //
  // Amount Filter
  //

  MyMoneyMoney from, to;
  if (amountFilter(from, to)) {    // bool getAmountFilter(MyMoneyMoney&,MyMoneyMoney&);
    QDomElement f = doc->createElement("AMOUNT");
    f.setAttribute("from", from.toString());
    f.setAttribute("to", to.toString());
    e.appendChild(f);
  }

  //
  // Payees Filter
  //

  QStringList payeelist;
  if (payees(payeelist)) {
    if (payeelist.empty()) {
      QDomElement p = doc->createElement("PAYEE");
      e.appendChild(p);
    } else {
      // iterate over payees, and add each one
      QStringList::const_iterator it_payee = payeelist.constBegin();
      while (it_payee != payeelist.constEnd()) {
        QDomElement p = doc->createElement("PAYEE");
        p.setAttribute("id", *it_payee);
        e.appendChild(p);

        ++it_payee;
      }
    }
  }

  //
  // Tags Filter
  //

  QStringList taglist;
  if (tags(taglist)) {
    if (taglist.empty()) {
      QDomElement p = doc->createElement("TAG");
      e.appendChild(p);
    } else {
      // iterate over tags, and add each one
      QStringList::const_iterator it_tag = taglist.constBegin();
      while (it_tag != taglist.constEnd()) {
        QDomElement p = doc->createElement("TAG");
        p.setAttribute("id", *it_tag);
        e.appendChild(p);

        ++it_tag;
      }
    }
  }

  //
  // Account Groups Filter
  //

  QList<MyMoneyAccount::accountTypeE> accountgrouplist;
  if (accountGroups(accountgrouplist)) {
    // iterate over accounts, and add each one
    QList<MyMoneyAccount::accountTypeE>::const_iterator it_group = accountgrouplist.constBegin();
    while (it_group != accountgrouplist.constEnd()) {
      QDomElement p = doc->createElement("ACCOUNTGROUP");
      p.setAttribute("group", kAccountTypeText[*it_group]);
      e.appendChild(p);

      ++it_group;
    }
  }

  //
  // Accounts Filter
  //

  QStringList accountlist;
  if (accounts(accountlist)) {
    // iterate over accounts, and add each one
    QStringList::const_iterator it_account = accountlist.constBegin();
    while (it_account != accountlist.constEnd()) {
      QDomElement p = doc->createElement("ACCOUNT");
      p.setAttribute("id", *it_account);
      e.appendChild(p);

      ++it_account;
    }
  }

  //
  // Categories Filter
  //

  accountlist.clear();
  if (categories(accountlist)) {
    // iterate over accounts, and add each one
    QStringList::const_iterator it_account = accountlist.constBegin();
    while (it_account != accountlist.constEnd()) {
      QDomElement p = doc->createElement("CATEGORY");
      p.setAttribute("id", *it_account);
      e.appendChild(p);

      ++it_account;
    }
  }

  //
  // Date Filter
  //

  if (m_dateLock == userDefined) {
    QDate dateFrom, dateTo;
    if (dateFilter(dateFrom, dateTo)) {
      QDomElement f = doc->createElement("DATES");
      if (dateFrom.isValid())
        f.setAttribute("from", dateFrom.toString(Qt::ISODate));
      if (dateTo.isValid())
        f.setAttribute("to", dateTo.toString(Qt::ISODate));
      e.appendChild(f);
    }
  }
}
Ejemplo n.º 7
0
QScriptValue searchReplaceFunction(QScriptContext *context, QScriptEngine *engine, bool replace){
	QEditor *editor = qobject_cast<QEditor*>(context->thisObject().toQObject());
	//read arguments
	SCRIPT_REQUIRE(editor, "invalid object");
	SCRIPT_REQUIRE(!replace || context->argumentCount()>=2, "at least two arguments are required");
	SCRIPT_REQUIRE(context->argumentCount()>=1, "at least one argument is required");
	SCRIPT_REQUIRE(context->argumentCount()<=4, "too many arguments");
	SCRIPT_REQUIRE(context->argument(0).isString()||context->argument(0).isRegExp(), "first argument must be a string or regexp");
	QDocumentSearch::Options flags = QDocumentSearch::Silent;
	bool global = false, caseInsensitive = false;
	QString searchFor;
	if (context->argument(0).isRegExp()) {
		flags |= QDocumentSearch::RegExp;
		QRegExp r = context->argument(0).toRegExp();
		searchFor = r.pattern();
		caseInsensitive = r.caseSensitivity() == Qt::CaseInsensitive;
		Q_ASSERT(caseInsensitive == context->argument(0).property("ignoreCase").toBool()); //check assumption about javascript core
		global = context->argument(0).property("global").toBool();
	} else searchFor = context->argument(0).toString();
	QScriptValue handler;
	QDocumentCursor scope = editor->document()->cursor(0,0,editor->document()->lineCount(),0);
	int handlerCount = 0;
	for (int i=1; i<context->argumentCount();i++)
		if (context->argument(i).isString() || context->argument(i).isFunction()) handlerCount++;
	SCRIPT_REQUIRE(handlerCount <= (replace?2:1), "too many string or function arguments");
	for (int i=1; i<context->argumentCount();i++) {
		QScriptValue a = context->argument(i);
		if (a.isFunction()) {
			SCRIPT_REQUIRE(!handler.isValid(), "Multiple callbacks");
			handler = a;
		} else if (a.isString()) {
			if (!replace || handlerCount > 1) {
				QString s = a.toString().toLower();
				global = s.contains("g");
				caseInsensitive = s.contains("i");
				if (s.contains("w")) flags |= QDocumentSearch::WholeWords;
			} else {
				SCRIPT_REQUIRE(!handler.isValid(), "Multiple callbacks");
				handler = a;
			}
			handlerCount--;
		} else if (a.isNumber()) flags |= QDocumentSearch::Options((int)a.toNumber());
		else if (a.isObject()) scope = cursorFromValue(a);
		else SCRIPT_REQUIRE(false, "Invalid argument");
	}
	SCRIPT_REQUIRE(handler.isValid() || !replace, "No callback given");
	if (!caseInsensitive) flags |= QDocumentSearch::CaseSensitive;
	
	//search/replace
	QDocumentSearch search(editor, searchFor, flags);
	search.setScope(scope);
	if (replace && handler.isString()) {
		search.setReplaceText(handler.toString());
		search.setOption(QDocumentSearch::Replace,true);
		return search.next(false, global, false, false);
	}
	if (!handler.isValid())
		return search.next(false,global,true,false);
	int count=0;
	while (search.next(false, false, true, false) && search.cursor().isValid()) {
		count++;
		QDocumentCursor temp = search.cursor();
		QScriptValue cb = handler.call(QScriptValue(), QScriptValueList() << engine->newQObject(&temp));
		if (replace && cb.isValid()){
			QDocumentCursor tmp = search.cursor();
			tmp.replaceSelectedText(cb.toString());
			search.setCursor(tmp.selectionEnd());
		}
		if (!global) break;
	}
	return count;
}