From: kawi Date: Mon, 5 Jan 2015 12:32:48 +0000 (+0100) Subject: not pattern starts now with '-' (^ is a meta char in windows shell) X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=999d48f846e105a235315c9cb62e1512e38884cc;p=crepublib not pattern starts now with '-' (^ is a meta char in windows shell) --- diff --git a/base/ReByteBuffer.cpp b/base/ReByteBuffer.cpp index 4194fa2..0b2e274 100644 --- a/base/ReByteBuffer.cpp +++ b/base/ReByteBuffer.cpp @@ -294,7 +294,7 @@ int ReByteBuffer::indexOf(const Byte* toFind, size_t toFindLength, int start, if (start >= 0 && start <= int(m_length - toFindLength) && end >= (int) toFindLength && end <= (int) m_length){ while(rc < 0 && start <= int(end - toFindLength)){ - if (ignoreCase ? strncasecmp(toFind, m_buffer + start, toFindLength) == 0 + if (ignoreCase ? memicmp(toFind, m_buffer + start, toFindLength) == 0 : memcmp(toFind, m_buffer + start, toFindLength) == 0) rc = start; else diff --git a/base/ReCString.cpp b/base/ReCString.cpp index a5252dd..99f6475 100644 --- a/base/ReCString.cpp +++ b/base/ReCString.cpp @@ -43,3 +43,31 @@ void replaceSubstring(char* start, size_t bufferSize, size_t lengthReplaced, } } } +#if defined __linux__ +/** + * Compares two memory regions case insensitive. + * + * @param region1 the first region to compare + * @param region2 the second region to compare + * @return 0: both regions are equal (case insensitive)
+ * < 0: region1 is alphabetically less than region2
+ * > 0: region1 is alphabetically greater than region2 + */ +int memicmp(void* region1, void* region2, int size) +{ + unsigned char* ptr1 = (unsigned char*) region1; + unsigned char* ptr2 = (unsigned char*) region2; + int rc = 0; + for (int ix = 0; ix < size; ix++){ + unsigned char cc1 = *ptr1++; + unsigned char cc2 = *ptr2++; + int diff = tolower(cc1) - tolower(cc2); + if (diff != 0) + { + rc = diff; + break; + } + } + return rc; +} +#endif diff --git a/base/ReCString.hpp b/base/ReCString.hpp index 7784b6d..03d31a9 100644 --- a/base/ReCString.hpp +++ b/base/ReCString.hpp @@ -10,4 +10,7 @@ void replaceSubstring(char* start, size_t bufferSize, size_t lengthReplaced, const char* newString); +#if defined __linux__ +int memicmp(void* region1, void* region2, int size); +#endif #endif /* RESTRING_H_ */ diff --git a/cunit/cuReCString.cpp b/cunit/cuReCString.cpp index 97de41f..5a49336 100644 --- a/cunit/cuReCString.cpp +++ b/cunit/cuReCString.cpp @@ -14,6 +14,7 @@ public: } private: void run(){ + testMemicmp(); testReplaceSubstring(); } void testReplaceSubstring(){ @@ -31,6 +32,20 @@ private: replaceSubstring(buffer, 6, 0, "x"); checkEqu("xw.ab", buffer); } + void testMemicmp(){ + checkEqu(0, memicmp((void*) "abcd", (void*) "abcx", 3u)); + checkEqu(0, memicmp("aBcd", "AbCx", 3)); + + checkEqu(1, memicmp("bbcd", "abcx", 3)); + checkEqu(-1, memicmp("abcd", "bbcx", 3)); + + checkEqu(1, memicmp("Bbcd", "abcx", 3)); + checkEqu(-1, memicmp("aBcd", "bbcx", 3)); + + checkEqu(1, memicmp("bbcd", "abcx", 3)); + checkEqu(-1, memicmp("ABcd", "bbcx", 3)); + } + }; extern void testReString(void); diff --git a/cunit/cuReMatcher.cpp b/cunit/cuReMatcher.cpp index f29f22e..36f7f1a 100644 --- a/cunit/cuReMatcher.cpp +++ b/cunit/cuReMatcher.cpp @@ -23,14 +23,14 @@ private: } void testPatternList(){ RePatternList list; - list.set(";*.cpp;^cu*;*.hpp;", true); + list.set(";*.cpp;-cu*;*.hpp;", true); checkT(list.match("a.hpp")); checkT(list.match("a.cpp")); checkT(list.match("a.hpp")); checkF(list.match("cuA.hpp")); checkF(list.match("a.hpp~")); - list.set(" * ^*~"); + list.set(" * -*~"); checkT(list.match("a.hpp")); checkF(list.match("a.hpp~")); } diff --git a/cunit/cuReTraverser.cpp b/cunit/cuReTraverser.cpp index 81151da..13a9185 100644 --- a/cunit/cuReTraverser.cpp +++ b/cunit/cuReTraverser.cpp @@ -111,7 +111,7 @@ private: ReDirOptions opts(s_empty, s_empty); opts.addStandardFilterOptions(); char* argv[] = { "x", "-y1970.01.02", "-o1970.01.03", - "-D5", "-d1", "-z1k", "-Z2M", "*" + "-D5", "-d1", "-z1k", "-Z2M", "-p;*;-*~" }; ReDirEntryFilter_t filter; opts.programArgs().init(sizeof argv / sizeof argv[0], argv); @@ -125,7 +125,7 @@ private: checkEqu(1000ll, filter.m_minSize); checkEqu(2*1024*1024ll, filter.m_maxSize); checkNN(filter.m_nodePatterns); - checkEqu("*", filter.m_nodePatterns->patternString()); + checkEqu(";*;-*~", filter.m_nodePatterns->patternString()); } void checkOneFile(const char* node, const char* parent, const ReHashList& hash){ ReByteBuffer path, expected; diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 304b9aa..0a7e61b 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -8,7 +8,7 @@ #include "base/rebase.hpp" #include "os/reos.hpp" -const char* ReDirTools::m_version = "2015.01.04"; +const char* ReDirTools::m_version = "2015.01.05"; static const char* s_empty[] = { NULL }; @@ -46,7 +46,7 @@ const char* s_listUsage[] = { }; const char* s_listExamples[] = { "dirtool list --min-size=10M e:\\data", - "dirtool list --type=f -y7d --size=10M -p;*.cpp;*.hpp;Makefile*;^*~ /home/data" , + "dirtool list --type=f -y7d --size=10M -p;*.cpp;*.hpp;Makefile*;-*~ /home/data" , NULL }; @@ -138,18 +138,18 @@ void ReDirOptions::addStandardFilterOptions(){ i18n("a list of patterns for the path (without basename)\n" "the separator is the first character of the list\n" "Each pattern can contain '*' as wildcard\n" - "If the first character is '^' the pattern is a 'not pattern':\n" + "If the first character is '-' the pattern is a 'not pattern':\n" "A directory will be entered if at least one of the positive patterns\n" "and none of the 'not patterns' matches\n" - "examples: ';*;^*/.git/' ',*/cache/,*/temp/"), + "examples: ';*;-*/.git/' ',*/cache/,*/temp/"), 'P', "path-pattern", false, NULL); m_programArgs.addString("nodepattern", i18n("a list of patterns for the basename (name without path) separated by ';'\n" "Each pattern can contain '*' as wildcard\n" - "If the first character is '^' the pattern is a 'not pattern':\n" + "If the first character is '-' the pattern is a 'not pattern':\n" "A file will be found if at least one of the positive patterns and none\n" "of the 'not patterns' matches\n" - "examples: '*.cpp;*.hpp;Make*' '*;^*.bak;^*~"), + "examples: '*.cpp;*.hpp;Make*' '*;-*.bak;-*~"), 'p', "basename-pattern", false, NULL); m_programArgs.addBool("quiet", i18n("no additional information like runtime"), @@ -316,7 +316,7 @@ time_t ReDirOptions::checkSize(const char* value){ * @throws ReOptionExecption */ const char* ReDirOptions::checkPatternList(const char* value){ - if (isalpha(*value) || *value == '*' || *value == '.') + if (iscsym(*value) || *value == '*' || *value == '.' || *value == '-') throw ReOptionException(&m_programArgs, i18n("invalid separator (first character): $1 use ';' instead"), value); diff --git a/string/ReMatcher.cpp b/string/ReMatcher.cpp index e3ca4be..4788952 100644 --- a/string/ReMatcher.cpp +++ b/string/ReMatcher.cpp @@ -215,7 +215,7 @@ void RePatternList::destroy(){ * Tests whether a name matches at least one of the patterns. * *
Examples:
- * list: ";*.cpp;^test*;*.hpp"
+ * list: ";*.cpp;-test*;*.hpp"
  * returns true: "a.cpp" "xy.hpp"
  * returns false: "x.img", "test.cpp"
  * 
diff --git a/string/ReMatcher.hpp b/string/ReMatcher.hpp index f4fb869..3567e9b 100644 --- a/string/ReMatcher.hpp +++ b/string/ReMatcher.hpp @@ -90,7 +90,7 @@ public: void destroy(); bool match(const char* pattern); void set(const char* patterns, bool ignoreCase = false, - const char* separator = NULL, const char* notPrefix = "^"); + const char* separator = NULL, const char* notPrefix = "-"); /** Returns the original pattern string. * @return the string describing the patterns. */