File: cxx11-test-regex.cpp

package info (click to toggle)
libvmime 0.9.2-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,552 kB
  • sloc: cpp: 55,419; ansic: 822; makefile: 88; sh: 8
file content (26 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <algorithm>
#include <regex>

int parse_line(std::string const& line)
{
	std::string tmp;
	if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+//(-)?(\\d)+(\\s)+"))) {
		tmp = std::regex_replace(line, std::regex("(-)?(\\d)+//(-)?(\\d)+"), std::string("V"));
	} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
		tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
	} else if(std::regex_search(line, std::regex("(\\s)+(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+(\\s)+"))) {
		tmp = std::regex_replace(line, std::regex("(-)?(\\d)+/(-)?(\\d)+/(-)?(\\d)+"), std::string("V"));
	} else {
		tmp = std::regex_replace(line, std::regex("(-)?(\\d)+"), std::string("V"));
	}
	return static_cast<int>(std::count(tmp.begin(), tmp.end(), 'V'));
}

int main()
{
	bool test = (parse_line("f 7/7/7 -3/3/-3 2/-2/2") == 3) &&
				(parse_line("f 7//7 3//-3 -2//2") == 3) &&
				(parse_line("f 7/7 3/-3 -2/2") == 3) &&
				(parse_line("f 7 3 -2") == 3);
	return test ? 0 : 1;
}