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