Merge topic 'update-kwsys'

94902cd03c Merge branch 'upstream-KWSys' into update-kwsys
891e4d5418 KWSys 2025-01-27 (2fbdf7e5)

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !10239
This commit is contained in:
Brad King 2025-01-28 13:41:14 +00:00 committed by Kitware Robot
commit ca7aab97fd
2 changed files with 21 additions and 12 deletions

View File

@ -861,7 +861,8 @@ public:
// find -- Matches the regular expression to the given string. // find -- Matches the regular expression to the given string.
// Returns true if found, and sets start and end indexes accordingly. // Returns true if found, and sets start and end indexes accordingly.
bool RegularExpression::find(char const* string, bool RegularExpression::find(char const* string,
RegularExpressionMatch& rmatch) const RegularExpressionMatch& rmatch,
std::string::size_type offset) const
{ {
char const* s; char const* s;
@ -882,7 +883,7 @@ bool RegularExpression::find(char const* string,
// If there is a "must appear" string, look for it. // If there is a "must appear" string, look for it.
if (this->regmust) { if (this->regmust) {
s = string; s = string + offset;
while ((s = strchr(s, this->regmust[0]))) { while ((s = strchr(s, this->regmust[0]))) {
if (strncmp(s, this->regmust, this->regmlen) == 0) if (strncmp(s, this->regmust, this->regmlen) == 0)
break; // Found it. break; // Found it.
@ -896,14 +897,13 @@ bool RegularExpression::find(char const* string,
// Mark beginning of line for ^ . // Mark beginning of line for ^ .
regFind.regbol = string; regFind.regbol = string;
s = string + offset;
// Simplest case: anchored match need be tried only once. // Simplest case: anchored match need be tried only once.
if (this->reganch) if (this->reganch)
return ( return (regFind.regtry(s, rmatch.startp, rmatch.endp, this->program) != 0);
regFind.regtry(string, rmatch.startp, rmatch.endp, this->program) != 0);
// Messy cases: unanchored match. // Messy cases: unanchored match.
s = string;
if (this->regstart != '\0') if (this->regstart != '\0')
// We know what char it must start with. // We know what char it must start with.
while ((s = strchr(s, this->regstart))) { while ((s = strchr(s, this->regstart))) {

View File

@ -121,6 +121,9 @@ inline std::string::size_type RegularExpressionMatch::end() const
*/ */
inline std::string::size_type RegularExpressionMatch::start(int n) const inline std::string::size_type RegularExpressionMatch::start(int n) const
{ {
if (!this->startp[n]) {
return std::string::npos;
}
return static_cast<std::string::size_type>(this->startp[n] - return static_cast<std::string::size_type>(this->startp[n] -
this->searchstring); this->searchstring);
} }
@ -131,6 +134,9 @@ inline std::string::size_type RegularExpressionMatch::start(int n) const
*/ */
inline std::string::size_type RegularExpressionMatch::end(int n) const inline std::string::size_type RegularExpressionMatch::end(int n) const
{ {
if (!this->endp[n]) {
return std::string::npos;
}
return static_cast<std::string::size_type>(this->endp[n] - return static_cast<std::string::size_type>(this->endp[n] -
this->searchstring); this->searchstring);
} }
@ -338,19 +344,20 @@ public:
* This method is thread safe when called with different * This method is thread safe when called with different
* RegularExpressionMatch instances. * RegularExpressionMatch instances.
*/ */
bool find(char const*, RegularExpressionMatch&) const; bool find(char const*, RegularExpressionMatch&,
std::string::size_type offset = 0) const;
/** /**
* Matches the regular expression to the given string. * Matches the regular expression to the given string.
* Returns true if found, and sets start and end indexes accordingly. * Returns true if found, and sets start and end indexes accordingly.
*/ */
inline bool find(char const*); inline bool find(char const*, std::string::size_type offset = 0);
/** /**
* Matches the regular expression to the given std string. * Matches the regular expression to the given std string.
* Returns true if found, and sets start and end indexes accordingly. * Returns true if found, and sets start and end indexes accordingly.
*/ */
inline bool find(std::string const&); inline bool find(std::string const&, std::string::size_type offset = 0);
/** /**
* Match indices * Match indices
@ -474,18 +481,20 @@ inline bool RegularExpression::compile(std::string const& s)
* Matches the regular expression to the given std string. * Matches the regular expression to the given std string.
* Returns true if found, and sets start and end indexes accordingly. * Returns true if found, and sets start and end indexes accordingly.
*/ */
inline bool RegularExpression::find(char const* s) inline bool RegularExpression::find(char const* s,
std::string::size_type offset)
{ {
return this->find(s, this->regmatch); return this->find(s, this->regmatch, offset);
} }
/** /**
* Matches the regular expression to the given std string. * Matches the regular expression to the given std string.
* Returns true if found, and sets start and end indexes accordingly. * Returns true if found, and sets start and end indexes accordingly.
*/ */
inline bool RegularExpression::find(std::string const& s) inline bool RegularExpression::find(std::string const& s,
std::string::size_type offset)
{ {
return this->find(s.c_str()); return this->find(s.c_str(), offset);
} }
/** /**