KD System Rewrite:
[reactos.git] / reactos / ntoskrnl / rtl / wstring.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/rtl/wstring.c
6 * PURPOSE: Wide string functions
7 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <internal/debug.h>
16
17 /* FUNCTIONS *****************************************************************/
18
19 int _wcsicmp (const wchar_t* cs, const wchar_t* ct)
20 {
21 while (*cs != '\0' && *ct != '\0' && towupper(*cs) == towupper(*ct))
22 {
23 cs++;
24 ct++;
25 }
26 return *cs - *ct;
27 }
28
29 /*
30 * @implemented
31 */
32 wchar_t *_wcslwr (wchar_t *x)
33 {
34 wchar_t *y=x;
35
36 while (*y)
37 {
38 *y=towlower(*y);
39 y++;
40 }
41 return x;
42 }
43
44
45 /*
46 * @implemented
47 */
48 int _wcsnicmp (const wchar_t * cs,const wchar_t * ct,size_t count)
49 {
50 if (count == 0)
51 return 0;
52 do {
53 if (towupper(*cs) != towupper(*ct++))
54 return towupper(*cs) - towupper(*--ct);
55 if (*cs++ == 0)
56 break;
57 } while (--count != 0);
58 return 0;
59 }
60
61
62 /*
63 * @implemented
64 */
65 wchar_t *_wcsnset (wchar_t* wsToFill, wchar_t wcFill, size_t sizeMaxFill)
66 {
67 wchar_t *t = wsToFill;
68 int i = 0;
69 while( *wsToFill != 0 && i < (int) sizeMaxFill)
70 {
71 *wsToFill = wcFill;
72 wsToFill++;
73 i++;
74 }
75 return t;
76 }
77
78
79 /*
80 * @implemented
81 */
82 wchar_t *_wcsrev(wchar_t *s)
83 {
84 wchar_t *e;
85 wchar_t a;
86 e=s;
87 while (*e)
88 e++;
89 while (s<e)
90 {
91 a=*s;
92 *s=*e;
93 *e=a;
94 s++;
95 e--;
96 }
97 return s;
98 }
99
100
101 /*
102 * @implemented
103 */
104 wchar_t *_wcsupr(wchar_t *x)
105 {
106 wchar_t *y=x;
107
108 while (*y)
109 {
110 *y=towupper(*y);
111 y++;
112 }
113 return x;
114 }
115
116 /*
117 * @implemented
118 */
119 size_t wcscspn(const wchar_t *str,const wchar_t *reject)
120 {
121 wchar_t *s;
122 wchar_t *t;
123 s=(wchar_t *)str;
124 do {
125 t=(wchar_t *)reject;
126 while (*t) {
127 if (*t==*s)
128 break;
129 t++;
130 }
131 if (*t)
132 break;
133 s++;
134 } while (*s);
135 return s-str; /* nr of wchars */
136 }
137
138 /*
139 * @implemented
140 */
141 size_t wcsspn(const wchar_t *str,const wchar_t *accept)
142 {
143 wchar_t *s;
144 wchar_t *t;
145 s=(wchar_t *)str;
146 do
147 {
148 t=(wchar_t *)accept;
149 while (*t)
150 {
151 if (*t==*s)
152 break;
153 t++;
154 }
155 if (!*t)
156 break;
157 s++;
158 } while (*s);
159 return s-str; /* nr of wchars */
160 }
161
162
163 /*
164 * @implemented
165 */
166 wchar_t *wcsstr(const wchar_t *s,const wchar_t *b)
167 {
168 wchar_t *x;
169 wchar_t *y;
170 wchar_t *c;
171 x=(wchar_t *)s;
172 while (*x)
173 {
174 if (*x==*b)
175 {
176 y=x;
177 c=(wchar_t *)b;
178 while (*y && *c && *y==*c)
179 {
180 c++;
181 y++;
182 }
183 if (!*c)
184 return x;
185 }
186 x++;
187 }
188 return NULL;
189 }