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