2 // Copyright (c) 1999-2006 by Digital Mars
4 // written by Walter Bright
6 // License for redistribution is by either the Artistic License
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
8 // See the included readme.txt for details.
14 #if __GNUC__ && !_WIN32
19 // Disable useless warnings about unreferenced functions
20 #pragma warning (disable : 4514)
24 typedef size_t hash_t
;
28 // NOTE: All functions accepting pointer arguments must not be NULL
35 typedef wchar_t dchar
;
42 static dchar
*inc(dchar
*p
) { return p
+ 1; }
43 static dchar
*dec(dchar
*pstart
, dchar
*p
) { (void)pstart
; return p
- 1; }
44 static int len(const dchar
*p
) { return wcslen(p
); }
45 static dchar
get(dchar
*p
) { return *p
; }
46 static dchar
getprev(dchar
*pstart
, dchar
*p
) { (void)pstart
; return p
[-1]; }
47 static dchar
*put(dchar
*p
, dchar c
) { *p
= c
; return p
+ 1; }
48 static int cmp(dchar
*s1
, dchar
*s2
)
51 if (!*s1
&& !*s2
) // wcscmp is broken
54 return wcscmp(s1
, s2
);
58 : ((int)*s1
- (int)*s2
);
61 static int memcmp(const dchar
*s1
, const dchar
*s2
, int nchars
) { return ::memcmp(s1
, s2
, nchars
* sizeof(dchar
)); }
62 static int isDigit(dchar c
) { return '0' <= c
&& c
<= '9'; }
63 static int isAlpha(dchar c
) { return iswalpha(c
); }
64 static int isUpper(dchar c
) { return iswupper(c
); }
65 static int isLower(dchar c
) { return iswlower(c
); }
66 static int isLocaleUpper(dchar c
) { return isUpper(c
); }
67 static int isLocaleLower(dchar c
) { return isLower(c
); }
68 static int toLower(dchar c
) { return isUpper(c
) ? towlower(c
) : c
; }
69 static int toLower(dchar
*p
) { return toLower(*p
); }
70 static int toUpper(dchar c
) { return isLower(c
) ? towupper(c
) : c
; }
71 static dchar
*dup(dchar
*p
) { return ::_wcsdup(p
); } // BUG: out of memory?
72 static dchar
*dup(char *p
);
73 static dchar
*chr(dchar
*p
, unsigned c
) { return wcschr(p
, (dchar
)c
); }
74 static dchar
*rchr(dchar
*p
, unsigned c
) { return wcsrchr(p
, (dchar
)c
); }
75 static dchar
*memchr(dchar
*p
, int c
, int count
);
76 static dchar
*cpy(dchar
*s1
, dchar
*s2
) { return wcscpy(s1
, s2
); }
77 static dchar
*str(dchar
*s1
, dchar
*s2
) { return wcsstr(s1
, s2
); }
78 static hash_t
calcHash(const dchar
*str
, size_t len
);
80 // Case insensitive versions
81 static int icmp(dchar
*s1
, dchar
*s2
) { return wcsicmp(s1
, s2
); }
82 static int memicmp(const dchar
*s1
, const dchar
*s2
, int nchars
) { return ::wcsnicmp(s1
, s2
, nchars
); }
83 static hash_t
icalcHash(const dchar
*str
, size_t len
);
94 #define Dchar_mbmax MB_LEN_MAX
101 #define Dchar_mbmax 6
105 static char mblen
[256];
107 static dchar
*inc(dchar
*p
) { return p
+ mblen
[*p
& 0xFF]; }
108 static dchar
*dec(dchar
*pstart
, dchar
*p
);
109 static int len(const dchar
*p
) { return strlen(p
); }
110 static int get(dchar
*p
);
111 static int getprev(dchar
*pstart
, dchar
*p
)
112 { return *dec(pstart
, p
) & 0xFF; }
113 static dchar
*put(dchar
*p
, unsigned c
);
114 static int cmp(dchar
*s1
, dchar
*s2
) { return strcmp(s1
, s2
); }
115 static int memcmp(const dchar
*s1
, const dchar
*s2
, int nchars
) { return ::memcmp(s1
, s2
, nchars
); }
116 static int isDigit(dchar c
) { return '0' <= c
&& c
<= '9'; }
117 static int isAlpha(dchar c
) { return c
<= 0x7F ? isalpha(c
) : 0; }
118 static int isUpper(dchar c
) { return c
<= 0x7F ? isupper(c
) : 0; }
119 static int isLower(dchar c
) { return c
<= 0x7F ? islower(c
) : 0; }
120 static int isLocaleUpper(dchar c
) { return isUpper(c
); }
121 static int isLocaleLower(dchar c
) { return isLower(c
); }
122 static int toLower(dchar c
) { return isUpper(c
) ? tolower(c
) : c
; }
123 static int toLower(dchar
*p
) { return toLower(*p
); }
124 static int toUpper(dchar c
) { return isLower(c
) ? toupper(c
) : c
; }
125 static dchar
*dup(dchar
*p
) { return ::strdup(p
); } // BUG: out of memory?
126 static dchar
*chr(dchar
*p
, int c
) { return strchr(p
, c
); }
127 static dchar
*rchr(dchar
*p
, int c
) { return strrchr(p
, c
); }
128 static dchar
*memchr(dchar
*p
, int c
, int count
)
129 { return (dchar
*)::memchr(p
, c
, count
); }
130 static dchar
*cpy(dchar
*s1
, dchar
*s2
) { return strcpy(s1
, s2
); }
131 static dchar
*str(dchar
*s1
, dchar
*s2
) { return strstr(s1
, s2
); }
132 static hash_t
calcHash(const dchar
*str
, size_t len
);
134 // Case insensitive versions
135 static int icmp(dchar
*s1
, dchar
*s2
) { return _mbsicmp(s1
, s2
); }
136 static int memicmp(const dchar
*s1
, const dchar
*s2
, int nchars
) { return ::_mbsnicmp(s1
, s2
, nchars
); }
150 #define Dchar_mbmax 1
154 static dchar
*inc(dchar
*p
) { return p
+ 1; }
155 static dchar
*dec(dchar
*pstart
, dchar
*p
) { return p
- 1; }
156 static int len(const dchar
*p
) { return strlen(p
); }
157 static int get(dchar
*p
) { return *p
& 0xFF; }
158 static int getprev(dchar
*pstart
, dchar
*p
) { return p
[-1] & 0xFF; }
159 static dchar
*put(dchar
*p
, unsigned c
) { *p
= c
; return p
+ 1; }
160 static int cmp(dchar
*s1
, dchar
*s2
) { return strcmp(s1
, s2
); }
161 static int memcmp(const dchar
*s1
, const dchar
*s2
, int nchars
) { return ::memcmp(s1
, s2
, nchars
); }
162 static int isDigit(dchar c
) { return '0' <= c
&& c
<= '9'; }
164 static int isAlpha(dchar c
) { return isalpha(c
); }
165 static int isUpper(dchar c
) { return isupper(c
); }
166 static int isLower(dchar c
) { return islower(c
); }
167 static int isLocaleUpper(dchar c
) { return isupper(c
); }
168 static int isLocaleLower(dchar c
) { return islower(c
); }
169 static int toLower(dchar c
) { return isupper(c
) ? tolower(c
) : c
; }
170 static int toLower(dchar
*p
) { return toLower(*p
); }
171 static int toUpper(dchar c
) { return islower(c
) ? toupper(c
) : c
; }
172 static dchar
*dup(dchar
*p
) { return ::strdup(p
); } // BUG: out of memory?
174 static dchar
*chr(dchar
*p
, int c
) { return strchr(p
, c
); }
175 static dchar
*rchr(dchar
*p
, int c
) { return strrchr(p
, c
); }
176 static dchar
*memchr(dchar
*p
, int c
, int count
)
177 { return (dchar
*)::memchr(p
, c
, count
); }
178 static dchar
*cpy(dchar
*s1
, dchar
*s2
) { return strcpy(s1
, s2
); }
179 static dchar
*str(dchar
*s1
, dchar
*s2
) { return strstr(s1
, s2
); }
180 static hash_t
calcHash(const dchar
*str
, size_t len
);
182 // Case insensitive versions
184 static int icmp(dchar
*s1
, dchar
*s2
) { return strcasecmp(s1
, s2
); }
186 static int icmp(dchar
*s1
, dchar
*s2
) { return stricmp(s1
, s2
); }
188 static int memicmp(const dchar
*s1
, const dchar
*s2
, int nchars
) { return ::memicmp(s1
, s2
, nchars
); }
189 static hash_t
icalcHash(const dchar
*str
, size_t len
);