1/*
2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef REG_EXP_H
6#define REG_EXP_H
7
8
9#include <stddef.h>
10
11
12class RegExp {
13public:
14			enum PatternType {
15				PATTERN_TYPE_REGULAR_EXPRESSION,
16				PATTERN_TYPE_WILDCARD
17			};
18
19			class MatchResult;
20
21public:
22								RegExp();
23								RegExp(const char* pattern,
24									PatternType patternType
25										= PATTERN_TYPE_REGULAR_EXPRESSION,
26									bool caseSensitive = true);
27								RegExp(const RegExp& other);
28								~RegExp();
29
30			bool				IsValid() const
31									{ return fData != NULL; }
32
33			bool				SetPattern(const char* pattern,
34									PatternType patternType
35										= PATTERN_TYPE_REGULAR_EXPRESSION,
36									bool caseSensitive = true);
37
38			MatchResult			Match(const char* string) const;
39
40			RegExp&				operator=(const RegExp& other);
41
42private:
43			struct Data;
44			struct MatchResultData;
45
46private:
47			Data*				fData;
48};
49
50
51class RegExp::MatchResult {
52public:
53								MatchResult();
54								MatchResult(const MatchResult& other);
55								~MatchResult();
56
57			bool				HasMatched() const;
58
59			size_t				StartOffset() const;
60			size_t				EndOffset() const;
61
62			size_t				GroupCount() const;
63			size_t				GroupStartOffsetAt(size_t index) const;
64			size_t				GroupEndOffsetAt(size_t index) const;
65
66			MatchResult&		operator=(const MatchResult& other);
67
68private:
69			friend class RegExp;
70
71private:
72								MatchResult(MatchResultData* data);
73									// takes over the data reference
74
75private:
76			MatchResultData*	fData;
77};
78
79
80#endif	// REG_EXP_H
81