modernize C++: raw string literal

This commit is contained in:
wmayer
2023-08-07 16:02:39 +02:00
committed by Chris Hennes
parent 61daaceb8f
commit 96aabe113e
21 changed files with 48 additions and 46 deletions

View File

@@ -921,7 +921,7 @@ std::string Document::getTransientDirectoryName(const std::string& uuid, const s
void Document::Save (Base::Writer &writer) const
{
writer.Stream() << "<Document SchemaVersion=\"4\" ProgramVersion=\""
writer.Stream() << R"(<Document SchemaVersion="4" ProgramVersion=")"
<< App::Application::Config()["BuildVersionMajor"] << "."
<< App::Application::Config()["BuildVersionMinor"] << "R"
<< App::Application::Config()["BuildRevision"]
@@ -1072,11 +1072,11 @@ void Document::exportObjects(const std::vector<App::DocumentObject*>& obj, std::
Base::ZipWriter writer(out);
writer.putNextEntry("Document.xml");
writer.Stream() << "<?xml version='1.0' encoding='utf-8'?>" << endl;
writer.Stream() << "<Document SchemaVersion=\"4\" ProgramVersion=\""
<< App::Application::Config()["BuildVersionMajor"] << "."
<< App::Application::Config()["BuildVersionMinor"] << "R"
<< App::Application::Config()["BuildRevision"]
<< "\" FileVersion=\"1\">" << endl;
writer.Stream() << R"(<Document SchemaVersion="4" ProgramVersion=")"
<< App::Application::Config()["BuildVersionMajor"] << "."
<< App::Application::Config()["BuildVersionMinor"] << "R"
<< App::Application::Config()["BuildRevision"]
<< R"(" FileVersion="1">)" << endl;
// Add this block to have the same layout as for normal documents
writer.Stream() << "<Properties Count=\"0\">" << endl;
writer.Stream() << "</Properties>" << endl;

View File

@@ -265,7 +265,7 @@ void PropertyExpressionEngine::Save(Base::Writer &writer) const
writer.Stream() << "\">" << std::endl;
writer.incInd();
} else {
writer.Stream() << "\" xlink=\"1\">" << std::endl;
writer.Stream() << R"(" xlink="1">)" << std::endl;
writer.incInd();
PropertyExpressionContainer::Save(writer);
}

View File

