【发布时间】:2016-12-08 17:38:06
【问题描述】:
我创建了这个正则表达式并使用该值打印成一个字符串。
std::string s (filename);
std::smatch m;
std::regex e ("\/(?:.(?!\/))+$");
while (std::regex_search (s,m,e)) {
for (auto p:m) std::cout << p << " ";
s = m.suffix().str();
}
std::string currFileName = s;
std::string Original = filename;
std::string newFile = Original + currFileName;
std::cout << newFile;
问题是它没有显示在终端中。
印值
/simple-loops.cc /home/fypj/build/simple-loops.cc
预期值
/home/fypj/build/simple-loops.cc/simple-loops.cc
你可能会问文件名是什么
llvm::StringRef filename;
SourceLocation ST = f->getSourceRange().getBegin();
filename = Rewrite.getSourceMgr().getFilename(ST);
【问题讨论】:
-
是的,那么文件名字符串是什么样的呢?打印出来的值和传入的一样吗?
-
@wiktorstribizew /home/fypj/build/simple-loops.cc/
-
是不是要截断最后一个
/处的字符串? -
@wiktorstribizew 是的