本文整理汇总了C++中QRegularExpression函数的典型用法代码示例。如果您正苦于以下问题:C++ QRegularExpression函数的具体用法?C++ QRegularExpression怎么用?C++ QRegularExpression使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QRegularExpression函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QObject
KNMusicLrcParser::KNMusicLrcParser(QObject *parent) :
QObject(parent),
m_frameCatchRegExp(QRegularExpression("\\[[^\\]]*\\]")),
m_noneNumberRegExp(QRegularExpression("[^0-9]")),
m_utf8Codec(QTextCodec::codecForName("UTF-8")),
m_localeCodec(knI18n->localeCodec())
{
}
示例2: cleanupFileName
/**
* Does a file name cleanup
*/
QString Note::cleanupFileName(QString name) {
// remove characters from the name that are problematic
name.remove(QRegularExpression("[\\/\\\\:]"));
// remove multiple whitespaces from the name
name.replace(QRegularExpression("\\s+"), " ");
return name;
}
示例3: addAvion
void AvionShow::addAvion()
{
Direction * dir=dynamic_cast<Direction *>(g());
QString idc,idm;
idc=_idc->model()->index(0,0).data().toString().split(QRegularExpression("\\s+"))[0];
idm=_idm->model()->index(0,0).data().toString().split(QRegularExpression("\\s+"))[0];
dir->setIAvion();
connect(dir,SIGNAL(doneAddingAvion()),this,SLOT(maktir3ambetfidbascava()));
dir->addAvion(idm,idc,ui->IdAvC->text(),"0");
}
示例4: defined
QRegularExpression SystemFactory::supportedUpdateFiles() {
#if defined(Q_OS_WIN)
return QRegularExpression(QSL(".+win.+\\.(exe|7z)"));
#elif defined(Q_OS_MAC)
return QRegularExpression(QSL(".dmg"));
#elif defined(Q_OS_LINUX)
return QRegularExpression(QSL(".AppImage"));
#else
return QRegularExpression(QSL(".*"));
#endif
}
示例5: QRegularExpression
void PsUpdateDownloader::initOutput() {
QString fileName;
QRegularExpressionMatch m = QRegularExpression(qsl("/([^/\\?]+)(\\?|$)")).match(updateUrl);
if (m.hasMatch()) {
fileName = m.captured(1).replace(QRegularExpression(qsl("[^a-zA-Z0-9_\\-]")), QString());
}
if (fileName.isEmpty()) {
fileName = qsl("tupdate-%1").arg(rand());
}
QString dirStr = cWorkingDir() + qsl("tupdates/");
fileName = dirStr + fileName;
QFileInfo file(fileName);
QDir dir(dirStr);
if (dir.exists()) {
QFileInfoList all = dir.entryInfoList(QDir::Files);
for (QFileInfoList::iterator i = all.begin(), e = all.end(); i != e; ++i) {
if (i->absoluteFilePath() != file.absoluteFilePath()) {
QFile::remove(i->absoluteFilePath());
}
}
} else {
dir.mkdir(dir.absolutePath());
}
outputFile.setFileName(fileName);
if (file.exists()) {
uint64 fullSize = file.size();
if (fullSize < INT_MAX) {
int32 goodSize = (int32)fullSize;
if (goodSize % UpdateChunk) {
goodSize = goodSize - (goodSize % UpdateChunk);
if (goodSize) {
if (outputFile.open(QIODevice::ReadOnly)) {
QByteArray goodData = outputFile.readAll().mid(0, goodSize);
outputFile.close();
if (outputFile.open(QIODevice::WriteOnly)) {
outputFile.write(goodData);
outputFile.close();
QMutexLocker lock(&mutex);
already = goodSize;
}
}
}
} else {
QMutexLocker lock(&mutex);
already = goodSize;
}
}
if (!already) {
QFile::remove(fileName);
}
}
}
示例6: blocker
/**
* Parses a text document and builds the navigation tree for it
*/
void NavigationWidget::parse(QTextDocument *document) {
const QSignalBlocker blocker(this);
Q_UNUSED(blocker);
setDocument(document);
clear();
_lastHeadingItemList.clear();
for (int i = 0; i < document->blockCount(); i++) {
QTextBlock block = document->findBlockByNumber(i);
int elementType = block.userState();
// ignore all non headline types
if ((elementType < pmh_H1) || (elementType > pmh_H6)) {
continue;
}
QString text = block.text();
text.remove(QRegularExpression("^#+"))
.remove(QRegularExpression("#+$"))
.remove(QRegularExpression("^\\s+"))
.remove(QRegularExpression("^=+$"))
.remove(QRegularExpression("^-+$"));
if (text.isEmpty()) {
continue;
}
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(0, text);
item->setData(0, Qt::UserRole, block.position());
item->setToolTip(0, tr("headline %1").arg(elementType - pmh_H1 + 1));
// attempt to find a suitable parent item for the element type
QTreeWidgetItem *lastHigherItem = findSuitableParentItem(elementType);
if (lastHigherItem == NULL) {
// if there wasn't a last higher level item then add the current
// item to the top level
addTopLevelItem(item);
} else {
// if there was a last higher level item then add the current
// item as child of that item
lastHigherItem->addChild(item);
}
_lastHeadingItemList[elementType] = item;
}
expandAll();
}
示例7: QRegularExpression
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());
}
示例8: text
void ScintillaEditor::changeSpacesToTabs() {
/* -changes spaces into tabs */
//go through the text line by line and replace spaces with tabs
QStringList editorTextLines = text().split( QRegularExpression("\n") );
QString textExpression = tr("\\s{2,%1}").arg( tabWidth() );
for (int i = 0, l = editorTextLines.length(); i < l; i++) {
editorTextLines[i].replace( QRegularExpression(textExpression), "\t");
}
setText( editorTextLines.join("\n") );
}
示例9: Q_D
void FloorCapVector::UnpackVector()
{
Q_D(FloorCapVector);
d->m_FloorVal.clear();
d->m_CapVal.clear();
if (d->m_Vector.isEmpty()) return;
ExtractAnchorDate();
QString TempVec(d->m_Vector.trimmed().toUpper());
QStringList StringParts = TempVec.trimmed().toUpper().split(QRegularExpression("\\s"), QString::SkipEmptyParts);
int StepLen;
QString TempStr;
for (int i = 1; i < StringParts.size(); i += 2) {
TempStr = StringParts.at(i);
TempStr.replace(QRegularExpression("\\D"), "");
StepLen = TempStr.toInt();
TempStr = StringParts.at(i);
TempStr.replace(QRegularExpression("\\d"), "");
for (int j = 0; j < StepLen; j++) {
QString RawVal = StringParts.at(i - 1);
RawVal.replace("[", "");
RawVal.replace("]", "");
auto CapFloor = RawVal.split(',', QString::KeepEmptyParts);
if (CapFloor.size() > 0) {
if (CapFloor.at(0).isEmpty()) d->m_FloorVal.append(std::shared_ptr<double>(nullptr));
else d->m_FloorVal.append(std::make_shared<double>(CapFloor.at(0).toDouble()));
}
else d->m_FloorVal.append(std::shared_ptr<double>(nullptr));
if (CapFloor.size() > 1) {
if (CapFloor.at(1).isEmpty()) d->m_CapVal.append(std::shared_ptr<double>(nullptr));
else d->m_CapVal.append(std::make_shared<double>(CapFloor.at(1).toDouble()));
}
else d->m_CapVal.append(std::shared_ptr<double>(nullptr));
}
}
{
QString RawVal = StringParts.last();
RawVal.replace("[", "");
RawVal.replace("]", "");
auto CapFloor = RawVal.split(',', QString::KeepEmptyParts);
if (CapFloor.size() > 0) {
if (CapFloor.at(0).isEmpty()) d->m_FloorVal.append(std::shared_ptr<double>(nullptr));
else d->m_FloorVal.append(std::make_shared<double>(CapFloor.at(0).toDouble()));
}
else d->m_FloorVal.append(std::shared_ptr<double>(nullptr));
if (CapFloor.size() > 1) {
if (CapFloor.at(1).isEmpty()) d->m_CapVal.append(std::shared_ptr<double>(nullptr));
else d->m_CapVal.append(std::make_shared<double>(CapFloor.at(1).toDouble()));
}
else d->m_CapVal.append(std::shared_ptr<double>(nullptr));
}
}
示例10: QRegularExpression
QPointF SymbolDataEditor::getMovePoint(const QString &path)
{
QString move = QRegularExpression("^[mM] *-?\\d+\\.?\\d*,? ?-?\\d+\\.?\\d*").match(path).captured();
move.remove(QRegularExpression("^[mM] *"));
int indexOfSeparator = move.indexOf(QRegularExpression("[ ,]"));
if (indexOfSeparator >= 0 && indexOfSeparator + 1 < move.size())
{
QString x = move.left(indexOfSeparator);
QString y = move.mid(indexOfSeparator + 1);
return QPointF(x.toDouble(), y.toDouble());
}
return QPointF(0.0, 0.0);
}
示例11: createSafeSheetName
/*
Creates a valid sheet name
minimum length is 1
maximum length is 31
doesn't contain special chars: / \ ? * ] [ :
Sheet names must not begin or end with ' (apostrophe)
Invalid characters are replaced by one space character ' '.
*/
QString createSafeSheetName(const QString &nameProposal)
{
if (nameProposal.isEmpty())
return QString();
QString ret = nameProposal;
if (nameProposal.contains(QRegularExpression(QStringLiteral("[/\\\\?*\\][:]+"))))
ret.replace(QRegularExpression(QStringLiteral("[/\\\\?*\\][:]+")), QStringLiteral(" "));
while(ret.contains(QRegularExpression(QStringLiteral("^\\s*'\\s*|\\s*'\\s*$"))))
ret.remove(QRegularExpression(QStringLiteral("^\\s*'\\s*|\\s*'\\s*$")));
ret = ret.trimmed();
if (ret.size() > 31)
ret = ret.left(31);
return ret;
}
示例12: QString
void LoadJob::onNewEntry(const Archive::Entry *entry)
{
m_extractedFilesSize += entry->property("size").toLongLong();
m_isPasswordProtected |= entry->property("isPasswordProtected").toBool();
if (entry->isDir()) {
m_dirCount++;
} else {
m_filesCount++;
}
if (m_isSingleFolderArchive) {
// RPM filenames have the ./ prefix, and "." would be detected as the subfolder name, so we remove it.
const QString fullPath = entry->fullPath().replace(QRegularExpression(QStringLiteral("^\\./")), QString());
const QString basePath = fullPath.split(QLatin1Char('/')).at(0);
if (m_basePath.isEmpty()) {
m_basePath = basePath;
m_subfolderName = basePath;
} else {
if (m_basePath != basePath) {
m_isSingleFolderArchive = false;
m_subfolderName.clear();
}
}
}
}
示例13: saveAllSheetsToImages
void MainWindow::saveAllSheetsToImages(const QString &fileName)
{
int indexOfExtension = fileName.indexOf(QRegularExpression("\\.\\w+$"), 0);
QString currentFileName;
currentSheetNumber = -1;
ui->toolBar->actions()[ToolButton::Next]->setEnabled(true);
ui->svgView->hideBorders(true);
while (ui->toolBar->actions()[ToolButton::Next]->isEnabled()) //while "Next Sheet" tool button is enabled,
{ //i.e. while rendering all sheets
renderNextSheet();
currentFileName = fileName;
if (currentSheetNumber > 0 || ui->toolBar->actions()[ToolButton::Next]->isEnabled())
//i.e. there is more than one sheet
currentFileName.insert(indexOfExtension, QString("_%1").arg(currentSheetNumber));
saveSheet(currentFileName);
}
ui->svgView->hideBorders(false);
//we used renderNextSheet() for the first sheet instead of renderFirstSheet()
//so we need to check the number of sheet and disable previous toolbutton if needed
if (currentSheetNumber == 0)
ui->toolBar->actions()[ToolButton::Previous]->setDisabled(true);
}
示例14: QRegularExpression
void WebLoadManager::onMeta() {
QNetworkReply *reply = qobject_cast<QNetworkReply*>(QObject::sender());
if (!reply) return;
Replies::iterator j = _replies.find(reply);
if (j == _replies.cend()) { // handled already
return;
}
webFileLoaderPrivate *loader = j.value();
typedef QList<QNetworkReply::RawHeaderPair> Pairs;
Pairs pairs = reply->rawHeaderPairs();
for (Pairs::iterator i = pairs.begin(), e = pairs.end(); i != e; ++i) {
if (QString::fromUtf8(i->first).toLower() == "content-range") {
QRegularExpressionMatch m = QRegularExpression(qsl("/(\\d+)([^\\d]|$)")).match(QString::fromUtf8(i->second));
if (m.hasMatch()) {
loader->setProgress(qMax(qint64(loader->data().size()), loader->already()), m.captured(1).toLongLong());
if (!handleReplyResult(loader, WebReplyProcessProgress)) {
_replies.erase(j);
_loaders.remove(loader);
delete loader;
reply->abort();
reply->deleteLater();
}
}
}
}
}
示例15: set
void MCGUILayoutAxis::set(const QString &str) {
QString s = str;
if (s.size() <= 0)
return;
s.replace(" ", "");
QStringList a = s.split(QRegularExpression("(?=\\-|\\+)"));
components.clear();
for (QString p : a) {
if (p.length() <= 0)
continue;
int i = p.indexOf("%");
Component c;
if (i >= 0) {
c.value = p.midRef(0, i).toFloat() / 100.f;
if (p.endsWith("x"))
c.unit = Component::Unit::PERCENT_X;
else if (p.endsWith("y"))
c.unit = Component::Unit::PERCENT_Y;
else
c.unit = (axis == Axis::X ? Component::Unit::PERCENT_X : Component::Unit::PERCENT_Y);
} else {
if (p.endsWith("px"))
c.value = p.midRef(0, p.length() - 2).toFloat();
else
c.value = p.toFloat();
c.unit = Component::Unit::PIXELS;
}
components.push_back(c);
}
}