Add ability to specify case insensitive matching.
This commit is contained in:
@@ -22,7 +22,8 @@ public:
|
|||||||
RegExp();
|
RegExp();
|
||||||
RegExp(const char* pattern,
|
RegExp(const char* pattern,
|
||||||
PatternType patternType
|
PatternType patternType
|
||||||
= PATTERN_TYPE_REGULAR_EXPRESSION);
|
= PATTERN_TYPE_REGULAR_EXPRESSION,
|
||||||
|
bool caseSensitive = true);
|
||||||
RegExp(const RegExp& other);
|
RegExp(const RegExp& other);
|
||||||
~RegExp();
|
~RegExp();
|
||||||
|
|
||||||
@@ -31,7 +32,8 @@ public:
|
|||||||
|
|
||||||
bool SetPattern(const char* pattern,
|
bool SetPattern(const char* pattern,
|
||||||
PatternType patternType
|
PatternType patternType
|
||||||
= PATTERN_TYPE_REGULAR_EXPRESSION);
|
= PATTERN_TYPE_REGULAR_EXPRESSION,
|
||||||
|
bool caseSensitive = true);
|
||||||
|
|
||||||
MatchResult Match(const char* string) const;
|
MatchResult Match(const char* string) const;
|
||||||
|
|
||||||
|
|||||||
+18
-10
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
struct RegExp::Data : public BReferenceable {
|
struct RegExp::Data : public BReferenceable {
|
||||||
Data(const char* pattern, PatternType patternType)
|
Data(const char* pattern, PatternType patternType, bool caseSensitive)
|
||||||
:
|
:
|
||||||
BReferenceable()
|
BReferenceable()
|
||||||
{
|
{
|
||||||
@@ -115,7 +115,11 @@ struct RegExp::Data : public BReferenceable {
|
|||||||
pattern = patternString.String();
|
pattern = patternString.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
fError = regcomp(&fCompiledExpression, pattern, REG_EXTENDED);
|
int flags = REG_EXTENDED;
|
||||||
|
if (!caseSensitive)
|
||||||
|
flags |= REG_ICASE;
|
||||||
|
|
||||||
|
fError = regcomp(&fCompiledExpression, pattern, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
~Data()
|
~Data()
|
||||||
@@ -218,11 +222,12 @@ RegExp::RegExp()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RegExp::RegExp(const char* pattern, PatternType patternType)
|
RegExp::RegExp(const char* pattern, PatternType patternType,
|
||||||
|
bool caseSensitive)
|
||||||
:
|
:
|
||||||
fData(NULL)
|
fData(NULL)
|
||||||
{
|
{
|
||||||
SetPattern(pattern, patternType);
|
SetPattern(pattern, patternType, caseSensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -243,20 +248,23 @@ RegExp::~RegExp()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
RegExp::SetPattern(const char* pattern, PatternType patternType)
|
RegExp::SetPattern(const char* pattern, PatternType patternType,
|
||||||
|
bool caseSensitive)
|
||||||
{
|
{
|
||||||
if (fData != NULL) {
|
if (fData != NULL) {
|
||||||
fData->ReleaseReference();
|
fData->ReleaseReference();
|
||||||
fData = NULL;
|
fData = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fData = new Data(pattern, patternType);
|
Data* newData = new(std::nothrow) Data(pattern, patternType, caseSensitive);
|
||||||
if (!fData->IsValid()) {
|
if (newData == NULL)
|
||||||
delete fData;
|
|
||||||
fData = NULL;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
|
BReference<Data> dataReference(newData, true);
|
||||||
|
if (!newData->IsValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
fData = dataReference.Detach();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user