File: results.cpp

package info (click to toggle)
ctre 3.9.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 5,084 kB
  • sloc: cpp: 80,452; makefile: 135; javascript: 69; python: 31
file content (39 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download | duplicates (2)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <ctre.hpp>
#include <iostream>

static constexpr auto pattern = ctll::fixed_string("(?<first>[0-9])[0-9]++");

int main() {
	using namespace std::string_view_literals;
	auto input = "123,456,768"sv;
	
	for (auto match: ctre::search_all<pattern>(input)) {
		
		if (match == "456") std::cout << "bingo: ";
		if (match != "768") std::cout << "bad: ";
		
		if ("456" == match) std::cout << "bingo: ";
		if ("768" != match) std::cout << "bad: ";
		
		auto capture = match.get<1>();
		
		if (capture == "456") std::cout << "bingo: ";
		if (capture != "768") std::cout << "bad: ";
		
		if ("456" == capture) std::cout << "bingo: ";
		if ("768" != capture) std::cout << "bad: ";
		
		[[maybe_unused]] const char * ptr = std::data(match);
		[[maybe_unused]] size_t length = std::size(match);
		
		[[maybe_unused]] const char * ptr2 = std::data(capture);
		[[maybe_unused]] size_t length2 = std::size(capture);
		
		//auto [ptr, err] = std::from_chars(std::data(match), std::data(match)+std::size(match), value);
		//if (err == std::errc{}) {
		//	std::cout << value << "\n";
		//} else {
		//	std::cout << "error\n";
		//}
	}
}