Ticket #7758: BoostRegexTest.cpp

File BoostRegexTest.cpp, 1.7 KB (added by david.ecker@…, 10 years ago)

cpp file

Line 
1// BoostRegexTest.cpp : Defines the entry point for the console application.
2//
3
4
5//#define BOOST_REGEX_NON_RECURSIVE
6#include "stdafx.h"
7#include <fstream>
8#include <string>
9#include <boost\regex.hpp>
10
11int _tmain(int argc, _TCHAR* argv[])
12{
13 // Hier mache ich jetzt den Boost Regex Test
14 std::string a_OutputString;
15
16 std::string a_InputString = "";
17 std::string a_RegExString = ".*?\r\n(version .*?\r\n)";
18
19 std::ifstream fs("Session.txt");
20 std::string tmp;
21 while (!fs.eof())
22 {
23 getline(fs,tmp);
24 a_InputString += tmp + "\r\n";
25 }
26
27 fs.close();
28
29 bool a_IsIgnoreCase = true;
30 bool a_IsMatchNotDotNewline = false;
31 bool a_IsMatchSingleLine = false;
32 bool a_IsFormatAll = true;
33 bool a_IsFormatNoCopy = true;
34
35 if( !a_InputString.empty() && !a_RegExString.empty() )
36 {
37 {
38 boost::regex::flag_type a_RegExFlags = 0;
39 boost::regex_constants::match_flag_type a_RegExMatchFlags = boost::regex_constants::format_default;
40
41 if( a_IsIgnoreCase ) a_RegExFlags |= boost::regex::icase;
42
43 boost::regex a_Expression( a_RegExString, a_RegExFlags );
44
45 {
46 if( a_IsMatchNotDotNewline ) a_RegExMatchFlags |= boost::match_not_dot_newline;
47 if( a_IsMatchSingleLine ) a_RegExMatchFlags |= boost::match_single_line;
48
49 boost::sregex_iterator a_RegCheckIterator;
50 boost::sregex_iterator a_RegIterator( a_InputString.begin(), a_InputString.end(), a_Expression, a_RegExMatchFlags );
51
52 a_OutputString.reserve( a_InputString.length() );
53
54 while( a_RegIterator != a_RegCheckIterator )
55 {
56 for ( size_t i = 1; i < (*a_RegIterator).size(); i++ )
57 {
58 a_OutputString += (*a_RegIterator)[i].str().c_str();
59 }
60 a_RegIterator++;
61 }
62 }
63 }
64 }
65 return 0;
66}
67