@@ -156,7 +156,7 @@ void PropertyPythonObject::loadPickle(const std::string& str)
Base::PyGILStateLocker lock;
try {
std::string buffer = str;
boost::regex pickle("S'(\\w+)'.+S'(\\w+)'\\n");
boost::regex pickle(R"(S'(\w+)'.+S'(\w+)'\n)");
boost::match_results<std::string::const_iterator> what;
std::string::const_iterator start, end;
start = buffer.begin();
@@ -271,7 +271,7 @@ void PropertyPythonObject::Save (Base::Writer &writer) const
repr = Base::base64_encode((const unsigned char*)repr.c_str(), repr.size());
std::string val = /*encodeValue*/(repr);
writer.Stream() << writer.ind() << "<Python value=\"" << val
<< "\" encoded=\"yes\"";
<< R"(" encoded="yes")";
Base::PyGILStateLocker lock;
try {
@@ -324,7 +324,7 @@ void PropertyPythonObject::Restore(Base::XMLReader &reader)
Base::PyGILStateLocker lock;
try {
boost::regex pickle("^\\(i(\\w+)\\n(\\w+)\\n");
boost::regex pickle(R"(^\(i(\w+)\n(\w+)\n)");
boost::match_results<std::string::const_iterator> what;
std::string::const_iterator start, end;
start = buffer.begin();

View File

@@ -707,7 +707,7 @@ void CallTipsList::callTipItemActivated(QListWidgetItem *item)
* Try to find out if call needs arguments.
* For this we search the description for appropriate hints ...
*/
QRegularExpression argumentMatcher( QRegularExpression::escape( callTip.name ) + QLatin1String("\\s*\\(\\s*\\w+.*\\)") );
QRegularExpression argumentMatcher( QRegularExpression::escape( callTip.name ) + QLatin1String(R"(\s*\(\s*\w+.*\))") );
argumentMatcher.setPatternOptions( QRegularExpression::InvertedGreedinessOption ); //< set regex non-greedy!
if (argumentMatcher.match( callTip.description ).hasMatch())
{

View File

@@ -94,7 +94,7 @@ void StdCmdWorkbench::activated(int i)
QString msg(QLatin1String(e.what()));
// ignore '<type 'exceptions.*Error'>' prefixes
QRegularExpression rx;
rx.setPattern(QLatin1String("^\\s*<type 'exceptions.\\w*'>:\\s*"));
rx.setPattern(QLatin1String(R"(^\s*<type 'exceptions.\w*'>:\s*)"));
auto match = rx.match(msg);
if (match.hasMatch())
msg = msg.mid(match.capturedLength());

View File

@@ -48,7 +48,7 @@ DlgCreateNewPreferencePackImp::DlgCreateNewPreferencePackImp(QWidget* parent)
{
ui->setupUi(this);
QRegularExpression validNames(QString::fromUtf8("[^/\\\\?%*:|\"<>]+"));
QRegularExpression validNames(QString::fromUtf8(R"([^/\\?%*:|"<>]+)"));
_nameValidator.setRegularExpression(validNames);
ui->lineEdit->setValidator(&_nameValidator);
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);

View File

@@ -237,7 +237,7 @@ void DlgSettingsImageImp::onStandardSizeBoxActivated(int index)
else {
// try to extract from the string
QString text = ui->standardSizeBox->itemText(index);
QRegularExpression rx(QLatin1String("\\b\\d{2,5}\\b"));
QRegularExpression rx(QLatin1String(R"(\b\d{2,5}\b)"));
int pos = 0;
auto match = rx.match(text, pos);
if (match.hasMatch()) {

View File

@@ -86,7 +86,7 @@ FileDialog::~FileDialog()
void FileDialog::onSelectedFilter(const QString& /*filter*/)
{
QRegularExpression rx(QLatin1String("\\(\\*.(\\w+)"));
QRegularExpression rx(QLatin1String(R"(\(\*.(\w+))"));
QString suf = selectedNameFilter();
auto match = rx.match(suf);
if (match.hasMatch()) {
@@ -186,7 +186,7 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
}
QRegularExpression rx;
rx.setPattern(QLatin1String("\\s(\\(\\*\\.\\w{1,})\\W"));
rx.setPattern(QLatin1String(R"(\s(\(\*\.\w{1,})\W)"));
auto match = rx.match(*filterToSearch);
if (match.hasMatch()) {
int index = match.capturedStart();
@@ -498,7 +498,7 @@ void FileOptionsDialog::accept()
else if (!fn.isEmpty()) {
QFileInfo fi(fn);
QString ext = fi.completeSuffix();
QRegularExpression rx(QLatin1String("\\(\\*.(\\w+)"));
QRegularExpression rx(QLatin1String(R"(\(\*.(\w+))"));
QString suf = selectedNameFilter();
auto match = rx.match(suf);
if (match.hasMatch())
@@ -869,7 +869,7 @@ SelectModule::SelectModule (const QString& type, const SelectModule::Dict& types
QString module = it.value();
// ignore file types in (...)
rx.setPattern(QLatin1String("\\s+\\([\\w\\*\\s\\.]+\\)$"));
rx.setPattern(QLatin1String(R"(\s+\([\w\*\s\.]+\)$)"));
auto match = rx.match(filter);
if (match.hasMatch()) {
filter = filter.left(match.capturedStart());

View File

@@ -149,13 +149,13 @@ void MDIView::onRelabel(Gui::Document *pDoc)
// Try to separate document name and view number if there is one
QString cap = windowTitle();
// Either with dirty flag ...
QRegularExpression rx(QLatin1String("(\\s\\:\\s\\d+\\[\\*\\])$"));
QRegularExpression rx(QLatin1String(R"((\s\:\s\d+\[\*\])$)"));
QRegularExpressionMatch match;
//int pos =
boost::ignore_unused(cap.lastIndexOf(rx, -1, &match));
if (!match.hasMatch()) {
// ... or not
rx.setPattern(QLatin1String("(\\s\\:\\s\\d+)$"));
rx.setPattern(QLatin1String(R"((\s\:\s\d+)$)"));
//pos =
boost::ignore_unused(cap.lastIndexOf(rx, -1, &match));
}

View File

@@ -274,7 +274,7 @@ void PlacementHandler::applyPlacement(App::DocumentObject* obj, const QString& d
QString PlacementHandler::getIncrementalPlacement(App::DocumentObject* obj, const QString& data) const
{
return QString::fromLatin1(
"App.getDocument(\"%1\").%2.%3=%4.multiply(App.getDocument(\"%1\").%2.%3)")
R"(App.getDocument("%1").%2.%3=%4.multiply(App.getDocument("%1").%2.%3))")
.arg(QString::fromLatin1(obj->getDocument()->getName()),
QString::fromLatin1(obj->getNameInDocument()),
QString::fromLatin1(this->propertyName.c_str()),

View File

@@ -333,7 +333,7 @@ void SelectionView::select(QListWidgetItem* item)
//Gui::Selection().clearSelection();
Gui::Command::runCommand(Gui::Command::Gui,"Gui.Selection.clearSelection()");
//Gui::Selection().addSelection(elements[0].toLatin1(),elements[1].toLatin1(),0);
QString cmd = QString::fromLatin1("Gui.Selection.addSelection(App.getDocument(\"%1\").getObject(\"%2\"))").arg(elements[0],elements[1]);
QString cmd = QString::fromLatin1(R"(Gui.Selection.addSelection(App.getDocument("%1").getObject("%2")))").arg(elements[0],elements[1]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
}catch(Base::Exception &e) {
e.ReportException();
@@ -350,7 +350,7 @@ void SelectionView::deselect()
return;
//Gui::Selection().rmvSelection(elements[0].toLatin1(),elements[1].toLatin1(),0);
QString cmd = QString::fromLatin1("Gui.Selection.removeSelection(App.getDocument(\"%1\").getObject(\"%2\"))").arg(elements[0],elements[1]);
QString cmd = QString::fromLatin1(R"(Gui.Selection.removeSelection(App.getDocument("%1").getObject("%2")))").arg(elements[0],elements[1]);
try {
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
}catch(Base::Exception &e) {
@@ -457,7 +457,7 @@ void SelectionView::touch()
QStringList elements = item->data(Qt::UserRole).toStringList();
if (elements.size() < 2)
return;
QString cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").touch()").arg(elements[0],elements[1]);
QString cmd = QString::fromLatin1(R"(App.getDocument("%1").getObject("%2").touch())").arg(elements[0],elements[1]);
try {
Gui::Command::runCommand(Gui::Command::Doc,cmd.toLatin1());
}catch(Base::Exception &e) {
@@ -475,19 +475,19 @@ void SelectionView::toPython()
return;
try {
QString cmd = QString::fromLatin1("obj = App.getDocument(\"%1\").getObject(\"%2\")").arg(elements[0], elements[1]);
QString cmd = QString::fromLatin1(R"(obj = App.getDocument("%1").getObject("%2"))").arg(elements[0], elements[1]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
if (elements.length() > 2) {
App::Document* doc = App::GetApplication().getDocument(elements[0].toLatin1());
App::DocumentObject* obj = doc->getObject(elements[1].toLatin1());
QString property = getProperty(obj);
cmd = QString::fromLatin1("shp = App.getDocument(\"%1\").getObject(\"%2\").%3")
cmd = QString::fromLatin1(R"(shp = App.getDocument("%1").getObject("%2").%3)")
.arg(elements[0], elements[1], property);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
if (supportPart(obj, elements[2])) {
cmd = QString::fromLatin1("elt = App.getDocument(\"%1\").getObject(\"%2\").%3.%4")
cmd = QString::fromLatin1(R"(elt = App.getDocument("%1").getObject("%2").%3.%4)")
.arg(elements[0], elements[1], property, elements[2]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
}
@@ -512,7 +512,7 @@ void SelectionView::showPart()
if (!module.isEmpty() && !property.isEmpty() && supportPart(obj, elements[2])) {
try {
Gui::Command::addModule(Gui::Command::Gui, module.toLatin1());
QString cmd = QString::fromLatin1("%1.show(App.getDocument(\"%2\").getObject(\"%3\").%4.%5)")
QString cmd = QString::fromLatin1(R"(%1.show(App.getDocument("%2").getObject("%3").%4.%5))")
.arg(module, elements[0], elements[1], property, elements[2]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
}

View File

@@ -592,7 +592,7 @@ void Gui::SoFCDB::writeX3D(SoVRMLGroup* node, bool exportViewpoints, std::ostrea
<< "\" centerOfRotation=\"" << cnt[0] << " " << cnt[1] << " " << cnt[2]
<< "\" position=\"" << pos[0] << " " << pos[1] << " " << pos[2]
<< "\" orientation=\"" << axis[0] << " " << axis[1] << " " << axis[2] << " " << angle
<< "\" description=\"camera\" fieldOfView=\"0.9\">"
<< R"(" description="camera" fieldOfView="0.9">)"
<< "</Viewpoint>\n";
};

View File

@@ -402,11 +402,11 @@ SoFCVectorizeSVGAction::getSVGOutput() const
void SoFCVectorizeSVGAction::printHeader() const
{
std::ostream& str = this->getSVGOutput()->getFileStream();
str << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" << std::endl;
str << R"(<?xml version="1.0" encoding="UTF-8" standalone="no"?>)" << std::endl;
str << "<!-- Created with FreeCAD (http://www.freecad.org) -->" << std::endl;
str << "<svg xmlns=\"http://www.w3.org/2000/svg\"" << std::endl;
str << " xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ev=\"http://www.w3.org/2001/xml-events\"" << std::endl;
str << " version=\"1.1\" baseProfile=\"full\"" << std::endl;
str << R"( xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events")" << std::endl;
str << R"( version="1.1" baseProfile="full")" << std::endl;
SbVec2f size = getPageSize();
if (this->getOrientation() == LANDSCAPE) {

View File

@@ -204,7 +204,7 @@ public:
}
else {
// ignore activation of commands
rx.setPattern(QLatin1String("^\\s*(\\+App::|Create|CmdC:|CmdG:|Act:)\\s*"));
rx.setPattern(QLatin1String(R"(^\s*(\+App::|Create|CmdC:|CmdG:|Act:)\s*)"));
match = rx.match(msg);
if (match.hasMatch() && match.capturedStart() == 0)
return;

View File

@@ -46,8 +46,8 @@ ReaderOBJ::ReaderOBJ(MeshKernel& kernel, Material* material)
bool ReaderOBJ::Load(std::istream &str)
{
boost::regex rx_m("^mtllib\\s+(.+)\\s*$");
boost::regex rx_u("^usemtl\\s+([\\x21-\\x7E]+)\\s*$");
boost::regex rx_g("^g\\s+([\\x21-\\x7E]+)\\s*$");
boost::regex rx_u(R"(^usemtl\s+([\x21-\x7E]+)\s*$)");
boost::regex rx_g(R"(^g\s+([\x21-\x7E]+)\s*$)");
boost::regex rx_p("^v\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)"
"\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)"
"\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)\\s*$");

View File

@@ -412,7 +412,7 @@ bool MeshInput::LoadSMF (std::istream &rstrIn)
bool MeshInput::LoadOFF (std::istream &rstrIn)
{
// http://edutechwiki.unige.ch/en/3D_file_format
boost::regex rx_n("^\\s*([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s*$");
boost::regex rx_n(R"(^\s*([0-9]+)\s+([0-9]+)\s+([0-9]+)\s*$)");
boost::cmatch what;
bool colorPerVertex = false;
@@ -842,7 +842,7 @@ bool MeshInput::LoadPLY (std::istream &inp)
boost::regex rx_d("(([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?))\\s*");
boost::regex rx_s("\\b([-+]?[0-9]+)\\s*");
boost::regex rx_u("\\b([0-9]+)\\s*");
boost::regex rx_f("^\\s*3\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s*");
boost::regex rx_f(R"(^\s*3\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s*)");
boost::smatch what;
for (std::size_t i = 0; i < v_count && std::getline(inp, line); i++) {
@@ -1066,7 +1066,7 @@ bool MeshInput::LoadMeshNode (std::istream &rstrIn)
boost::regex rx_p("^v\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)"
"\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)"
"\\s+([-+]?[0-9]*)\\.?([0-9]+([eE][-+]?[0-9]+)?)\\s*$");
boost::regex rx_f("^f\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s*$");
boost::regex rx_f(R"(^f\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s*$)");
boost::regex rx_e("\\s*]\\s*");
boost::cmatch what;
@@ -2716,7 +2716,7 @@ bool MeshOutput::SaveX3DContent (std::ostream &out, bool exportViewpoints) const
out.setf(std::ios::fixed | std::ios::showpoint);
// Header info
out << "<X3D profile=\"Immersive\" version=\"3.2\" xmlns:xsd="
out << R"(<X3D profile="Immersive" version="3.2" xmlns:xsd=)"
<< "\"http://www.w3.org/2001/XMLSchema-instance\" xsd:noNamespaceSchemaLocation="
<< "\"http://www.web3d.org/specifications/x3d-3.2.xsd\" width=\"1280px\" height=\"1024px\">\n";
out << " <head>\n"
@@ -2735,7 +2735,7 @@ bool MeshOutput::SaveX3DContent (std::ostream &out, bool exportViewpoints) const
<< "\" centerOfRotation=\"" << cnt.x << " " << cnt.y << " " << cnt.z
<< "\" position=\"" << pos.x << " " << pos.y << " " << pos.z
<< "\" orientation=\"" << axis.x << " " << axis.y << " " << axis.z << " " << angle
<< "\" description=\"camera\" fieldOfView=\"0.9\">"
<< R"(" description="camera" fieldOfView="0.9">)"
<< "</Viewpoint>\n";
};

View File

@@ -1323,7 +1323,7 @@ void CmdPartMakeFace::activated(int iMsg)
App::DocumentT doc(sketches.front()->getDocument());
std::stringstream str;
str << doc.getDocumentPython()
<< ".addObject(\"Part::Face\", \"Face\").Sources = (";
<< R"(.addObject("Part::Face", "Face").Sources = ()";
for (auto &obj : sketches) {
str << App::DocumentObjectT(obj).getObjectPython() << ", ";
}

View File

@@ -142,7 +142,7 @@ bool Mirroring::accept()
activeDoc->openTransaction("Mirroring");
QString shape, label;
QRegularExpression rx(QString::fromLatin1(" \\(Mirror #\\d+\\)$"));
QRegularExpression rx(QString::fromLatin1(R"( \(Mirror #\d+\)$)"));
QList<QTreeWidgetItem *> items = ui->shapes->selectedItems();
float normx=0, normy=0, normz=0;
int index = ui->comboBox->currentIndex();

View File

@@ -211,7 +211,7 @@ QString TaskSketchBasedParameters::getFaceReference(const QString& obj, const QS
if (o.isEmpty())
return QString();
return QString::fromLatin1("(App.getDocument(\"%1\").%2, [\"%3\"])")
return QString::fromLatin1(R"((App.getDocument("%1").%2, ["%3"]))")
.arg(QString::fromLatin1(doc->getName()), o, sub);
}

View File

@@ -144,8 +144,10 @@ void FitBSplineSurfaceWidget::onMakePlacementClicked()
.arg(q3);
QString document = QString::fromStdString(d->obj.getDocumentPython());
QString command = QString::fromLatin1("%1.addObject(\"App::Placement\", \"Placement\").Placement = %2")
.arg(document, argument);
QString command =
QString::fromLatin1(
R"(%1.addObject("App::Placement", "Placement").Placement = %2)"
).arg(document, argument);
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Placement"));
Gui::Command::runCommand(Gui::Command::Doc, "from FreeCAD import Base");

View File

@@ -373,7 +373,7 @@ void PropertySheet::Save(Base::Writer &writer) const
}
writer.Stream() << writer.ind() << "<Cells Count=\"" << count
<< "\" xlink=\"1\">" << std::endl;
<< R"(" xlink="1">)" << std::endl;
writer.incInd();