+ move appendToFirstOccurence() to regexTools.cpp and use now ICU as regex engine

This commit is contained in:
kelson42 2011-12-22 11:25:24 +00:00
parent 73217d5e49
commit 72e62fab6b
3 changed files with 28 additions and 0 deletions

View File

@ -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);

View File

@ -52,3 +52,29 @@ bool matchRegex(const std::string &content, const std::string &regex) {
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(&regexp, regex.data(), REG_ICASE);
if (!regexec(&regexp, content.data(), 1, matchs, 0)) {
if (matchs[0].rm_so > 0)
content.insert(matchs[0].rm_eo, replacement);
}
regfree(&regexp);
*/
}

View File

@ -26,5 +26,6 @@
#include <map>
bool matchRegex(const std::string &content, const std::string &regex);
void appendToFirstOccurence(std::string &content, const std::string regex, const std::string &replacement);
#endif