extension_switchのxpressive対応

久々に、extension_switchを改造してxpressiveに対応出来るようにしました。

git https://github.com/yamada28go/extension_switch

今回の特徴は、正規表現の判定対象となる文字列の型指定が出来るようにした事です。
以下の例では、普通のstd::string型を対象としています。
この指定は、xpressive::match::regex関数の第一型指定で行います。

result verification(const std::string & line)
{
	using namespace extension_switch;
	using namespace boost::xpressive;
	return _switch
		(line,
		 xpressive::match::regex< xpressive::target::string >
		 ( sregex(  +_d ) ,
		  []( const smatch & result )
		  {
		    std::cout << "This line is digits only." << std::endl;
		    return case4::result::digits_only;
		  }),
		 xpressive::match::regex< xpressive::target::string >
		 ( sregex( +range('a','z') ),
		[](const smatch & result)
		   {
		     std::cout << "This line is lower case." << std::endl;
		     return case4::result::lower_case;
		   }),
		 xpressive::match::regex< xpressive::target::string >
		 ( sregex( +range('A','Z') ),
		[](const smatch & result)
		   {
		     std::cout << "This line is upper case." << std::endl;
		     return case4::result::upper_case;
		   }),
		 xpressive::match::regex< xpressive::target::string >
		 ( sregex( bos >> as_xpr("This year is ") >> (s1=+_d) >> as_xpr(".") >> eos ),
		   [](const smatch & result )
		   {
		    std::cout << "Year number is " << result.str(1) << "." << std::endl;
		    return case4::result::get_yesr_number;
		   }),
		 match::other
		 ([](const boost::any & ref)
		  {
		    std::cout << "default type" << std::endl;
		    return case4::result::other;
		  })
		 );
}

以下の例では、const char型を正規表現の対象とするように調整しています。

result verification(const char * line)
{
	using namespace extension_switch;
	using namespace boost::xpressive;
	return _switch
		(line,
		 xpressive::match::regex< xpressive::target::c_char >
		 ( cregex(  +_d ) ,
		  []( const cmatch & result )
		  {
		    std::cout << "This line is digits only." << std::endl;
		    return case5::result::digits_only;
		  }),
		 xpressive::match::regex< xpressive::target::c_char >
		 ( cregex( +range('a','z') ),
		[](const cmatch & result)
		   {
		     std::cout << "This line is lower case." << std::endl;
		     return case5::result::lower_case;
		   }),
		 xpressive::match::regex< xpressive::target::c_char >
		 ( cregex( +range('A','Z') ),
		[](const cmatch & result)
		   {
		     std::cout << "This line is upper case." << std::endl;
		     return case5::result::upper_case;
		   }),
		 xpressive::match::regex< xpressive::target::c_char >
		 ( cregex( bos >> as_xpr("This year is ") >> (s1=+_d) >> as_xpr(".") >> eos ),
		   [](const cmatch & result )
		   {
		    std::cout << "Year number is " << result.str(1) << "." << std::endl;
		    return case5::result::get_yesr_number;
		   }),
		 match::other
		 ([](const boost::any & ref)
		  {
		    std::cout << "default type" << std::endl;
		    return case5::result::other;
		  })
		 );

}

普通のboost::regexに対応した時は、このあたりの実装がいい加減でしたヽ(;´Д`)ノ

その他の修正事項として、ロギングモードを強化しました。
マクロ「__EXTENSION_SWITCH_DEBUG_MODE__」が定義されている場合、デバッグマクロが表示されるようになります(〃▽〃)

同じ正規表現処理なのに、xpressive側とregexで記法がずれる状態になってしまいましたヽ(;´Д`)ノ
gccの次のバージョン?からlibstdc++にもregexが入りそうなので、regex関係の技術方法を合わせるように修正したいと思います(´・ω・`)

参考につせて頂いたサイト
・boost::xpressive 静的正規表現で書いてみた
http://hippos-lab.com/blog/node/400
正規表現判定対象型と正規表現オブジェクトの対比

・公式ドキュメントの日本語訳
http://alpha.sourceforge.jp/devel/boost.xpressive_ja_1_45_0.pdf