Changeset 5451 for trunk/src/kernel32/unicode.cpp
- Timestamp:
- Apr 3, 2001, 4:10:48 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/unicode.cpp
r4964 r5451 1 /* $Id: unicode.cpp,v 1.2 4 2001-01-18 18:14:16sandervl Exp $ */1 /* $Id: unicode.cpp,v 1.25 2001-04-03 14:10:48 sandervl Exp $ */ 2 2 3 3 /* … … 46 46 } 47 47 */ 48 /*********************************************************************** 49 * MultiByteToWideChar (KERNEL32.534) 50 * 51 * PARAMS 52 * page [in] Codepage character set to convert from 53 * flags [in] Character mapping flags 54 * src [in] Source string buffer 55 * srclen [in] Length of source string buffer 56 * dst [in] Destination buffer 57 * dstlen [in] Length of destination buffer 58 * 59 * NOTES 60 * The returned length includes the null terminator character. 61 * 62 * RETURNS 63 * Success: If dstlen > 0, number of characters written to destination 64 * buffer. If dstlen == 0, number of characters needed to do 65 * conversion. 66 * Failure: 0. Occurs if not enough space is available. 67 * 68 * ERRORS 69 * ERROR_INSUFFICIENT_BUFFER 70 * ERROR_INVALID_FLAGS (not yet implemented) 71 * ERROR_INVALID_PARAMETER (not yet implemented) 72 * 73 * BUGS 74 * Does not properly handle codepage conversions. 75 * Does not properly handle flags. 76 * 77 */ 78 INT WINAPI MultiByteToWideChar(UINT page, DWORD flags, 79 LPCSTR src, INT srclen, 80 LPWSTR dst, INT dstlen) 81 { 82 int ret; 83 84 dprintf2(("MultiByteToWideChar: %d %x (%s %d) (%x %d)", page, flags, src, srclen, dst, dstlen)); 85 86 if (!src || (!dst && dstlen)) 87 { 88 SetLastError( ERROR_INVALID_PARAMETER ); 89 return 0; 90 } 91 //-1 means the input string is null terminated and we need to calculate 92 //its length 93 if (srclen == -1) 94 srclen = lstrlenA(src)+1; 95 96 if (!dstlen) 97 return srclen; 98 99 ret = srclen; 100 while (srclen && dstlen) { 101 *dst = (WCHAR)(unsigned char)*src; 102 dst++; src++; 103 dstlen--; srclen--; 104 } 105 if (!dstlen && srclen) { 106 SetLastError(ERROR_INSUFFICIENT_BUFFER); 107 return 0; 108 } 109 return ret; 110 } 111 112 /*********************************************************************** 113 * WideCharToMultiByte (KERNEL32.727) 114 * 115 * PARAMS 116 * page [in] Codepage character set to convert to 117 * flags [in] Character mapping flags 118 * src [in] Source string buffer 119 * srclen [in] Length of source string buffer 120 * dst [in] Destination buffer 121 * dstlen [in] Length of destination buffer 122 * defchar [in] Default character to use for conversion if no exact 123 * conversion can be made 124 * used [out] Set if default character was used in the conversion 125 * 126 * NOTES 127 * The returned length includes the null terminator character. 128 * 129 * RETURNS 130 * Success: If dstlen > 0, number of characters written to destination 131 * buffer. If dstlen == 0, number of characters needed to do 132 * conversion. 133 * Failure: 0. Occurs if not enough space is available. 134 * 135 * ERRORS 136 * ERROR_INSUFFICIENT_BUFFER 137 * ERROR_INVALID_FLAGS (not yet implemented) 138 * 139 * BUGS 140 * Does not properly handle codepage conversions. 141 * Does not properly handle flags. 142 * 143 */ 144 INT WIN32API WideCharToMultiByte(UINT page, DWORD flags, LPCWSTR src, 145 INT srclen,LPSTR dst, INT dstlen, 146 LPCSTR defchar, BOOL *used) 147 { 148 int count = 0; 149 int eos = 0; 150 int care_for_eos=0; 151 int dont_copy= (dstlen==0); 152 153 dprintf2(("WideCharToMultiByte: %d %x (%x %d) (%x %d)", page, flags, src, srclen, dst, dstlen)); 154 155 if ((!src) || ((!dst) && (!dont_copy)) ) 156 { 157 SetLastError(ERROR_INVALID_PARAMETER); 158 return 0; 159 } 160 161 if (page!=GetACP() && page!=CP_OEMCP && page!=CP_ACP) 162 dprintf(("WideCharToMultiByte, Conversion in CP %d not supported\n",page)); 163 #if 0 164 if (flags) 165 dprintf(("WideCharToMultiByte, flags %lx not supported\n",flags)); 166 #endif 167 if(used) 168 *used=0; 169 if (srclen == -1) 170 { 171 srclen = lstrlenW(src)+1; 172 care_for_eos=1; 173 } 174 while(srclen && (dont_copy || dstlen)) 175 { 176 if(!dont_copy){ 177 if(*src<256) 178 *dst = *src; 179 else 180 { 181 /* ??? The WC_DEFAULTCHAR flag only gets used in 182 * combination with the WC_COMPOSITECHECK flag or at 183 * least this is what it seems from using the function 184 * on NT4.0 in combination with reading the documentation. 185 */ 186 *dst = defchar ? *defchar : '?'; 187 if(used)*used=1; 188 } 189 dstlen--; 190 dst++; 191 } 192 count++; 193 srclen--; 194 if((!*src) && care_for_eos) { 195 eos = 1; 196 break; 197 } 198 src++; 199 } 200 if (dont_copy) 201 return count; 202 203 if (!eos && srclen > 0) { 204 SetLastError(ERROR_INSUFFICIENT_BUFFER); 205 return 0; 206 } 207 return count; 208 } 209 //****************************************************************************** 210 //****************************************************************************** 211 BOOL WIN32API GetCPInfo(UINT uCodePage, CPINFO *lpCPInfo) 212 { 213 dprintf(("GetCPInfo (%d), not correctly implemented\n", uCodePage)); 214 memset(lpCPInfo, 0, sizeof(CPINFO)); 215 lpCPInfo->MaxCharSize = 1; 216 lpCPInfo->DefaultChar[0] = 'a'; 217 218 return(TRUE); 219 } 220 48 //****************************************************************************** 221 49 //****************************************************************************** 222 50 // unilen: length of astring buffer (including 0 terminator)
Note:
See TracChangeset
for help on using the changeset viewer.