Release 960606
[wine/multimedia.git] / win32 / string32.c
blobc888d1105000ae83821ceb50f21ce054d56e214f
1 /*
2 * Unicode string management
4 * Copyright 1996 Martin von Loewis
6 * Conversion between Unicode and ISO-8859-1 is inherently lossy,
7 * so the conversion code should be called only if it does not matter
8 *
9 */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <ctype.h>
14 #include "string32.h"
15 #include "xmalloc.h"
17 int
18 STRING32_UniLen(LPCWSTR s)
20 int i;
21 for(i=0;*s;s++)
22 i++;
23 return i;
26 void STRING32_UniToAnsi(LPSTR dest,LPCWSTR src)
28 static int have_warned=0;
29 while(*src)
31 if(*src>255 && !have_warned)
33 fprintf(stderr,"Cannot deal with non-ANSI characters\n");
34 have_warned=1;
36 *dest++=*src++;
38 /* copy the terminator */
39 *dest = *src;
42 /* FIXME: we need to use unsigned char here, for if
43 * we got chars with the 7th bit set, we will get
44 * negative integers -> wrong unicode values
46 void
47 STRING32_AnsiToUni(LPWSTR dest,LPCSTR src) {
48 unsigned char *usrc;
50 usrc=(unsigned char*)src;
51 while(*usrc)
52 *dest++=*usrc++;
53 *dest = *usrc;
56 LPSTR STRING32_DupUniToAnsi(LPCWSTR src)
58 LPSTR dest=xmalloc(STRING32_UniLen(src)+1);
59 STRING32_UniToAnsi(dest,src);
60 return dest;
63 LPWSTR STRING32_DupAnsiToUni(LPCSTR src)
65 LPWSTR dest=xmalloc(2*strlen(src)+2);
66 STRING32_AnsiToUni(dest,src);
67 return dest;
70 LPWSTR STRING32_lstrcpyW(LPWSTR dst, LPCWSTR src)
72 register LPWSTR p = dst;
73 while ((*p++ = *src++));
74 return dst;
78 DWORD STRING32_lstrlenW(LPCWSTR str)
80 int len;
81 for(len=0;*str;str++)
82 len++;
83 return len;
86 /* not an API function */
88 WCHAR STRING32_tolowerW(WCHAR c)
90 /* FIXME: Unicode */
91 return tolower(c);
94 int STRING32_lstrcmpniW(LPCWSTR a,LPCWSTR b,DWORD len)
96 while(len--)
98 WCHAR c1,c2;
99 c1 = STRING32_tolowerW(*a);
100 c2 = STRING32_tolowerW(*b);
101 if(c1<c2)return -1;
102 if(c1>c2)return 1;
103 if(c1==0 && c2==0)return 0;
104 if(c1==0)return -1;
105 if(c2==0)return 1;
106 a++;
107 b++;
109 return 0;
113 STRING32_lstrcmpW(LPCWSTR a,LPCWSTR b) {
114 WCHAR diff;
116 while(*a && *b) {
117 diff=*a-*b;
118 if (diff) return diff;
119 a++;
120 b++;
122 if (*a) return *a;
123 if (*b) return -*b;
124 return 0;
127 LPWSTR
128 STRING32_lstrchrW(LPCWSTR a,WCHAR c) {
129 while(*a) {
130 if (*a==c)
131 return a;
132 a++;
134 return NULL;
137 LPWSTR
138 STRING32_strdupW(LPCWSTR a) {
139 LPWSTR b;
140 int len;
142 len=sizeof(WCHAR)*(STRING32_UniLen(a)+1);
143 b=(LPWSTR)xmalloc(len);
144 memcpy(b,a,len);
145 return b;