diff options
author | George Hazan <george.hazan@gmail.com> | 2013-04-23 08:27:32 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-04-23 08:27:32 +0000 |
commit | 78a92aad0e3c2941b11b3115d9fd7aae44e5fc37 (patch) | |
tree | 28cf61c18a6d5d41bd2a1556b37b1f7026cb0ed0 /src/mir_core/utils.cpp | |
parent | 36ac355b3009665069258c76f9ce8b7f7229ece9 (diff) |
- added unicode analogs of ltrim, ltrimp, wildcmp;
- wildcmpi[w] added
git-svn-id: http://svn.miranda-ng.org/main/trunk@4511 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/mir_core/utils.cpp')
-rw-r--r-- | src/mir_core/utils.cpp | 101 |
1 files changed, 95 insertions, 6 deletions
diff --git a/src/mir_core/utils.cpp b/src/mir_core/utils.cpp index fb6076865a..a98444d5da 100644 --- a/src/mir_core/utils.cpp +++ b/src/mir_core/utils.cpp @@ -61,7 +61,7 @@ MIR_CORE_DLL(WCHAR*) wrtrim(WCHAR *str) if (str == NULL)
return NULL;
- WCHAR* p = _tcschr(str, 0);
+ WCHAR *p = _tcschr(str, 0);
while (--p >= str) {
switch (*p) {
case ' ': case '\t': case '\n': case '\r':
@@ -90,12 +90,45 @@ MIR_CORE_DLL(char*) ltrim(char* str) }
}
-MIR_CORE_DLL(char*) ltrimp(char* str)
+MIR_CORE_DLL(WCHAR*) ltrimw(WCHAR *str)
{
if (str == NULL)
return NULL;
- char* p = str;
+ WCHAR *p = str;
+ for (;;) {
+ switch (*p) {
+ case ' ': case '\t': case '\n': case '\r':
+ ++p; break;
+ default:
+ memmove(str, p, sizeof(WCHAR)*(wcslen(p) + 1));
+ return str;
+ }
+ }
+}
+
+MIR_CORE_DLL(char*) ltrimp(char *str)
+{
+ if (str == NULL)
+ return NULL;
+
+ char *p = str;
+ for (;;) {
+ switch (*p) {
+ case ' ': case '\t': case '\n': case '\r':
+ ++p; break;
+ default:
+ return p;
+ }
+ }
+}
+
+MIR_CORE_DLL(WCHAR*) ltrimpw(WCHAR *str)
+{
+ if (str == NULL)
+ return NULL;
+
+ WCHAR *p = str;
for (;;) {
switch (*p) {
case ' ': case '\t': case '\n': case '\r':
@@ -106,15 +139,15 @@ MIR_CORE_DLL(char*) ltrimp(char* str) }
}
-MIR_CORE_DLL(int) wildcmp(char * name, char * mask)
+MIR_CORE_DLL(int) wildcmp(const char *name, const char *mask)
{
- char * last='\0';
+ const char *last='\0';
for (;; mask++, name++) {
if (*mask != '?' && *mask != *name) break;
if (*name == '\0') return ((BOOL)!*mask);
}
if (*mask != '*') return FALSE;
- for (;; mask++, name++){
+ for (;; mask++, name++) {
while (*mask == '*') {
last = mask++;
if (*mask == '\0') return ((BOOL)!*mask); /* true */
@@ -123,3 +156,59 @@ MIR_CORE_DLL(int) wildcmp(char * name, char * mask) if (*mask != '?' && *mask != *name) name -= (size_t)(mask - last) - 1, mask = last;
}
}
+
+MIR_CORE_DLL(int) wildcmpw(const WCHAR *name, const WCHAR *mask)
+{
+ const WCHAR* last = '\0';
+ for (;; mask++, name++) {
+ if (*mask != '?' && *mask != *name) break;
+ if (*name == '\0') return ((BOOL)!*mask);
+ }
+ if (*mask != '*') return FALSE;
+ for (;; mask++, name++) {
+ while(*mask == '*') {
+ last = mask++;
+ if (*mask == '\0') return ((BOOL)!*mask); /* true */
+ }
+ if (*name == '\0') return ((BOOL)!*mask); /* *mask == EOS */
+ if (*mask != '?' && *mask != *name) name -= (size_t)(mask - last) - 1, mask = last;
+ }
+}
+
+#define _qtoupper(_c) (((_c) >= 'a' && (_c) <= 'z')?((_c)-('a'+'A')):(_c))
+
+MIR_CORE_DLL(int) wildcmpi(const char *name, const char *mask)
+{
+ const char *last = NULL;
+ for (;; mask++, name++) {
+ if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) break;
+ if (*name == '\0') return ((BOOL)!*mask);
+ }
+ if (*mask != '*') return FALSE;
+ for (;; mask++, name++) {
+ while(*mask == '*') {
+ last = mask++;
+ if (*mask == '\0') return ((BOOL)!*mask); /* true */
+ }
+ if (*name == '\0') return ((BOOL)!*mask); /* *mask == EOS */
+ if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) name -= (size_t)(mask - last) - 1, mask = last;
+ }
+}
+
+MIR_CORE_DLL(int) wildcmpiw(const WCHAR *name, const WCHAR *mask)
+{
+ const WCHAR* last = NULL;
+ for (;; mask++, name++) {
+ if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) break;
+ if (*name == '\0') return ((BOOL)!*mask);
+ }
+ if (*mask != '*') return FALSE;
+ for (;; mask++, name++) {
+ while(*mask == '*') {
+ last = mask++;
+ if (*mask == '\0') return ((BOOL)!*mask); /* true */
+ }
+ if (*name == '\0') return ((BOOL)!*mask); /* *mask == EOS */
+ if (*mask != '?' && _qtoupper(*mask) != _qtoupper(*name)) name -= (size_t)(mask - last) - 1, mask = last;
+ }
+}
|