C++ (Qt) #include <ONE/someFileName.hpp> // <two/some_file_name.hpp>#include "ONE/someFileName.hpp" // "two/some_file_name.hpp"#include <any/ONE/someFileName.hpp> // <any/two/some_file_name.hpp>#include <anyONE/someFileName.hpp> // <anyONE/some_file_name.hpp> namespace ONE { // two someFunctionName(); // some_function_name();} namespace any { // any using namespace ONE; // two someFunctionName(); // some_function_name();} namespace ONE1 { // ONE1 namespace any2 { // any2 ::ONE::someFunctionName(); // ::two::some_function_name(); }} namespace ONEone { // ONEone namespace any2 { // any2 ::ONE::someFunctionName(); // ::two::some_function_name(); }} int main() { ONE::someFunctionName(); // two::some_function_name();}
QString str = "namespace ONE";QRegExp regExp("(\\D{3}$)");str.replace(regExp, "two");
QString str = "<ONE/someFileName.hpp>"; QList<QString> list; list.append("A"); list.append("B"); list.append("C"); list.append("D"); list.append("E"); list.append("F"); //... list.append("N"); //... QRegExp regExp("(<\\D{3})"); str.replace(regExp, "<two"); for (int i = 0; i < list.size(); i ++) { QRegExp regExp2("(" + list[i] + ")"); str.replace(regExp2, "_"+list[i].toLower()); } qDebug() << str;
#include <QtCore/QCoreApplication>#include <QFile>#include <QRegExp>#include <QDebug>QString Low(QString s){ QList<int> listIn; int index = 0; for (int i = 1;i < s.count();i++) { if (s[i].isUpper()) { listIn << i + index; index++; } } s = s.toLower(); for (int i = 0; i < listIn.count();i++) { s.insert(listIn[i],"_"); } return s;}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QFile file("in"); file.open(QIODevice::ReadOnly | QIODevice::WriteOnly); QString str = file.readAll(); QRegExp regex; regex.setPatternSyntax(QRegExp::RegExp); regex.setPattern("\\bONE/"); str.replace(regex,"tow/"); regex.setPattern("\\bONE::\\b"); str.replace(regex,"tow::"); regex.setPattern("\\bnamespace[^\\S]+ONE\\b"); str.replace(regex,"namespace tow"); regex.setPattern("\\b(\\S+)\\("); int pos = 0; while ((pos = regex.indexIn(str,pos)) != -1) { qDebug() << pos << regex.cap(1) << Low(regex.cap(1)); pos += regex.matchedLength(); str.replace(regex.cap(1),Low(regex.cap(1))); } regex.setPattern("\\b/(\\S+).hpp|\\b/(\\S+).h"); pos = 0; while ((pos = regex.indexIn(str,pos)) != -1) { qDebug() << pos << regex.cap(1) << Low(regex.cap(1)); pos += regex.matchedLength(); str.replace(regex.cap(1),Low(regex.cap(1))); } qDebug() << str; file.close(); return 0;}
#include <QtCore/QCoreApplication>#include <QFile>#include <QRegExp>#include <QDebug>QString Low(QString s){ QList<int> listIn; QRegExp reg; reg.setPatternSyntax(QRegExp::RegExp); reg.setPattern("\\b::(\\S+)"); if (reg.indexIn(s,0) != -1) { s.replace(reg.cap(1),Low(reg.cap(1))); return s; } int index = 0; for (int i = 1;i < s.count();i++) { if (s[i].isUpper()) { listIn << i + index; index++; } } s = s.toLower(); for (int i = 0; i < listIn.count();i++) { s.insert(listIn[i],"_"); } return s;}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QFile file("in"); file.open(QIODevice::ReadOnly | QIODevice::WriteOnly); QString str = file.readAll(); QRegExp regex; regex.setPatternSyntax(QRegExp::RegExp); regex.setPattern("\\bONE/"); str.replace(regex,"tow/"); regex.setPattern("\\bONE::\\b"); str.replace(regex,"tow::"); regex.setPattern("\\bnamespace[^\\S]+ONE\\b"); str.replace(regex,"namespace tow"); regex.setPattern("\\b(\\S+)\\("); int pos = 0; while ((pos = regex.indexIn(str,pos)) != -1) { qDebug() << pos << regex.cap(1) << Low(regex.cap(1)); pos += regex.matchedLength(); str.replace(regex.cap(1),Low(regex.cap(1))); } regex.setPattern("\\b/(\\S+).hpp|\\b/(\\S+).h"); pos = 0; while ((pos = regex.indexIn(str,pos)) != -1) { qDebug() << pos << regex.cap(1) << Low(regex.cap(1)); pos += regex.matchedLength(); str.replace(regex.cap(1),Low(regex.cap(1))); } qDebug() << str; file.close(); return 0;}