18#include "keyple/core/util/cpp/Matcher.hpp"
19#include "keyple/core/util/cpp/Pattern.hpp"
20#include "keyple/core/util/cpp/exception/IndexOutOfBoundsException.hpp"
27using keyple::core::util::cpp::exception::IndexOutOfBoundsException;
29Matcher::Matcher(
const Pattern* parent,
const std::string& text)
30: mParentPattern(parent)
38Matcher::match(
const int from,
const int anchor)
const
43 if (std::regex_search(mText, mParentPattern->mPattern))
52 return match(mFrom, ENDANCHOR);
56Matcher::replaceAll(
const std::string& replacement)
const
60 ss << std::regex_replace(mText, mParentPattern->mPattern, replacement);
68 int nextSearchIndex = mLast;
69 if (nextSearchIndex == mFirst)
73 if (nextSearchIndex < mFrom)
74 nextSearchIndex = mFrom;
77 if (nextSearchIndex > mTo) {
83 return search(nextSearchIndex);
87Matcher::find(
const int start)
89 int limit = getTextLength();
91 if (start < 0 || start > limit)
92 throw IndexOutOfBoundsException(
"Illegal start index");
100Matcher::group(
const int group)
const
102 if (group < 0 || group >
static_cast<int>(mGroups.size()))
103 throw IndexOutOfBoundsException(
"No group" + std::to_string(group));
105 return mGroups[group];
109Matcher::group()
const
115Matcher::search(
const int from)
117 mSubs = mText.substr(from, mText.length() - from);
119 if (std::regex_search(mSubs, mGroups, mParentPattern->mPattern))
126Matcher::getTextLength()
const
128 return static_cast<int>(mText.length());
138 for (
int i = 0; i < static_cast<int>(mGroups.size()); i++) {
140 for (
int i = 0; i < static_cast<int>(mLocals.size()); i++) mLocals[i] = -1;
142 mLastAppendPosition = 0;
144 mTo = getTextLength();