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
}
}
}
+#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)<br>
+ * < 0: region1 is alphabetically less than region2<br>
+ * > 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
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_ */
}
private:
void run(){
+ testMemicmp();
testReplaceSubstring();
}
void testReplaceSubstring(){
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);
}
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~"));
}
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);
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;
#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 };
};
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
};
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"),
* @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);
* Tests whether a name matches at least one of the patterns.
*
* <pre>Examples:
- * list: ";*.cpp;^test*;*.hpp"
+ * list: ";*.cpp;-test*;*.hpp"
* returns true: "a.cpp" "xy.hpp"
* returns false: "x.img", "test.cpp"
* </pre>
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.
*/