From 9d371f295ce42e1f87aff5b061f9652a5d897be6 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 31 Oct 2011 09:55:34 +0000 Subject: [PATCH] + use libicu in regexTools --- src/common/regexTools.cpp | 27 +++++++++++++++------------ src/common/regexTools.h | 4 ++-- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/common/regexTools.cpp b/src/common/regexTools.cpp index 202c55821..f5257f812 100644 --- a/src/common/regexTools.cpp +++ b/src/common/regexTools.cpp @@ -19,33 +19,36 @@ #include "regexTools.h" -std::map regexCache; +std::map regexCache; -regex_t buildRegex(const std::string ®ex) { - regex_t regexStruct; - std::map::iterator itr = regexCache.find(regex); +RegexMatcher *buildRegex(const std::string ®ex) { + RegexMatcher *matcher; + std::map::iterator itr = regexCache.find(regex); /* Regex is in cache */ if (itr != regexCache.end()) { - regexStruct = itr->second; + matcher = itr->second; } /* Regex needs to be parsed (and cached) */ else { - regcomp(®exStruct, regex.data(), REG_ICASE); - regexCache[regex] = regexStruct; + UErrorCode status = U_ZERO_ERROR; + UnicodeString uregex = UnicodeString(regex.c_str()); + matcher = new RegexMatcher(uregex, UREGEX_CASE_INSENSITIVE, status); + regexCache[regex] = matcher; } - return regexStruct; + return matcher; } /* todo */ void freeRegexCache() { - //regfree(®exStructure); } bool matchRegex(const std::string &content, const std::string ®ex) { - regex_t regexStructure = buildRegex(regex); - bool result = !regexec(®exStructure, content.data(), 0, 0, 0); - return result; + ucnv_setDefaultName("UTF-8"); + UnicodeString ucontent = UnicodeString(content.c_str()); + RegexMatcher *matcher = buildRegex(regex); + matcher->reset(ucontent); + return matcher->find(); } diff --git a/src/common/regexTools.h b/src/common/regexTools.h index 3e4443d10..7037c7789 100644 --- a/src/common/regexTools.h +++ b/src/common/regexTools.h @@ -20,9 +20,9 @@ #ifndef KIWIX_REGEXTOOLS_H #define KIWIX_REGEXTOOLS_H -#include +#include +#include #include -#include #include bool matchRegex(const std::string &content, const std::string ®ex);