本文整理汇总了C++中QRegularExpressionMatch::capturedStart方法的典型用法代码示例。如果您正苦于以下问题:C++ QRegularExpressionMatch::capturedStart方法的具体用法?C++ QRegularExpressionMatch::capturedStart怎么用?C++ QRegularExpressionMatch::capturedStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRegularExpressionMatch
的用法示例。
在下文中一共展示了QRegularExpressionMatch::capturedStart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fix_self_closing_tags
// Handle the general case
QString GumboInterface::fix_self_closing_tags(const QString &source)
{
QString newsource = source;
QRegularExpression selfclosed("<\\s*([a-zA-Z]+)(\\s*[^>/]*)/\\s*>");
QRegularExpressionMatch match = selfclosed.match(newsource, 0);
while (match.hasMatch()) {
if (match.capturedStart() == -1) {
break;
}
QString tag = match.captured(0);
int sp = match.capturedStart(0);
int n = match.capturedLength(0);
QString name = match.captured(1);
QString atts = match.captured(2);;
atts = atts.trimmed();
if (!atts.isEmpty()) {
atts = " " + atts;
}
int nsp = sp + n;
if (!allowed_void_tags.contains(name)) {
QString newtag = "<" + name + atts + "></" + name + ">";
newsource = newsource.replace(sp,n,newtag);
nsp = sp + newtag.length();
}
match = selfclosed.match(newsource, nsp);
}
return newsource;
}
示例2: Generate
// The actual generation engine
QString ShopTemplateManager::Generate(const Items &items) {
QString temp = shopTemplate;
{
QRegularExpression expr("{(?<key>.+?)(?<options>(\\|(.+?))*?)}");
QRegularExpressionMatchIterator matcher = expr.globalMatch(shopTemplate);
int offset = 0;
while (matcher.hasNext()) {
QRegularExpressionMatch match = matcher.next();
QString key = match.captured("key").toLower();
int startPos = offset + match.capturedStart();
int len = match.capturedLength();
QStringList optionsAndData = match.captured("options").split("|", QString::SkipEmptyParts);
QHash<QString, QString> options;
for (QString optionAndData : optionsAndData) {
int split = optionAndData.indexOf(":");
if (split == -1) {
options.insert(optionAndData.toLower(), "");
}
else {
QString option = optionAndData.left(split).toLower();
QString data = optionAndData.mid(split + 1);
options.insert(option, data);
}
}
QString replacement = FetchFromKey(key, items, &options);
temp.replace(startPos, len, replacement);
offset += replacement.length() - len;
}
}
// Now clean up empty spoiler tags!
int matches = -1;
while (matches != 0){
QRegularExpression expr("\\[spoiler=\\\"(?>.*?\\\"\\])(?>\\s*?\\[\\/spoiler\\]\\n)");
QRegularExpressionMatchIterator matcher = expr.globalMatch(temp);
int offset = 0;
matches = 0;
while (matcher.hasNext()) {
QRegularExpressionMatch match = matcher.next();
int startPos = match.capturedStart() + offset;
int length = match.capturedLength();
temp.remove(startPos, length);
offset -= length;
matches++;
}
}
return temp;
}
示例3: filterEntry
QList<LocatorFilterEntry> OpenDocumentsFilter::matchesFor(QFutureInterface<LocatorFilterEntry> &future,
const QString &entry)
{
QList<LocatorFilterEntry> goodEntries;
QList<LocatorFilterEntry> betterEntries;
const EditorManager::FilePathInfo fp = EditorManager::splitLineAndColumnNumber(entry);
const QRegularExpression regexp = createRegExp(fp.filePath);
if (!regexp.isValid())
return goodEntries;
const QList<Entry> editorEntries = editors();
for (const Entry &editorEntry : editorEntries) {
if (future.isCanceled())
break;
QString fileName = editorEntry.fileName.toString();
if (fileName.isEmpty())
continue;
QString displayName = editorEntry.displayName;
const QRegularExpressionMatch match = regexp.match(displayName);
if (match.hasMatch()) {
LocatorFilterEntry filterEntry(this, displayName, QString(fileName + fp.postfix));
filterEntry.extraInfo = FileUtils::shortNativePath(FileName::fromString(fileName));
filterEntry.fileName = fileName;
filterEntry.highlightInfo = highlightInfo(match);
if (match.capturedStart() == 0)
betterEntries.append(filterEntry);
else
goodEntries.append(filterEntry);
}
}
betterEntries.append(goodEntries);
return betterEntries;
}
示例4: prepend_symbol_on_nth_match
/**
* @brief prepend symbol on nth match
* @param input input string
* @param number_length the length of the number, will prepend symbol
* if the length smaller than this number
* @param nth the number of match
* @param reg the pattern want to find
* @param symbol symbol prepand before the number
* @return the input after symbol prepend if match the condition; if the reg
* found the match pattern but the target length less than number_length, do nothing;
* if reg do not find any match, return "the number of match is out of range
* or found no match in this string"
*/
QString prepend_symbol_on_nth_match(QString const &input, int number_length,
int nth, const QRegularExpression ®, QChar symbol)
{
auto it = reg.globalMatch(input);
QRegularExpressionMatch match;
int count = 0;
while (it.hasNext()){
match = it.next();
if(count == nth){
if(match.hasMatch()){
QString new_file_name = input;
if(!match.captured(1).isEmpty()){
if(match.capturedLength(0) < number_length){
new_file_name.insert(match.capturedStart(0),
QString(number_length - match.capturedLength(0),
symbol));
}
}
return new_file_name;
}else{
break;
}
}
++count;
}
return "the number of match is out of range or found no match in this string";
}
示例5: isLineMatchingBackward
bool QuickFindPattern::isLineMatchingBackward(
const QString& line, int column ) const
{
int pos = 0;
if ( ! active_ )
return false;
QRegularExpressionMatchIterator matches = regexp_.globalMatch(line);
QRegularExpressionMatch lastMatch;
while ( matches.hasNext() ) {
QRegularExpressionMatch nextMatch = matches.peekNext();
if ( column >= 0 && nextMatch.capturedEnd() >= column ) {
break;
}
lastMatch = matches.next();
}
if ( lastMatch.hasMatch() ) {
lastMatchStart_ = lastMatch.capturedStart();
lastMatchEnd_ = lastMatch.capturedEnd() - 1;
return true;
}
else {
return false;
}
}
示例6: parse
void HtmlParser::parse()
{
while(!_downloaded)
{
QThread::msleep(10);
}
_info->_status = UrlInfo::PARSING;
emit processing(_info.data());
_info->_found = _content.contains(_text, Qt::CaseInsensitive);
int start_offset = -1;
QRegularExpression regExp("(?:https?|ftp)://(((((((((\\w|\\d)|\\055)|\\056)|\\046)|\\077)|\\043)|\\045)|\\057)|\\075)+");
while (true)
{
QRegularExpressionMatch match = regExp.match(_content, ++start_offset);
if (!match.hasMatch())
break;
start_offset = match.capturedStart();
int end_offset = match.capturedEnd();
_links << new HtmlParser(_content.mid(start_offset, end_offset), _text);
}
_content.clear();
if (_downloader)
delete _downloader;
_downloader = nullptr;
_info->_status = UrlInfo::FINISHED;
emit processing(_info.data());
}
示例7: highlightBlock
void Highlighter::highlightBlock(const QString &text)
{
foreach (const HighlightingRule &rule, highlightingRules)
{
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
while (matchIterator.hasNext())
{
QRegularExpressionMatch match = matchIterator.next();
setFormat(match.capturedStart(), match.capturedLength(), rule.format);
}
}
示例8: highlightBlock
void SyntaxHighlighter::highlightBlock(const QString &text) {
for (std::size_t i = 0; i < _keywords.size(); i++) {
const KeywordRule &rule = _keywords.at(i);
QRegularExpressionMatchIterator it = rule.rulePattern.globalMatch(text);
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();
setFormat(
match.capturedStart(), match.capturedLength(), rule.ruleTextFormat);
}
}
}
示例9: translate
void Template::translate(ITemplateTranslationProvider &provider)
{
//This regex captures expressions of the form
//<?= tr("This is a test") ?> and <?= tr("optional %1 parameters %2","bla","blu") ?>
//The first capture group is the key (untranslated string), the second the optional list of parameters
const QRegularExpression regexp = QRegularExpression("<\\?=\\s*tr\\(\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"((?:,\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\")*)\\s*\\)\\?>");
//This one is used to extract the parameters using global matching
const QRegularExpression paramExp = QRegularExpression(",\"([^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)\"");
int offset = 0;
QRegularExpressionMatch match;
do
{
match = regexp.match(*this,offset);
if(match.hasMatch())
{
int start = match.capturedStart(0);
int len = match.capturedLength(0);
QString key = match.captured(1);
//replace escaped double and single quotes
key.replace("\\\"","\"");
key.replace("\\'", "'");
QString translation = provider.getTranslation(key);
//find out if we have optional parameters
if(match.capturedLength(2)>0)
{
QString params = match.captured(2);
//extract each optional parameter
QRegularExpressionMatchIterator it = paramExp.globalMatch(params);
while(it.hasNext())
{
QRegularExpressionMatch paramMatch = it.next();
QString param = paramMatch.captured(1);
//replace escaped quotes
param.replace("\\\"","\"");
param.replace("\\'", "'");
//apply the param
translation = translation.arg(param);
}
}
this->replace(start,len,translation);
offset = start+translation.length();
}
}while(match.hasMatch());
}
示例10: htmlEncode
QString StringUtils::htmlEncode(
QString text, bool urlAsLinks, bool newlineAsBr) {
QString s;
QHash<int,int> linksIndexes; // start of link index -> length of link
if (urlAsLinks) {
QRegularExpressionMatchIterator it = linkRe.globalMatch(text);
while (it.hasNext()) {
QRegularExpressionMatch match = it.next();
linksIndexes.insert(match.capturedStart(0), match.capturedLength(0));
}
}
for (int i = 0; i < text.length(); ) {
if (urlAsLinks && linksIndexes.contains(i)) {
int l = linksIndexes.value(i);
QString html = htmlEncode(text.mid(i, l), false), href = html;
href.replace("\"", "%22");
s.append("<a href=\"").append(href).append("\">").append(html)
.append("</a>");
i += l;
} else {
const QChar c = text.at(i);
switch(c.toLatin1()) {
case '<':
s.append("<");
break;
case '>':
s.append(">");
break;
case '&':
s.append("&");
break;
case '"':
s.append(""");
break;
case '\'':
s.append("'");
break;
case '\n':
if (newlineAsBr)
s.append("<br/>\n");
else
s.append(c);
break;
default:
s.append(c);
}
++i;
}
}
return s;
}
示例11: foreach
foreach (OnePartRule rule, onepartrules)
{
QRegularExpressionMatchIterator i = rule.pattern.globalMatch(text);
while (i.hasNext())
{
QRegularExpressionMatch match = i.next();
int length = match.capturedLength();
if (length == 0)
continue;
int start = match.capturedStart();
setFormat(start, length, rule.format);
}
}
示例12: indexIn
int QzRegExp::indexIn(const QString &str, int offset) const
{
QzRegExp* that = const_cast<QzRegExp*>(this);
QRegularExpressionMatch m = match(str, offset);
if (!m.hasMatch()) {
that->m_matchedLength = -1;
that->m_capturedTexts.clear();
return -1;
}
that->m_matchedLength = m.capturedLength();
that->m_capturedTexts = m.capturedTexts();
return m.capturedStart();
}
示例13: test
bool HRProcessor::test(const Element &, const QString &block)
{
//! No atomic grouping in python so we simulate it here for performance.
//! The regex only matches what would be in the atomic group - the HR.
//! Then check if we are at end of block or if next char is a newline.
QRegularExpressionMatch m = this->SEARCH_RE.match(block);
if ( m.hasMatch()
&& ( m.capturedEnd() == block.size()
|| block.at(m.capturedStart()+m.capturedLength()) == '\n' ) ) {
//! Save match object on class instance so we can use it later.
this->match = m;
return true;
}
return false;
}
示例14: isLineMatching
bool QuickFindPattern::isLineMatching( const QString& line, int column ) const
{
if ( ! active_ )
return false;
QRegularExpressionMatch match = regexp_.match( line, column );
if ( match.hasMatch() ) {
lastMatchStart_ = match.capturedStart();
lastMatchEnd_ = match.capturedEnd() - 1;
return true;
}
else {
return false;
}
}
示例15: replaceInString
static QString replaceInString (const QRegularExpression &rx, QString string, T func) {
QRegularExpressionMatchIterator it = rx.globalMatch (string);
int offset = 0;
while (it.hasNext ()) {
QRegularExpressionMatch match = it.next ();
QString replaceWith = func (match);
int length = match.capturedLength ();
int begin = match.capturedStart () + offset;
string.replace (begin, length, replaceWith);
offset += replaceWith.length () - length;
}
return string;
}