本文整理汇总了C++中QRegExp::indexIn方法的典型用法代码示例。如果您正苦于以下问题:C++ QRegExp::indexIn方法的具体用法?C++ QRegExp::indexIn怎么用?C++ QRegExp::indexIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRegExp
的用法示例。
在下文中一共展示了QRegExp::indexIn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkProgressLine
void AudioCdRecord::checkProgressLine( const QString & str )
{
QRegExp reg;
int pos;
bool ok;
reg.setPattern( "(\\d+)(?:\\s*)of\\s+\\d+\\s+(KB|MB|GB)" );
pos = reg.indexIn( str );
if( pos > -1 )
p->written_size_int = reg.cap(1).toInt(&ok);
reg.setPattern( "(\\d+)(?:\\s*)(KB|MB|GB)" );
pos = reg.indexIn( str );
if( pos > -1 )
p->image_size_int = reg.cap(1).toInt(&ok);
reg.setPattern( "fifo\\s+(\\d+)(?:\\s*)%" );
pos = reg.indexIn( str );
if( pos > -1 )
p->ring_buffer_percent_int = reg.cap(1).toInt(&ok);
reg.setPattern( "buf\\s+(\\d+)(?:\\s*)%" );
pos = reg.indexIn( str );
if( pos > -1 )
p->buffer_percent_int = reg.cap(1).toInt(&ok);
reg.setPattern( "(\\d+\\.\\d)(?:\\s*)x\\.$" );
pos = reg.indexIn( str );
if( pos > -1 )
p->written_speed_int = reg.cap(1).toDouble(&ok);
if( p->image_size_int > 0 )
p->process_precent = 100 * p->written_size_int / p->image_size_int;
emit ringBufferChanged( p->ring_buffer_percent_int );
emit bufferChanged( p->buffer_percent_int );
emit writeSizeChenged( p->written_size_int );
emit writeSpeedChanged( p->written_speed_int );
emit percentChanged( p->process_precent );
}
示例2: insertLinks
QString QgsStringUtils::insertLinks( const QString& string, bool *foundLinks )
{
QString converted = string;
// http://alanstorm.com/url_regex_explained
// note - there's more robust implementations available, but we need one which works within the limitation of QRegExp
static QRegExp urlRegEx( "(\\b(([\\w-]+://?|www[.])[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^!\"#$%&'()*+,\\-./:;<=>[email protected][\\\\\\]^_`{|}~\\s]|/))))" );
static QRegExp protoRegEx( "^(?:f|ht)tps?://" );
static QRegExp emailRegEx( "([\\w._%+-][email protected][\\w.-]+\\.[A-Za-z]+)" );
int offset = 0;
bool found = false;
while ( urlRegEx.indexIn( converted, offset ) != -1 )
{
found = true;
QString url = urlRegEx.cap( 1 );
QString protoUrl = url;
if ( protoRegEx.indexIn( protoUrl ) == -1 )
{
protoUrl.prepend( "http://" );
}
QString anchor = QStringLiteral( "<a href=\"%1\">%2</a>" ).arg( Qt::escape( protoUrl ), Qt::escape( url ) );
converted.replace( urlRegEx.pos( 1 ), url.length(), anchor );
offset = urlRegEx.pos( 1 ) + anchor.length();
}
offset = 0;
while ( emailRegEx.indexIn( converted, offset ) != -1 )
{
found = true;
QString email = emailRegEx.cap( 1 );
QString anchor = QStringLiteral( "<a href=\"mailto:%1\">%1</a>" ).arg( Qt::escape( email ), Qt::escape( email ) );
converted.replace( emailRegEx.pos( 1 ), email.length(), anchor );
offset = emailRegEx.pos( 1 ) + anchor.length();
}
if ( foundLinks )
*foundLinks = found;
return converted;
}
示例3: loadStylesheet
void loadStylesheet(const QString &name, QHash<QString, StyleData> &dict)
{
QFile file(name);
if (! file.open(QIODevice::ReadOnly)) {
err("Unable to open RTF style sheet file %s, using default file\n", qPrintable(name));
return;
}
msg("Loading RTF style sheet %s\n", qPrintable(name));
static const QRegExp seperator("[ \t]*=[ \t]*");
uint lineNr = 1;
QTextStream t(&file);
t.setCodec("UTF-8");
while (! t.atEnd()) {
QString s = t.readLine().trimmed();
if (s.isEmpty() || s.at(0) == '#') {
continue; // skip blanks & comments
}
int sepStart;
int sepLength;
sepStart = seperator.indexIn(s);
sepLength = seperator.matchedLength();
if (sepStart <= 0) {
// no valid assignment statement
warn(qPrintable(name), lineNr, "Assignment of style sheet name expected\n");
continue;
}
QString key = s.left(sepStart);
if (! dict.contains(key)) {
// not a valid style sheet name
warn(qPrintable(name), lineNr, "Invalid style sheet name %s ignored.\n", qPrintable(key));
continue;
}
// add command separator
StyleData &styleData = dict.find(key).value();
s += " ";
styleData.setStyle(s.mid(sepStart + sepLength), key);
lineNr++;
}
}
示例4: updateOrganism
void IniParser::updateOrganism(OrganismPtr organism)
{
QMutexLocker lock(&organism->mutex);
const QVariant name = value("organisms", "name");
const QVariant ref_seq_assembly_id = value("organisms", "ref_seq_assembly_id");
const QVariant real_chromosome_count = value("organisms", "real_chromosome_count");
const QVariant common_name = value("organisms", "common_name");
const QVariant real_mitochondria = value("organisms", "real_mitochondria");
const QVariant annotation_release = value("organisms", "annotation_release");
const QVariant annotation_date = value("organisms", "annotation_date");
if (name.isValid()) {
organism->name = name.toString();
}
if (ref_seq_assembly_id.isValid()) {
organism->refSeqAssemblyId = ref_seq_assembly_id.toString();
}
if (real_chromosome_count.isValid()) {
organism->realChromosomeCount = real_chromosome_count.toUInt();
}
if (common_name.isValid()) {
organism->commonName = common_name.toString();
}
if (real_mitochondria.isValid()) {
organism->realMitochondria = bool(real_mitochondria.toUInt());
}
if (annotation_release.isValid()) {
organism->annotationRelease = annotation_release.toString();
}
if (annotation_date.isValid()) {
static QRegExp rxDate("(\\d+)\\s+(\\S+)\\s+(\\d\\d\\d\\d)");
if (-1 != rxDate.indexIn(annotation_date.toString())) {
int day = rxDate.cap(1).toInt();
int year = rxDate.cap(3).toInt();
const QString monthString = rxDate.cap(2).toLower().left(3);
static const QStringList Months = QStringList()
<< "jan" << "feb" << "mar"
<< "apr" << "may" << "jun"
<< "jul" << "aug" << "sep"
<< "oct" << "nov" << "dec";
int month = 1 + Months.indexOf(monthString);
const bool dayValid = 1 <= day && day <= 31;
const bool monthValid = 1 <= month && month <= 12;
const bool yearValid = 1970 <= year && year <= 2039;
if (dayValid && monthValid && yearValid) {
organism->annotationDate.setDate(year, month, day);
}
}
}
}
示例5: HandleBody
QString Plugin::HandleBody (QString body)
{
QRegExp rx ("\\$\\$.+\\$\\$");
rx.setMinimal (true);
int pos = 0;
QMap<QString, QString> replaceMap;
while (pos >= 0 && pos < body.size ())
{
pos = rx.indexIn (body, pos);
if (pos < 0)
break;
const QString& match = rx.cap (0);
pos += rx.matchedLength ();
QString formula = match;
formula.remove ("$$");
formula = formula.trimmed ();
if (formula.isEmpty () || !IsSecure (formula))
continue;
formula.replace ("<", "<");
formula.replace (">", ">");
formula.replace (""", "\"");
formula.replace ("&", "&");
const QImage& rendered = GetRenderedImage (formula);
if (rendered.isNull ())
continue;
replaceMap [match] = Util::GetAsBase64Src (rendered);
}
if (replaceMap.isEmpty ())
return body;
Q_FOREACH (const QString& key, replaceMap.keys ())
{
QString escFormula = key;
escFormula.replace ('\"', """);
escFormula.remove ("$$");
const QString img = QString ("<img src=\"%1\" alt=\"%2\" style=\"vertical-align: middle;\" />")
.arg (replaceMap [key])
.arg (escFormula.trimmed ().simplified ());
body.replace (key, img);
}
return body;
}
示例6: ircFormatToPlainText
QString IrcProtocol::ircFormatToPlainText(const QString &msg)
{
QString result;
result.reserve(msg.size());
int pos = 0, oldPos = 0;
while ((pos = formatRx.indexIn(msg, pos)) != -1) {
result += msg.mid(oldPos, pos - oldPos);
pos += formatRx.matchedLength();
oldPos = pos;
}
result += msg.mid(oldPos);
return result;
}
示例7: textUnderCursor
QString LiteWordCompleter::textUnderCursor(QTextCursor tc) const
{
QString text = tc.block().text().left(tc.positionInBlock());
if (text.isEmpty()) {
return QString();
}
static QRegExp reg("[a-zA-Z_]+[a-zA-Z0-9_\\[email protected]]*$");
int index = reg.indexIn(text);
if (index < 0) {
return QString();
}
return text.right(reg.matchedLength());
}
示例8:
QVector<bool> Tags::find(const QRegExp& pattern, QVector<QString>& vector, QMap<QString, QPair<quint32, quint32> > & map)
{
QVector<bool> result;
QVector<QString>::iterator it;
for (it = vector.begin(); it != vector.end(); ++it) {
if (map.contains(*it) && pattern.indexIn(*it) >= 0) {
result.push_back(true);
} else {
result.push_back(false);
}
}
return result;
}
示例9: memoryUsage
int Shell::memoryUsage() const
{
QRegExp rx;
rx.setPattern("VmRSS:\\t\\s+(\\d+)");
QProcess p;
p.start("cat /proc/"+ QString::number(m_pid) +"/status");
p.waitForFinished();
QString kBString;
if (rx.indexIn(p.readAll()) != -1) {
kBString = rx.cap(1);
}
return kBString.toInt();
}
示例10: importUnderCursor
QString LiteEditorWidget::importUnderCursor(QTextCursor tc) const
{
QString text = tc.block().text().left(tc.positionInBlock());
if (text.isEmpty()) {
return QString();
}
static QRegExp reg("[\"`][a-zA-Z0-9_\\-\\.\\/]*$");
int index = reg.indexIn(text);
if (index < 0) {
return QString();
}
return text.right(reg.matchedLength()-1);
}
示例11: processEvent
void formulesPlugin::processEvent(Event &event)
{
if(event.args.size()<1)
return;
if(event.id == m_new_my_message_1 || event.id == m_new_message)
{
QString *msg = (QString *)event.args.at(1);
QRegExp rx;
rx.setMinimal(true);
int pos;
rx.setPattern("\\[tex\\](.*)\\[/tex\\]");
pos = 0;
while (pos >= 0)
{
pos = rx.indexIn(*msg, pos);
if (pos >= 0)
{
pos++;
itemfound(msg, rx.cap(1), 1);
}
}
rx.setPattern("\\$\\$(.*)\\$\\$");
pos = 0;
while (pos >= 0)
{
pos = rx.indexIn(*msg, pos);
if (pos >= 0)
{
pos++;
itemfound(msg, rx.cap(1), 2);
}
}
}
}
示例12: shouldStartCompletion
bool KateNewCompletionModel::shouldStartCompletion(KTextEditor::View* view, const QString &insertedText, bool userInsertion, const KTextEditor::Cursor &position)
{
if (!userInsertion) return false;
if(insertedText.isEmpty())
return false;
KateView *v = qobject_cast<KateView*> (view);
QString text = view->document()->line(position.line()).left(position.column());
static const QRegExp ktuan_new_class("((new \\w*)|(gen\\w*)|(get\\w*))$");
if (ktuan_new_class.indexIn(text) >= 0) return true;
return false;
}
示例13: rx
static QList<QByteArray> parseArguments(const QString &str)
{
const QRegExp rx("(\"([^\"]*)\"|([^ ]+))", Qt::CaseSensitive, QRegExp::RegExp2);
QList<QByteArray> res;
int pos = 0;
while ((pos = rx.indexIn(str, pos)) >= 0) {
auto cap2 = rx.cap(2);
res << ((cap2.isEmpty()) ? rx.cap(3) : cap2).toLocal8Bit();
pos += rx.matchedLength();
}
return res;
}
示例14: fileNameForLine
QString GitEditorWidget::fileNameForLine(int line) const
{
// 7971b6e7 share/qtcreator/dumper/dumper.py (hjk
QTextBlock block = document()->findBlockByLineNumber(line - 1);
QTC_ASSERT(block.isValid(), return source());
static QRegExp renameExp(QLatin1String("^" CHANGE_PATTERN "\\s+([^(]+)"));
if (renameExp.indexIn(block.text()) != -1) {
const QString fileName = renameExp.cap(1).trimmed();
if (!fileName.isEmpty())
return fileName;
}
return source();
}
示例15: notSeen
void
IrcAbstractChannel::CheckWatch (const QString & data)
{
QList<QRegExp>::iterator lit;
bool notSeen (true);
for (lit=watchList.begin(); notSeen && lit != watchList.end(); lit++) {
QRegExp rX = *lit;
if (rX.indexIn (data,0) >= 0) {
emit WatchAlert (chanName, data);
notSeen = false;
}
}
}