Regex: Add regex_replace native.
This commit is contained in:
@@ -34,6 +34,19 @@
|
||||
#define _INCLUDE_CREGEX_H
|
||||
|
||||
#include <am-vector.h>
|
||||
#include <am-string.h>
|
||||
|
||||
/**
|
||||
* Maximum number of sub-patterns, here 50 (this should be a multiple of 3).
|
||||
*/
|
||||
#define REGEX_MAX_SUBPATTERNS 150
|
||||
|
||||
/**
|
||||
* Flags to used with regex_replace, to control the replacement behavior.
|
||||
*/
|
||||
#define REGEX_FORMAT_DEFAULT 0 // Uses the standard formatting rules to replace matches.
|
||||
#define REGEX_FORMAT_NOCOPY 1 // The sections that do not match the regular expression are not copied when replacing matches.
|
||||
#define REGEX_FORMAT_FIRSTONLY 2 // Only the first occurrence of a regular expression is replaced.
|
||||
|
||||
class RegEx
|
||||
{
|
||||
@@ -42,6 +55,11 @@ public:
|
||||
int start, end;
|
||||
};
|
||||
|
||||
struct NamedGroup {
|
||||
ke::AString name;
|
||||
size_t index;
|
||||
};
|
||||
|
||||
RegEx();
|
||||
~RegEx();
|
||||
|
||||
@@ -52,8 +70,11 @@ public:
|
||||
int Compile(const char *pattern, int iFlags);
|
||||
int Match(const char *str);
|
||||
int MatchAll(const char *str);
|
||||
int Replace(char *text, size_t text_maxlen, const char *replace, size_t replaceLen, int flags = 0);
|
||||
void ClearMatch();
|
||||
const char *GetSubstring(int s, char buffer[], int max);
|
||||
const char *GetSubstring(size_t start, char buffer[], size_t max, size_t *outlen = NULL);
|
||||
const char *GetSubstring(size_t start, size_t end, char buffer[], size_t max, size_t *outlen = NULL);
|
||||
void MakeSubpatternsTable(int numSubpatterns);
|
||||
|
||||
public:
|
||||
int mErrorOffset;
|
||||
@@ -63,9 +84,12 @@ public:
|
||||
private:
|
||||
pcre *re;
|
||||
bool mFree;
|
||||
int ovector[30];
|
||||
int ovector[REGEX_MAX_SUBPATTERNS];
|
||||
char *subject;
|
||||
ke::Vector<RegExSub> mSubStrings;
|
||||
ke::Vector<size_t> mMatchesSubs;
|
||||
ke::Vector<NamedGroup> mSubsNameTable;
|
||||
int mNumSubpatterns;
|
||||
};
|
||||
|
||||
#endif //_INCLUDE_CREGEX_H
|
||||
|
||||
Reference in New Issue
Block a user