![]() |
|
||||||||
경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지 |
|
아래 코드가 컴파일이 안됩니다.
터보C 쪽에 있는 패치를 해도 에러가 나고, 부스트가 에럽네요...... 초보자는 접근 어려버요....... 쩝. //--------------------------------------- #include <iostream> #include <locale> #include <boost/regex.hpp> using std::cout; using std::wcout; using std::endl; void bad_search() { cout << "\nRegex++ can NOT support multibyte regex" << endl; std::string source = "アルファベットを含むShift_JIS文字列"; boost::reg_expression<char> regex = "[a-zA-Z]. *[a-zA-Z]"; boost::match_results<std::string::const_iterator> results; if ( boost::regex_search(source, results, regex) ) { cout << results. str(0) << endl; } } void good_search() { cout << "\nso let's try std::wstring & Regex++" << endl; std::wstring source = L"アルファベットを含むShift_JIS文字列"; boost::reg_expression<wchar_t> regex = L"[a-zA-Z]. *[a-zA-Z]"; boost::match_results<std::wstring::const_iterator> results; if ( boost::regex_search(source, results, regex) ) { wcout << results. str(0) << endl; } } void test_search() { cout << "\nregex_search for const char*" << endl; { const char* source = "here"; boost::reg_expression<char> regex = "(([a-z]+):)? //([^:/]+)(:([0-9]+))? /([a-zA-Z. 0-9]*)"; boost::match_results<const char*> results; cout << "URL = " << source << endl << "regex = " << regex. str() << endl; if ( boost::regex_search(source, results, regex) ) { cout << " scheme :" << results. str(2) << endl << " host :" << results. str(3) << endl << " port :" << results. str(5) << endl << " path :" << results. str(6) << endl; } else { cout << "no match. " << endl; } } cout << "\nregex_search for std::string" << endl; { std::string source = "here"; boost::reg_expression<std::string::value_type> regex = "(([a-z]+):)? //([^:/]+)(:([0-9]+))? /([a-zA-Z. 0-9]*)"; boost::match_results<std::string::const_iterator> results; cout << "URL = " << source << endl << "regex = " << regex. str() << endl; if ( boost::regex_search(source, results, regex) ) { cout << " scheme :" << results. str(2) << endl << " host :" << results. str(3) << endl << " port :" << results. str(5) << endl << " path :" << results. str(6) << endl; } else { cout << "no match. " << endl; } } } void test_wide_search() { cout << "\nregex_search for const wchar_t*" << endl; { const wchar_t* source = L"here"; boost::reg_expression<wchar_t> regex = L"(([a-z]+):)? //([^:/]+)(:([0-9]+))? /([a-zA-Z. 0-9]*)"; boost::match_results<const wchar_t*> results; wcout << L"URL = " << source << endl << L"regex = " << regex. str() << endl; if ( boost::regex_search(source, results, regex) ) { wcout << L" scheme :" << results. str(2) << endl << L" host :" << results. str(3) << endl << L" port :" << results. str(5) << endl << L" path :" << results. str(6) << endl; } else { cout << "no match. " << endl; } } cout << "\nregex_search for std::wstring" << endl; { std::wstring source = L"here"; boost::reg_expression<std::wstring::value_type> regex = L"(([a-z]+):)? //([^:/]+)(:([0-9]+))? /([a-zA-Z. 0-9]*)"; boost::match_results<std::wstring::const_iterator> results; wcout << L"URL = " << source << endl << L"regex = " << regex. str() << endl; if ( boost::regex_search(source, results, regex) ) { wcout << L" scheme :" << results. str(2) << endl << L" host :" << results. str(3) << endl << L" port :" << results. str(5) << endl << L" path :" << results. str(6) << endl; } else { cout << "no match. " << endl; } } } struct grep_predicate { bool operator()(const boost::match_results<std::string::const_iterator>& m) { cout << m. str(0) << endl; return true; } }; void test_grep() { cout << "\nregex_grep for std::string\n"; const std::string source = "My name is same as a name of a month"; boost::reg_expression<char> regex = ". ame"; boost::regex_grep(grep_predicate(), source. begin(), source. end(), regex); } struct grep_wide_predicate { bool operator()(const boost::match_results<std::wstring::const_iterator>& m) { wcout << m. str(0) << endl; return true; } }; void test_wide_grep() { cout << "\nregex_grep for std::wstring\n"; const std::wstring source = L"僕は海が好きで山が好きで川も好き"; boost::reg_expression<wchar_t> regex = L"(山|川)(.)好き"; boost::regex_grep(grep_wide_predicate(), source. begin(), source. end(), regex); } int main() { std::locale::global(std::locale("japanese")); bad_search(); good_search(); test_search(); test_wide_search(); test_grep(); test_wide_grep(); return 0; } 관련 글 리스트
|
Copyright © 1999-2015, borlandforum.com. All right reserved. |
설명해 주실수 없나요, 왜 부스트를 쓰야 하는지 그리고
코드에 주석을 ....
부탁 드릴께요