-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregex_index.h
40 lines (34 loc) · 1.23 KB
/
regex_index.h
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
40
/* -*- mode: C++; c-basic-offset: 4; tab-width: 8; -*-
* vi: set shiftwidth=4 tabstop=8:
* :indentSize=4:tabSize=8:
*/
#pragma once
#include "line.h"
#include <memory>
#include <regex>
/**
* parse regular expression flags string.
* Valid flags are 'i' and '!'.
* @param[in] flags string with regular expression flags.
* @param[out] fl std::regex flags.
* @param[out] positiveMatch false if the '!' flag was found; true otherwise.
* @throws std::runtime_error if an unknown flag was found.
*/
void convert(const std::string& flags, std::regex_constants::syntax_option_type& fl, bool& positiveMatch);
class regex_index
{
lineNum_vector_t lineNum_vector_;
std::regex rgx_;
bool positive_match_;
public:
/**
* create regular expression index object.
* @param rgx a (normalized) regular expression string.
* @throws std::runtime_error if regular expression could not be parsed.
*/
explicit regex_index(std::string rgx);
/// match line against the provisioned regular expression. If it matches add the line (number) to the set.
void match(const line_t& line);
unsigned size() const { return lineNum_vector_.size(); }
const lineNum_vector_t& lineNum_vector() { return lineNum_vector_; }
};