migrate substitution keywords to SVN
[reactos.git] / reactos / lib / ntdll / string / wstring.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/string/wstring.c
6 * PURPOSE: Wide string functions
7 * PROGRAMMER: David Welch (welch@mcmail.com)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 * 1998/12/04 RJJ Cleaned up and added i386 def checks
11 */
12
13 /* INCLUDES *****************************************************************/
14
15 #include <ddk/ntddk.h>
16 #include <wchar.h>
17
18
19 /* FUNCTIONS *****************************************************************/
20
21 int _wcsicmp (const wchar_t* cs, const wchar_t * ct)
22 {
23 while (towlower(*cs) == towlower(*ct))
24 {
25 if (*cs == 0)
26 return 0;
27 cs++;
28 ct++;
29 }
30 return towlower(*cs) - towlower(*ct);
31 }
32
33
34 /*
35 * @implemented
36 */
37 wchar_t *_wcslwr (wchar_t *x)
38 {
39 wchar_t *y=x;
40
41 while (*y) {
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 *_wcsupr(wchar_t *x)
70 {
71 wchar_t *y=x;
72
73 while (*y) {
74 *y=towupper(*y);
75 y++;
76 }
77 return x;
78 }
79
80 /*
81 * @implemented
82 */
83 size_t wcscspn(const wchar_t *str,const wchar_t *reject)
84 {
85 wchar_t *s;
86 wchar_t *t;
87 s=(wchar_t *)str;
88 do {
89 t=(wchar_t *)reject;
90 while (*t) {
91 if (*t==*s)
92 break;
93 t++;
94 }
95 if (*t)
96 break;
97 s++;
98 } while (*s);
99 return s-str; /* nr of wchars */
100 }
101
102 /*
103 * @implemented
104 */
105 wchar_t *wcspbrk(const wchar_t *s1, const wchar_t *s2)
106 {
107 const wchar_t *scanp;
108 int c, sc;
109
110 while ((c = *s1++) != 0)
111 {
112 for (scanp = s2; (sc = *scanp++) != 0;)
113 if (sc == c)
114 {
115 return (wchar_t *)(--s1);
116 }
117 }
118 return 0;
119 }
120
121 /*
122 * @implemented
123 */
124 size_t wcsspn(const wchar_t *str,const wchar_t *accept)
125 {
126 wchar_t *s;
127 wchar_t *t;
128 s=(wchar_t *)str;
129 do {
130 t=(wchar_t *)accept;
131 while (*t) {
132 if (*t==*s)
133 break;
134 t++;
135 }
136 if (!*t)
137 break;
138 s++;
139 } while (*s);
140 return s-str; /* nr of wchars */
141 }
142
143
144 /*
145 * @implemented
146 */
147 wchar_t *wcsstr(const wchar_t *s,const wchar_t *b)
148 {
149 wchar_t *x;
150 wchar_t *y;
151 wchar_t *c;
152 x=(wchar_t *)s;
153 while (*x) {
154 if (*x==*b) {
155 y=x;
156 c=(wchar_t *)b;
157 while (*y && *c && *y==*c) {
158 c++;
159 y++;
160 }
161 if (!*c)
162 return x;
163 }
164 x++;
165 }
166 return NULL;
167 }
168
169 /* EOF */