diff --git a/src/common/pathTools.h b/src/common/pathTools.h index 3ad73e4e6..edc21fe24 100644 --- a/src/common/pathTools.h +++ b/src/common/pathTools.h @@ -41,6 +41,7 @@ bool isRelativePath(const string &path); string computeAbsolutePath(const string libraryPath, const string relativePath); string removeLastPathElement(const string path, const bool removePreSeparator = false, const bool removePostSeparator = false); + unsigned int getFileSize(const string &path); string getFileSizeAsString(const string &path); bool fileExists(const string &path); diff --git a/src/common/regexTools.cpp b/src/common/regexTools.cpp index f5257f812..acfc3f85a 100644 --- a/src/common/regexTools.cpp +++ b/src/common/regexTools.cpp @@ -52,3 +52,29 @@ bool matchRegex(const std::string &content, const std::string ®ex) { matcher->reset(ucontent); return matcher->find(); } + +void appendToFirstOccurence(std::string &content, const std::string regex, const std::string &replacement) { + ucnv_setDefaultName("UTF-8"); + UnicodeString ucontent = UnicodeString(content.c_str()); + RegexMatcher *matcher = buildRegex(regex); + matcher->reset(ucontent); + + if (matcher->find()) { + UErrorCode status = U_ZERO_ERROR; + content.insert(matcher->start(status), replacement); + } + + /* + regmatch_t matchs[1]; + regex_t regexp; + + regcomp(®exp, regex.data(), REG_ICASE); + if (!regexec(®exp, content.data(), 1, matchs, 0)) { + if (matchs[0].rm_so > 0) + content.insert(matchs[0].rm_eo, replacement); + } + + regfree(®exp); + */ +} + diff --git a/src/common/regexTools.h b/src/common/regexTools.h index 7037c7789..0ef7297e8 100644 --- a/src/common/regexTools.h +++ b/src/common/regexTools.h @@ -26,5 +26,6 @@ #include bool matchRegex(const std::string &content, const std::string ®ex); +void appendToFirstOccurence(std::string &content, const std::string regex, const std::string &replacement); #endif