mirror of https://github.com/kiwix/libkiwix.git
+ move appendToFirstOccurence() to regexTools.cpp and use now ICU as regex engine
This commit is contained in:
parent
73217d5e49
commit
72e62fab6b
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
*/
|
||||
}
|
||||
|
||||
|
|
|
@ -26,5 +26,6 @@
|
|||
#include <map>
|
||||
|
||||
bool matchRegex(const std::string &content, const std::string ®ex);
|
||||
void appendToFirstOccurence(std::string &content, const std::string regex, const std::string &replacement);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue