Release 961023
[wine/multimedia.git] / win32 / string32.c
blob011b445e59bf6419ce104073b7be566225e403c2
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 "windows.h"
15 #include "string32.h"
16 #include "xmalloc.h"
18 void STRING32_UniToAnsi(LPSTR dest,LPCWSTR src)
20 static int have_warned=0;
21 while(*src)
23 if(*src>255 && !have_warned)
25 fprintf(stderr,"Cannot deal with non-ANSI characters\n");
26 have_warned=1;
28 *dest++=*src++;
30 /* copy the terminator */
31 *dest = *src;
34 /* FIXME: we need to use unsigned char here, for if
35 * we got chars with the 7th bit set, we will get
36 * negative integers -> wrong unicode values
38 void
39 STRING32_AnsiToUni(LPWSTR dest,LPCSTR src) {
40 unsigned char *usrc;
42 usrc=(unsigned char*)src;
43 while(*usrc)
44 *dest++=*usrc++;
45 *dest = *usrc;
48 LPSTR STRING32_DupUniToAnsi(LPCWSTR src)
50 LPSTR dest=xmalloc(lstrlen32W(src)+1);
51 STRING32_UniToAnsi(dest,src);
52 return dest;
55 LPWSTR STRING32_DupAnsiToUni(LPCSTR src)
57 LPWSTR dest=xmalloc(2*strlen(src)+2);
58 STRING32_AnsiToUni(dest,src);
59 return dest;
62 /* not an API function */
64 WCHAR STRING32_tolowerW(WCHAR c)
66 /* FIXME: Unicode */
67 return tolower(c);
70 LPWSTR
71 STRING32_lstrchrW(LPCWSTR a,WCHAR c) {
72 while(*a) {
73 if (*a==c)
74 return a;
75 a++;
77 return NULL;
80 LPWSTR
81 STRING32_strdupW(LPCWSTR a) {
82 LPWSTR b;
83 int len;
85 len=sizeof(WCHAR)*(lstrlen32W(a)+1);
86 b=(LPWSTR)xmalloc(len);
87 memcpy(b,a,len);
88 return b;