本文整理汇总了C++中QRegExp::matchedLength方法的典型用法代码示例。如果您正苦于以下问题:C++ QRegExp::matchedLength方法的具体用法?C++ QRegExp::matchedLength怎么用?C++ QRegExp::matchedLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRegExp
的用法示例。
在下文中一共展示了QRegExp::matchedLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
///Obtain all regex matches in a std::string
//From http://www.richelbilderbeek.nl/CppGetRegexMatches.htm
const std::vector<std::string> ribi::RegexTesterQtMainDialog::GetRegexMatches(
const std::string& s,
const QRegExp& r_original)
{
QRegExp r = r_original;
r.setMinimal(true); //QRegExp must be non-greedy
std::vector<std::string> v;
int pos = 0;
while ((pos = r.indexIn(s.c_str(), pos)) != -1)
{
const QString q = r.cap(1);
if (q.isEmpty()) break;
v.push_back(q.toStdString());
pos += r.matchedLength();
}
return v;
}
示例2: resolvedReplacement
static QString resolvedReplacement( const QString &replacement, const QRegExp &expr )
{
//qDebug("START");
static const QRegExp rexpr("(\\\\\\\\)|(\\\\[0-9]+)");
QString str( replacement );
int i=0;
while(i < str.size() && ((i = rexpr.indexIn(str, i)) != -1))
{
int len = rexpr.matchedLength();
if(rexpr.pos(1) != -1)
{
//qDebug("%i (%s): escape", i, CSTR(rexpr.cap(1)));
str.replace(i, len, "\\");
i += 1;
}
else if(rexpr.pos(2) != -1)
{
QString num_str = rexpr.cap(2);
num_str.remove(0, 1);
int num = num_str.toInt();
//qDebug("%i (%s): backref = %i", i, CSTR(rexpr.cap(2)), num);
if(num <= expr.captureCount())
{
QString cap = expr.cap(num);
//qDebug("resolving ref to: %s", CSTR(cap));
str.replace(i, len, cap);
i += cap.size();
}
else
{
//qDebug("ref out of range", i, num);
str.remove(i, len);
}
}
else
{
//qDebug("%i (%s): unknown match", i, CSTR(rexpr.cap(0)));
str.remove(i, len);
}
//qDebug(">> [%s] %i", CSTR(str), i);
}
//qDebug("END");
return str;
}
示例3: translateDocument
void HttpConnection::translateDocument(QString& data) {
static QRegExp regex(QString::fromUtf8("_\\(([\\w\\s?!:\\/\\(\\),%µ&\\-\\.]+)\\)"));
static QRegExp mnemonic("\\(?&([a-zA-Z]?\\))?");
const std::string contexts[] = {"TransferListFiltersWidget", "TransferListWidget",
"PropertiesWidget", "MainWindow", "HttpServer",
"confirmDeletionDlg", "TrackerList", "TorrentFilesModel",
"options_imp", "Preferences", "TrackersAdditionDlg",
"ScanFoldersModel", "PropTabBar", "TorrentModel",
"downloadFromURL", "misc"};
const size_t context_count = sizeof(contexts)/sizeof(contexts[0]);
int i = 0;
bool found = true;
const QString locale = Preferences().getLocale();
bool isTranslationNeeded = !locale.startsWith("en") || locale.startsWith("en_AU") || locale.startsWith("en_GB");
while(i < data.size() && found) {
i = regex.indexIn(data, i);
if (i >= 0) {
//qDebug("Found translatable string: %s", regex.cap(1).toUtf8().data());
QByteArray word = regex.cap(1).toUtf8();
QString translation = word;
if (isTranslationNeeded) {
int context_index = 0;
while(context_index < context_count && translation == word) {
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
translation = qApp->translate(contexts[context_index].c_str(), word.constData(), 0, QCoreApplication::UnicodeUTF8, 1);
#else
translation = qApp->translate(contexts[context_index].c_str(), word.constData(), 0, 1);
#endif
++context_index;
}
}
// Remove keyboard shortcuts
translation.replace(mnemonic, "");
data.replace(i, regex.matchedLength(), translation);
i += translation.length();
} else {
found = false; // no more translatable strings
}
}
}
示例4: parseContextDiffHeader
bool PerforceParser::parseContextDiffHeader()
{
// qCDebug(LIBKOMPAREDIFF2) << "ParserBase::parseContextDiffHeader()";
bool result = false;
QStringList::ConstIterator itEnd = m_diffLines.end();
QRegExp sourceFileRE ( "([^\\#]+)#(\\d+)" );
QRegExp destinationFileRE( "([^\\#]+)#(|\\d+)" );
while ( m_diffIterator != itEnd )
{
if ( m_contextDiffHeader1.exactMatch( *(m_diffIterator)++ ) )
{
// qCDebug(LIBKOMPAREDIFF2) << "Matched length Header1 = " << m_contextDiffHeader1.matchedLength();
// qCDebug(LIBKOMPAREDIFF2) << "Matched string Header1 = " << m_contextDiffHeader1.cap( 0 );
// qCDebug(LIBKOMPAREDIFF2) << "First capture Header1 = " << m_contextDiffHeader1.cap( 1 );
// qCDebug(LIBKOMPAREDIFF2) << "Second capture Header1 = " << m_contextDiffHeader1.cap( 2 );
m_currentModel = new DiffModel();
sourceFileRE.exactMatch( m_contextDiffHeader1.cap( 1 ) );
destinationFileRE.exactMatch( m_contextDiffHeader1.cap( 2 ) );
qCDebug(LIBKOMPAREDIFF2) << "Matched length = " << sourceFileRE.matchedLength();
qCDebug(LIBKOMPAREDIFF2) << "Matched length = " << destinationFileRE.matchedLength();
qCDebug(LIBKOMPAREDIFF2) << "Captured texts = " << sourceFileRE.capturedTexts();
qCDebug(LIBKOMPAREDIFF2) << "Captured texts = " << destinationFileRE.capturedTexts();
qCDebug(LIBKOMPAREDIFF2) << "Source File : " << sourceFileRE.cap( 1 );
qCDebug(LIBKOMPAREDIFF2) << "Destination File : " << destinationFileRE.cap( 1 );
m_currentModel->setSourceFile ( sourceFileRE.cap( 1 ) );
m_currentModel->setDestinationFile( destinationFileRE.cap( 1 ) );
result = true;
break;
}
else
{
qCDebug(LIBKOMPAREDIFF2) << "Matched length = " << m_contextDiffHeader1.matchedLength();
qCDebug(LIBKOMPAREDIFF2) << "Captured texts = " << m_contextDiffHeader1.capturedTexts();
}
}
return result;
}
示例5: setFilePath
bool Project::setFilePath(const QString &filePath)
{
static const QRegExp rx("/\\*\\s+QssEditor:\\s+([a-zA-Z0-9+\\/=]+)\\s+\\*/\\s+");
m_error.clear();
if(filePath.isEmpty())
{
m_error = QObject::tr("File name is empty");
return false;
}
QFile file(filePath);
if(!file.open(QIODevice::ReadOnly))
{
m_error = file.errorString();
return false;
}
QString qss = file.readAll();
int version = -1;
file.close();
if(rx.indexIn(qss) == 0)
{
QByteArray ba = QByteArray::fromBase64(rx.cap(1).toLatin1());
QDataStream ds(&ba, QIODevice::ReadOnly);
ds.setVersion(QDataStream::Qt_4_0);
ds >> version;
if(ds.status() != QDataStream::Ok)
{
m_error = dataStreamErrorToString(ds.status());
return false;
}
qss = qss.mid(rx.matchedLength());
qDebug("Loaded project version %d", version);
}
示例6: textUnderCursor
QString LiteEditorWidget::textUnderCursor(QTextCursor tc) const
{
QString text = tc.block().text().left(tc.positionInBlock());
if (text.isEmpty()) {
return QString();
}
//int index = text.lastIndexOf(QRegExp("\\b[a-zA-Z_][a-zA-Z0-9_\.]+"));
static QRegExp reg("[a-zA-Z_\\.]+[a-zA-Z0-9_\\.]*$");
int index = reg.indexIn(text);
if (index < 0) {
return QString();
}
return text.right(reg.matchedLength());
//int index = text.lastIndexOf(QRegExp("[\w]+$"));
// qDebug() << ">" << text << index;
// int left = text.lastIndexOf(QRegExp("[ |\t|\"|\(|\)|\'|<|>]"));
// text = text.right(text.length()-left+1);
return "";
}
示例7: parseArray
VariableList_t* PHPVariableParser::parseArray(PHPVariable* var)
{
int size;
VariableList_t* list = new VariableList_t;
QRegExp rx;
rx.setPattern("a:(\\d*):\\{");
if(rx.search(m_raw, m_index) == -1) return list;
size = rx.cap(1).toInt();
m_index += rx.matchedLength();
for(int i = 0; i < size; i++) {
list->append(parseVarName(var));
}
m_index++; //eats the '}'
return list;
}
示例8: isCodeDiffersFrom
bool BaseObject::isCodeDiffersFrom(const QString &xml_def1, const QString &xml_def2, const vector<QString> &ignored_attribs, const vector<QString> &ignored_tags)
{
QString xml, tag=QString("<%1").arg(this->getSchemaName()),
attr_regex=QString("(%1=\")"),
tag_regex=QString("<%1[^>]*((/>)|(>((?:(?!</%1>).)*)</%1>))");
QStringList xml_defs{ xml_def1, xml_def2 };
int start=0, end=-1, tag_end=-1;
QRegExp regexp;
for(int i=0; i < 2; i++)
{
xml=xml_defs[i].simplified();
start=xml.indexOf(tag) + tag.length();
end=-1;
//Removing ignored attributes
for(QString attr : ignored_attribs)
{
do
{
regexp=QRegExp(attr_regex.arg(attr));
tag_end=xml.indexOf(QRegExp(QString("(\\\\)?(>)")));
start=regexp.indexIn(xml);//, start);
end=xml.indexOf('"', start + regexp.matchedLength());
if(end > tag_end)
end=-1;
if(start >=0 && end >=0)
xml.remove(start, (end - start) + 1);
}
while(start >= 0 && end >= 0);
}
//Removing ignored tags
for(QString tag : ignored_tags)
xml.remove(QRegExp(tag_regex.arg(tag)));
xml_defs[i]=xml.simplified();
}
return(xml_defs[0]!=xml_defs[1]);
}
示例9: replaceFunctionInvocations
QString CodeConverterBase::replaceFunctionInvocations(QString const &expression) const
{
QString result = expression;
QString const randomTemplate = mFunctionInvocationsConverter->convert("random");
QRegExp const randomFunctionInvocationRegEx("random\\((.*)\\)");
int pos = randomFunctionInvocationRegEx.indexIn(result, 0);
while (pos != -1) {
QString const param = randomFunctionInvocationRegEx.cap(1);
QString randomInvocation = randomTemplate;
randomInvocation.replace("@@[email protected]@", param);
result.replace(randomFunctionInvocationRegEx, randomInvocation);
pos += randomFunctionInvocationRegEx.matchedLength();
pos = randomFunctionInvocationRegEx.indexIn(result, pos);
}
return result;
}
示例10: resolve
void Resolver::resolve(QString& inStr, QString& outStr)
{
QRegExp rx ("[\"'](http://(.+))[\"']");
rx.setMinimal(true);
inStr.replace(QRegExp("[\\r\\n]"), " ");
QTextStream stream(&inStr);
QString line;
sqlite3_stmt* ppStmt;
while((line = stream.readLine()) != 0)
{
int pos = 0;
while ((pos = rx.indexIn(line, pos)) != -1)
{
QString url = rx.cap(2);
url.replace('/', "_");
QString fname(CacheDir + url);
if(!QFile::exists(fname))
{
QFile fd(fname);
if(!_db->query(QString("SELECT data FROM http WHERE url = '") + rx.cap(2) + QString("'")))
qFatal("TODO #3 Resolver");
if((ppStmt = _db->next()) != 0)
{
fd.open(QIODevice::WriteOnly);
const void* data = sqlite3_column_blob(ppStmt, 0);
int size = sqlite3_column_bytes(ppStmt, 0);
QByteArray ba(static_cast<const char*>(data), size);
fd.write(ba);
fd.close();
}
else
fname = _uFileName;
}
line.replace(rx.cap(1), fname);
pos += rx.matchedLength();
}
outStr += line;
}
}
示例11: highlightBlock
void MercurialSubmitHighlighter::highlightBlock(const QString &text)
{
// figure out current state
State state = static_cast<State>(previousBlockState());
if (text.startsWith(QLatin1String("HG:"))) {
setFormat(0, text.size(), formatForCategory(Format_Comment));
setCurrentBlockState(state);
return;
}
if (state == None) {
if (text.isEmpty()) {
setCurrentBlockState(state);
return;
}
state = Header;
} else if (state == Header) {
state = Other;
}
setCurrentBlockState(state);
// Apply format.
switch (state) {
case None:
break;
case Header: {
QTextCharFormat charFormat = format(0);
charFormat.setFontWeight(QFont::Bold);
setFormat(0, text.size(), charFormat);
break;
}
case Other:
// Format key words ("Task:") italic
if (m_keywordPattern.indexIn(text, 0, QRegExp::CaretAtZero) == 0) {
QTextCharFormat charFormat = format(0);
charFormat.setFontItalic(true);
setFormat(0, m_keywordPattern.matchedLength(), charFormat);
}
break;
}
}
示例12: parseObjectMembers
VariableList_t* PHPVariableParser::parseObjectMembers(PHPVariable* parent)
{
//O:6:"Classe":3:{s:6:"membro";N;s:4:"mem2";N;s:4:"priv";N;}
int size;
VariableList_t* list = new VariableList_t;
QRegExp rx;
rx.setPattern("(\\d*):\\{");
if(rx.search(m_raw, m_index) == -1) return list;
size = rx.cap(1).toInt();
m_index += rx.matchedLength();
for(int i = 0; i < size; i++) {
list->append(parseVarName(parent));
}
m_index++; //eats the '}'
return list;
}
示例13: highlightBlock
void SpellHighlighter::highlightBlock(const QString &AText)
{
if (FEnabled)
{
// Match words (minimally) excluding digits within a word
static const QRegExp expression("\\b[^\\s\\d]+\\b");
int index = 0;
while ((index = expression.indexIn(AText, index)) != -1)
{
int length = expression.matchedLength();
if (!isUserNickName(expression.cap()))
{
if (!SpellBackend::instance()->isCorrect(expression.cap()))
setFormat(index, length, FCharFormat);
}
index += length;
}
}
}
示例14: startSearch
void SearchWhileTyping::startSearch(const KTextEditor::Document *doc, const QRegExp ®Exp)
{
int column;
QTime maxTime;
maxTime.start();
for (int line =0; line < doc->lines(); line++) {
if (maxTime.elapsed() > 50) {
kDebug() << "Search time exceeded -> stop" << maxTime.elapsed() << line;
break;
}
column = regExp.indexIn(doc->line(line));
while (column != -1) {
emit matchFound(doc->url().pathOrUrl(), line, column,
doc->line(line), regExp.matchedLength());
column = regExp.indexIn(doc->line(line), column + 1);
}
}
emit searchDone();
}
示例15: simplifyStdString
// Simplify string types in a type
// 'std::set<std::basic_string<char... > >' -> std::set<std::string>'
static inline void simplifyStdString(const QString &charType, const QString &replacement,
QString *type)
{
QRegExp stringRegexp = stdStringRegExp(charType);
const int replacementSize = replacement.size();
for (int pos = 0; pos < type->size(); ) {
// Check next match
const int matchPos = stringRegexp.indexIn(*type, pos);
if (matchPos == -1)
break;
const int matchedLength = stringRegexp.matchedLength();
type->replace(matchPos, matchedLength, replacement);
pos = matchPos + replacementSize;
// If we were inside an 'allocator<std::basic_string..char > >'
// kill the following blank -> 'allocator<std::string>'
if (pos + 1 < type->size() && type->at(pos) == QLatin1Char(' ')
&& type->at(pos + 1) == QLatin1Char('>'))
type->remove(pos, 1);
}
}