Commit 38312f60 authored by Bryan Berthou's avatar Bryan Berthou
Browse files

refs#16

In ElementaryUtils (trunk) :
- In StringUtils correct stuff find pattern in string.
parent 14cb8728
#include "../../../include/ElementaryUtils/string_utils/StringUtils.h"
#include <algorithm> // pour transform #include <cctype> #include <cstdlib> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <iterator>
#include "../../../include/ElementaryUtils/logger/CustomException.h"
#include <algorithm> // pour transform #include <cctype> #include <cstdlib> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <cctype> #include <iterator> #include <cctype> #include <iterator> #include <cctype> #include <iterator> #include "../../../include/ElementaryUtils/logger/CustomException.h"
#include "../../../include/ElementaryUtils/logger/LoggerManager.h"
#include "../../../include/ElementaryUtils/string_utils/Formatter.h"
......@@ -266,6 +264,10 @@ std::string StringUtils::removeAfterLast(const std::string &chaine,
size_t StringUtils::findFirstJustAfter(const std::string& file,
const std::string& pattern, const size_t startIndex) {
LoggerManager::getInstance()->debug("StringUtils", __func__,
Formatter() << "Trying to find (" << pattern << ") at startIndex("
<< startIndex << ") in file = " << file);
size_t fileSize = file.size();
if (fileSize == 0) {
......@@ -281,27 +283,32 @@ size_t StringUtils::findFirstJustAfter(const std::string& file,
size_t i = startIndex;
size_t j = 0;
while (i != fileSize) {
while (i < fileSize) {
if (file.at(i) == pattern.at(j)) {
while (i + j != fileSize && j != pattern.size()
LoggerManager::getInstance()->debug("StringUtils", __func__,
Formatter() << "fileIndex = " << i);
while (i + j < fileSize && j < pattern.size()
&& file.at(i + j) == pattern.at(j)) {
LoggerManager::getInstance()->debug("StringUtils", __func__,
Formatter() << "Compare [" << file.at(i + j)
<< "] to [" << pattern.at(j) << "]");
Formatter() << "Compare [" << file.at(i + j)
<< "] to [" << pattern.at(j)
<< "] patternIndex = " << j);
j += 1;
}
if (j == pattern.size()) {
// throw CustomException("StringUtils", __func__, Formatter() << file.at(i+pattern.size()));
LoggerManager::getInstance()->debug("StringUtils", __func__,
Formatter() << "Pattern found at indexPos = " << i);
//TODO : why i+pattern.size() didn't work ?
//return pos after matching character
return i + pattern.size();
}
} else {
j = 0;
i += 1;
}
j = 0;
i += 1;
}
}
......@@ -330,9 +337,9 @@ size_t StringUtils::findFirst(const std::string& file,
size_t i = startIndex;
size_t j = 0;
while (i <= fileSize) {
while (i < fileSize) {
if (file.at(i) == pattern.at(j)) {
while (i + j <= fileSize && j != pattern.size()
while (i + j < fileSize && j < pattern.size()
&& file.at(i + j) == pattern.at(j)) {
LoggerManager::getInstance()->debug("StringUtils", __func__,
Formatter() << "Compare [" << file.at(i + j)
......@@ -349,10 +356,9 @@ size_t StringUtils::findFirst(const std::string& file,
//return pos at matching 1st character
return i;
}
} else {
j = 0;
i += 1;
}
j = 0;
i += 1;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment