本文整理汇总了C++中QRegularExpressionMatch::capturedLength方法的典型用法代码示例。如果您正苦于以下问题:C++ QRegularExpressionMatch::capturedLength方法的具体用法?C++ QRegularExpressionMatch::capturedLength怎么用?C++ QRegularExpressionMatch::capturedLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRegularExpressionMatch
的用法示例。
在下文中一共展示了QRegularExpressionMatch::capturedLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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";
}
示例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: 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());
}
示例4: 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;
}
示例5: 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);
}
}
}
示例6: 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);
}
}
示例7: 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;
}
示例8: 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);
}
}
示例9: check_links
bool check_links(QString text)
{
QRegularExpression link_regex("http://restbase.wikitolearn.org/en.wikitolearn.org/v1/media/math/render/svg");
QRegularExpressionMatch contain = link_regex.match(text);
qDebug() << contain;
QRegularExpression png_regex("http://pool.wikitolearn.org");
QRegularExpressionMatch png = png_regex.match(text);
qDebug() << png;
if(contain.capturedLength() > 0 && png.capturedLength() > 0)
{
// change the status to true , so that i can download dependencies
math_svg = true;
image_png = true;
return true;
}
else if(contain.capturedLength() > 0)
{
// change the status to true , to download the dependencies
math_svg = true;
return true;
}
else if(png.capturedLength() > 0)
{
// change the status to true , to download the images
image_png = true;
return true;
}
else
{
return false;
}
}
示例10: 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();
}
示例11: update_style_urls
std::string GumboInterface::update_style_urls(const std::string &source)
{
QString result = QString::fromStdString(source);
// Now parse the text once looking urls and replacing them where needed
QRegularExpression reference(
"(?:(?:src|background|background-image|list-style|list-style-image|border-image|border-image-source|content)\\s*:|@import)\\s*"
"[^;\\}\\(\"']*"
"(?:"
"url\\([\"']?([^\\(\\)\"']*)[\"']?\\)"
"|"
"[\"']([^\\(\\)\"']*)[\"']"
")");
int start_index = 0;
QRegularExpressionMatch mo = reference.match(result, start_index);
do {
for (int i = 1; i < reference.captureCount(); ++i) {
if (mo.captured(i).trimmed().isEmpty()) {
continue;
}
QString apath = Utility::URLDecodePath(mo.captured(i));
QString search_key = QDir::cleanPath(m_currentdir + FORWARD_SLASH + apath);
QString new_href;
if (m_sourceupdates.contains(search_key)) {
new_href = m_sourceupdates.value(search_key);
}
if (!new_href.isEmpty()) {
new_href = Utility::URLEncodePath(new_href);
result.replace(mo.capturedStart(i), mo.capturedLength(i), new_href);
}
}
start_index += mo.capturedLength();
mo = reference.match(result, start_index);
} while (mo.hasMatch());
return result.toStdString();
}
示例12: 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;
}
示例13: 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;
}
示例14: matchLine
bool QuickFindPattern::matchLine( const QString& line,
QList<QuickFindMatch>& matches ) const
{
matches.clear();
if ( active_ ) {
QRegularExpressionMatchIterator matchIterator = regexp_.globalMatch(line);
while( matchIterator.hasNext() ) {
QRegularExpressionMatch match = matchIterator.next();
matches << QuickFindMatch ( match.capturedStart(), match.capturedLength() );
}
}
return ( matches.count() > 0 );
}
示例15: incrementNumberInString
QString Toolbox::incrementNumberInString(QString string) noexcept {
QRegularExpression regex("([0-9]+)(?!.*[0-9]+)");
QRegularExpressionMatch match = regex.match(string);
if (match.hasMatch()) {
// string contains numbers -> increment last number
bool ok = false;
uint number = match.captured().toUInt(&ok);
if (ok) {
string.replace(match.capturedStart(), match.capturedLength(),
QString::number(number + 1U));
return string;
}
}
// fallback: just add a "1" at the end
return string % "1";
}