version 5.0.0_beta
integrate PIRegularExpression into PIString and PIDir add piliterals_regularexpression.h for ""_regex and ""_glob literals
This commit is contained in:
@@ -192,25 +192,8 @@ int PIRegularExpression::captureGroupIndex(const PIString & gname) const {
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::matchIterator(PIString & subject, size_t offset) {
|
||||
PIRegularExpression::Matcher ret(this);
|
||||
ret.start_offset = offset;
|
||||
ret.subject = &subject;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::matchIterator(PIString && subject, size_t offset) {
|
||||
PIRegularExpression::Matcher ret(this);
|
||||
ret.start_offset = offset;
|
||||
ret.subject_own = std::move(subject);
|
||||
ret.subject = &ret.subject_own;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::matchIterator(const PIString & subject, size_t offset) {
|
||||
PIRegularExpression::Matcher ret(this);
|
||||
PIRegularExpression::Matcher PIRegularExpression::matchIterator(const PIString & subject, size_t offset) const {
|
||||
PIRegularExpression::Matcher ret(const_cast<PIRegularExpression *>(this));
|
||||
ret.start_offset = offset;
|
||||
ret.subject_own = subject;
|
||||
ret.subject = &ret.subject_own;
|
||||
@@ -218,27 +201,44 @@ PIRegularExpression::Matcher PIRegularExpression::matchIterator(const PIString &
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::match(PIString & subject, size_t offset) {
|
||||
PIRegularExpression::Matcher PIRegularExpression::matchIterator(PIString & subject, size_t offset) const {
|
||||
PIRegularExpression::Matcher ret(const_cast<PIRegularExpression *>(this));
|
||||
ret.start_offset = offset;
|
||||
ret.subject = &subject;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::matchIterator(PIString && subject, size_t offset) const {
|
||||
PIRegularExpression::Matcher ret(const_cast<PIRegularExpression *>(this));
|
||||
ret.start_offset = offset;
|
||||
ret.subject_own = std::move(subject);
|
||||
ret.subject = &ret.subject_own;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::match(const PIString & subject, size_t offset) const {
|
||||
PIRegularExpression::Matcher ret = matchIterator(subject, offset);
|
||||
PRIVATE->match(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::match(PIString && subject, size_t offset) {
|
||||
PIRegularExpression::Matcher PIRegularExpression::match(PIString & subject, size_t offset) const {
|
||||
PIRegularExpression::Matcher ret = matchIterator(subject, offset);
|
||||
PRIVATE->match(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::match(PIString && subject, size_t offset) const {
|
||||
PIRegularExpression::Matcher ret = matchIterator(std::move(subject), offset);
|
||||
PRIVATE->match(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher PIRegularExpression::match(const PIString & subject, size_t offset) {
|
||||
PIRegularExpression::Matcher ret = matchIterator(subject, offset);
|
||||
PRIVATE->match(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIRegularExpression::Matcher::Matcher(PIRegularExpression * p): parent(p) {}
|
||||
|
||||
|
||||
|
||||
@@ -103,13 +103,13 @@ public:
|
||||
PIString captureGroupName(int index) const;
|
||||
int captureGroupIndex(const PIString & gname) const;
|
||||
|
||||
Matcher match(const PIString & subject, size_t offset = 0);
|
||||
Matcher match(PIString & subject, size_t offset = 0);
|
||||
Matcher match(PIString && subject, size_t offset = 0);
|
||||
Matcher match(const PIString & subject, size_t offset = 0) const;
|
||||
Matcher match(PIString & subject, size_t offset = 0) const;
|
||||
Matcher match(PIString && subject, size_t offset = 0) const;
|
||||
|
||||
Matcher matchIterator(const PIString & subject, size_t offset = 0);
|
||||
Matcher matchIterator(PIString & subject, size_t offset = 0);
|
||||
Matcher matchIterator(PIString && subject, size_t offset = 0);
|
||||
Matcher matchIterator(const PIString & subject, size_t offset = 0) const;
|
||||
Matcher matchIterator(PIString & subject, size_t offset = 0) const;
|
||||
Matcher matchIterator(PIString && subject, size_t offset = 0) const;
|
||||
|
||||
static PIRegularExpression fromGlob(const PIString & pattern, Options opt = None);
|
||||
static PIRegularExpression fromPOSIX(const PIString & pattern, Options opt = None);
|
||||
|
||||
@@ -998,6 +998,11 @@ PIStringList PIString::split(const PIString & delim) const {
|
||||
}
|
||||
|
||||
|
||||
bool PIString::contains(const PIRegularExpression & regexp) const {
|
||||
return regexp.match(const_cast<PIString &>(*this)).hasMatch();
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! PIString s("012345012345");
|
||||
@@ -1033,6 +1038,11 @@ int PIString::find(const PIString & str, const int start) const {
|
||||
}
|
||||
|
||||
|
||||
int PIString::find(const PIRegularExpression & regexp, const int start) const {
|
||||
return regexp.match(const_cast<PIString &>(*this), start).matchedStart();
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! piCout << PIString("1.str").findAny(".,:"); // 1
|
||||
@@ -1090,6 +1100,16 @@ int PIString::findLast(const PIString & str, const int start) const {
|
||||
}
|
||||
|
||||
|
||||
int PIString::findLast(const PIRegularExpression & regexp, const int start) const {
|
||||
auto m = regexp.match(const_cast<PIString &>(*this), start);
|
||||
int ret = m.matchedStart();
|
||||
while (m.next()) {
|
||||
ret = m.matchedStart();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! piCout << PIString(".str.0").findAnyLast(".,:"); // 4
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
|
||||
class PIStringList;
|
||||
class PIRegularExpression;
|
||||
|
||||
//! \ingroup Text
|
||||
//! \~\brief
|
||||
@@ -1174,6 +1175,10 @@ public:
|
||||
//! \~russian Возвращает содержит ли строка подстроку "str".
|
||||
bool contains(const PIString & str) const { return find(str) >= 0; }
|
||||
|
||||
//! \~english Returns if string match "regexp".
|
||||
//! \~russian Возвращает совпадает ли строка "regexp".
|
||||
bool contains(const PIRegularExpression & regexp) const;
|
||||
|
||||
|
||||
//! \~english Search character "c" from character at index "start" and return first occur position.
|
||||
//! \~russian Ищет символ "c" от символа "start" и возвращает первое вхождение.
|
||||
@@ -1200,6 +1205,10 @@ public:
|
||||
//! \~\sa \a findAny(), \a findLast(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
|
||||
int find(const char * str, const int start = 0) const { return find(PIString(str), start); }
|
||||
|
||||
//! \~english Search match of "regexp" from character at index "start" and return first occur position.
|
||||
//! \~russian Ищет совпадение с "regexp" от символа "start" и возвращает первое вхождение.
|
||||
int find(const PIRegularExpression & regexp, const int start = 0) const;
|
||||
|
||||
//! \~english Search any character of "str" from character at index "start" and return first occur position.
|
||||
//! \~russian Ищет любой символ строки "str" от симола "start" и возвращает первое вхождение.
|
||||
int findAny(const PIString & str, const int start = 0) const;
|
||||
@@ -1240,6 +1249,10 @@ public:
|
||||
//! \~\sa \a find(), \a findAny(), \a findAnyLast(), \a findWord(), \a findCWord(), \a findRange()
|
||||
int findLast(const char * str, const int start = 0) const { return findLast(PIString(str), start); }
|
||||
|
||||
//! \~english Search match of "regexp" from character at index "start" and return last occur position.
|
||||
//! \~russian Ищет совпадение с "regexp" от символа "start" и возвращает последнее вхождение.
|
||||
int findLast(const PIRegularExpression & regexp, const int start = 0) const;
|
||||
|
||||
//! \~english Search any character of "str" from character at index "start" and return last occur position.
|
||||
//! \~russian Ищет любой символ строки "str" от символа "start" и возвращает последнее вхождение.
|
||||
int findAnyLast(const PIString & str, const int start = 0) const;
|
||||
|
||||
Reference in New Issue
Block a user