显示标签为“Boost”的博文。显示所有博文
显示标签为“Boost”的博文。显示所有博文

2008年2月26日星期二

Boost regex backslash 问题

regex eps_change_blash("\"); //throw exception causes of a "bad_pattern".The problem is that
//have to escape the backslash once because of how C literals are interpreted
//and again because of how characters in regular expressions are interpreted.

Lösung:
regex eps_change_blash("\\");
or:
boost::regex expression("\", boost::regbase::literal);






Beispiel: use sourceDB(c:\backup\dbinfo.mdb) to repalce c:/apo_work/dbinfo.mdb
comes the problem "c:backupdbinfo.mdb"
Lösung: \\\\ for just once \

CString CDBinfoListCt::replaceSourceDB(CString s)
{
regex eps_sql_sourceDB("^.*\'c:\/apo_work\/dbinfo\.mdb\'$");
regex eps_sql_change_sourceDB("(c:/apo_work/dbinfo\.mdb)");
regex eps_change_blash("\\\\"); // \\\\ backslash for c, for boost... god!!!

cmatch what; // a array to store the matching string

std::string stdReplace;
CString sTmp;
CString sTmpDB;


if(regex_match(s, what, eps_sql_sourceDB))
{


stdReplace = (LPCTSTR)sourceDB;
stdReplace = boost::regex_replace(stdReplace,eps_change_blash,"\\\\\\\\");
sTmpDB.Format("%s",stdReplace.c_str());

sTmp.Format("%s",what[0]);
stdReplace = (LPCTSTR)sTmp;
stdReplace = boost::regex_replace(stdReplace,eps_sql_change_sourceDB,(LPCTSTR)sTmpDB);

sTmp.Format("%s",stdReplace.c_str());
return sTmp;

}
else
{
return s;

}


}

2008年1月28日星期一

VC++ boost: regex应用

下载boost_1_34_1.zip,解压
安装:
  1、打开vs2005在菜单tools中选择Visual Studio 2005 Command Prompt,打开已配置好环境的命令行。
  2、进入目录boost_1_34_1\libs\regex\build,
  编译文件:nmake -f vc8.mak
  安装(将编译好的文件复制到vs2005的特定目录下):nmake -f vc8.mak install
  删除临时文件:nmake -f vc8.mak clean
  3、Tools->Options->Projects and Solutions->VC++ Directories->Include files添加boost_1_34_1路径

  初次使用提示找不到libboost_regex-vc80-mt-gd-1_34_1.lib文件,到网上搜了下解决方法为:将 libboost_regex-vc80-mt-gd-1_34.lib改名libboost_regex-vc80-mt-gd-1_34_1.lib 放到vs或工程目录下。
4.
#include <boost/regex.hpp>
using namespace boost;
...
regex expression("^([0-9]{8})_([0-9]{6})_([[:word:]]+)\.([[:word:]]+)\.gz$");
cmatch what; // a array to store the matching string
if(regex_match(sName, what, expression
{
...