Accept "in" instance variables
[delight/core.git] / dmd / dchar.h
blob2f33e4ca78a46cb04e9f97370fd75b8fc5be5b71
2 // Copyright (c) 1999-2006 by Digital Mars
3 // All Rights Reserved
4 // written by Walter Bright
5 // www.digitalmars.com
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.
11 #ifndef DCHAR_H
12 #define DCHAR_H
14 #if __GNUC__ && !_WIN32
15 #include "gnuc.h"
16 #endif
18 #if _MSC_VER
19 // Disable useless warnings about unreferenced functions
20 #pragma warning (disable : 4514)
21 #endif
23 //#include "root.h"
24 typedef size_t hash_t;
26 #undef TEXT
28 // NOTE: All functions accepting pointer arguments must not be NULL
30 #if M_UNICODE
32 #include <string.h>
33 #include <wchar.h>
35 typedef wchar_t dchar;
36 #define TEXT(x) L##x
38 #define Dchar_mbmax 1
40 struct 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)
50 #if __DMC__
51 if (!*s1 && !*s2) // wcscmp is broken
52 return 0;
53 #endif
54 return wcscmp(s1, s2);
55 #if 0
56 return (*s1 == *s2)
57 ? wcscmp(s1, s2)
58 : ((int)*s1 - (int)*s2);
59 #endif
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);
86 #elif MCBS
88 #include <limits.h>
89 #include <mbstring.h>
91 typedef char dchar;
92 #define TEXT(x) x
94 #define Dchar_mbmax MB_LEN_MAX
96 #elif UTF8
98 typedef char dchar;
99 #define TEXT(x) x
101 #define Dchar_mbmax 6
103 struct Dchar
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); }
139 #else
141 #include <string.h>
143 #ifndef GCC_SAFE_DMD
144 #include <ctype.h>
145 #endif
147 typedef char dchar;
148 #define TEXT(x) x
150 #define Dchar_mbmax 1
152 struct Dchar
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'; }
163 #ifndef GCC_SAFE_DMD
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?
173 #endif
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
183 #ifdef __GNUC__
184 static int icmp(dchar *s1, dchar *s2) { return strcasecmp(s1, s2); }
185 #else
186 static int icmp(dchar *s1, dchar *s2) { return stricmp(s1, s2); }
187 #endif
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);
192 #endif
193 #endif