C++入門/正規表現1
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
''[[FrontPage]]''
* C++と正規表現(regex++) テストその1 [#k9df5326]
C/C++言語ソースファイルを想定し、正規表現を使って解析する...
[[C++入門/正規表現2]]~
[[C++入門/正規表現3]]
** 制約 [#i68b3c78]
MFC、.NET関数を使用しないこと。~
~
#include <string> ...
#include <iostream> ...
#include <boost/regex.hpp> ...
#include <tchar.h> ...
// # include "x.x.h" ...
...
using namespace std; ...
using namespace boost; ...
...
...
regex targetI( ...
"#[[:space:]]*(include)" ...
"[[:space:]]*L*\"" ...
"(.*?" ...
"\.[hc]p{0,2})" ...
"\"" ); ...
...
char main( void ) ...
{ ...
const string file( ...
"#include <windows.h> \n" ...
"#include \"me.h.h\" \n" ...
"#include \"stuff.cpp\""); ...
...
string::const_iterator start; ...
string::const_iterator end; ...
...
start = file.begin(); ...
end = file.end(); ...
...
smatch partial; ...
match_flag_type flags = match_default; ...
...
while(regex_search(start, end, partial, targetI, fla...
{ ...
cout << ...
"partial[0] = " << partial[0] << ...
"\npartial[1] = " << partial[1] << ...
"\npartial[2] = " << partial[2] << ...
"\npartial[3] = " << partial[3] << ...
"\npartial[4] = " << partial[4] << ...
'\n' <<endl; ...
...
start = partial[0].second; ...
...
flags |= match_prev_avail; ...
flags |= match_not_bob; ...
} ...
...
getchar(); ...
return 0; ...
}
*** 修正履歴 [#ae17ed05]
boost、regexライブラリのビルドに成功。~
*** 課題 [#h8bd802d]
インクルードファイル名が"xxxx.h.h"のように、複数のピリオ...
defineによる定数定義が、文字定数によって行われていたら?
#define CHAR_THREE '3' // ソースとしては問題のない...
今はcoutで画面表示に成功しているが、UNICODE対応(wsmatch使...
むしろ、sub_matchが文字列として表示されていることが奇跡的?
終了行:
''[[FrontPage]]''
* C++と正規表現(regex++) テストその1 [#k9df5326]
C/C++言語ソースファイルを想定し、正規表現を使って解析する...
[[C++入門/正規表現2]]~
[[C++入門/正規表現3]]
** 制約 [#i68b3c78]
MFC、.NET関数を使用しないこと。~
~
#include <string> ...
#include <iostream> ...
#include <boost/regex.hpp> ...
#include <tchar.h> ...
// # include "x.x.h" ...
...
using namespace std; ...
using namespace boost; ...
...
...
regex targetI( ...
"#[[:space:]]*(include)" ...
"[[:space:]]*L*\"" ...
"(.*?" ...
"\.[hc]p{0,2})" ...
"\"" ); ...
...
char main( void ) ...
{ ...
const string file( ...
"#include <windows.h> \n" ...
"#include \"me.h.h\" \n" ...
"#include \"stuff.cpp\""); ...
...
string::const_iterator start; ...
string::const_iterator end; ...
...
start = file.begin(); ...
end = file.end(); ...
...
smatch partial; ...
match_flag_type flags = match_default; ...
...
while(regex_search(start, end, partial, targetI, fla...
{ ...
cout << ...
"partial[0] = " << partial[0] << ...
"\npartial[1] = " << partial[1] << ...
"\npartial[2] = " << partial[2] << ...
"\npartial[3] = " << partial[3] << ...
"\npartial[4] = " << partial[4] << ...
'\n' <<endl; ...
...
start = partial[0].second; ...
...
flags |= match_prev_avail; ...
flags |= match_not_bob; ...
} ...
...
getchar(); ...
return 0; ...
}
*** 修正履歴 [#ae17ed05]
boost、regexライブラリのビルドに成功。~
*** 課題 [#h8bd802d]
インクルードファイル名が"xxxx.h.h"のように、複数のピリオ...
defineによる定数定義が、文字定数によって行われていたら?
#define CHAR_THREE '3' // ソースとしては問題のない...
今はcoutで画面表示に成功しているが、UNICODE対応(wsmatch使...
むしろ、sub_matchが文字列として表示されていることが奇跡的?
ページ名: