Boost_regex のバックアップの現在との差分(No.1) - アールメカブ

アールメカブ


Boost_regex のバックアップの現在との差分(No.1)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
[[Programming]]

 //g++ boostSample.cpp -lboost_regex
 #include <iostream>
 #include <string>
 #include <locale>
 #include <boost/regex.hpp>
 using namespace std;
 
 int main()
 {
  locale::global(locale("ja_JP.UTF-8"));//必須
  wcout.imbue(std::locale("ja_JP.UTF-8"));//必須
  wcin.imbue(std::locale("ja_JP.UTF-8"));//必須
 
  //    VC7(windows) 用には
  //    wcout.imbue(std::locale("japanese"));
  //    wcin.imbue(std::locale("japanese"));
  //    setlocale(LC_CTYPE, "") というして方法もある
 
  boost::wregex target(L"(.)れは");
  wstring str = L"これはペンです。\
         this is a park それは公園です。\
         あれは本です。";
 // 発見した箇所すべてを表示するための変数
 //例えば VC7 では有効
	// Linux euc terminalでは表示はされない
  wstring::const_iterator it = str.begin(), end = str.end();
  while(it != end){
	boost::wsmatch result;
 // typedef match_results wsmatch; として定義されている
 //http://boost.cppll.jp/HEAD/libs/regex/doc/match_results.html
	if(!boost::regex_search(it, end, result, target))
	  break;
	
	wcout << result.str() << endl;
	it = result[0].second;
  }
  
  return 0;
 }
Makefile
 # BOOST_LIB = /usr/lib64
 # BOOST_INC = /usr/include/boost
 CC     = g++
 OPT    = -O3
 DEBUG  = -g -Wall
 CFLAGS = $(DEBUG)
 TARGET = boost.test
 SRCS = boost.test.cpp
 OBJS = boost.test.o
 
 INCDIR = -I$(BOOST_INC)
 
 .SUFFIXES: .cc .cpp .o .x
 
 $(TARGET): $(OBJS)
	$(CC) -o $@ $(OBJS)   $(BOOST_LIB)/libboost_regex.a 2>&1 | c++filt
 
 .cpp.o:
	$(CC) $(CFLAGS) $(INCDIR) -c $<
 
 .cc.o:
	$(CC) $(CFLAGS) $(INCDIR) -c $<
 
 clean: