Import RegExp classes from Ham.

Minor adjustments made by myself to fit into Haiku better.
This commit is contained in:
Rene Gollent
2013-06-05 22:02:42 -04:00
parent 58535f5a9a
commit 47fedeb598
3 changed files with 465 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright 2013, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#ifndef REG_EXP_H
#define REG_EXP_H
#include <stddef.h>
class RegExp {
public:
enum PatternType {
PATTERN_TYPE_REGULAR_EXPRESSION,
PATTERN_TYPE_WILDCARD
};
class MatchResult;
public:
RegExp();
RegExp(const char* pattern,
PatternType patternType
= PATTERN_TYPE_REGULAR_EXPRESSION);
RegExp(const RegExp& other);
~RegExp();
bool IsValid() const
{ return fData != NULL; }
bool SetPattern(const char* pattern,
PatternType patternType
= PATTERN_TYPE_REGULAR_EXPRESSION);
MatchResult Match(const char* string) const;
RegExp& operator=(const RegExp& other);
private:
struct Data;
struct MatchResultData;
private:
Data* fData;
};
class RegExp::MatchResult {
public:
MatchResult();
MatchResult(const MatchResult& other);
~MatchResult();
bool HasMatched() const;
size_t StartOffset() const;
size_t EndOffset() const;
size_t GroupCount() const;
size_t GroupStartOffsetAt(size_t index) const;
size_t GroupEndOffsetAt(size_t index) const;
MatchResult& operator=(const MatchResult& other);
private:
friend class RegExp;
private:
MatchResult(MatchResultData* data);
// takes over the data reference
private:
MatchResultData* fData;
};
#endif // REG_EXP_H