Changeset 1838 for trunk/src/kernel32/unicode.cpp
- Timestamp:
- Nov 25, 1999, 8:19:57 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/unicode.cpp
r917 r1838 1 /* $Id: unicode.cpp,v 1.1 4 1999-09-13 09:06:05sandervl Exp $ */1 /* $Id: unicode.cpp,v 1.15 1999-11-25 19:19:57 sandervl Exp $ */ 2 2 3 3 /* … … 41 41 } 42 42 43 //****************************************************************************** 44 //Not identical, but close enough 45 //****************************************************************************** 46 int WIN32API MultiByteToWideChar(UINT uCodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, 47 int cchMultiByte, LPWSTR lpWideCharStr, int cchWideChar) 48 { 49 int i, len; 50 51 // dprintf(("MultiByteToWideChar %s\n", lpMultiByteStr)); 52 53 if((int)lpMultiByteStr == (int)lpWideCharStr) {//not allowed 54 SetLastError(ERROR_INVALID_PARAMETER); 55 return(FALSE); 56 } 57 if(cchWideChar == 0) {//return space required for conversion 58 if(cchMultiByte == -1) 59 cchMultiByte = strlen(lpMultiByteStr) + 1; 60 return(cchMultiByte); //return length in wide chars 61 } 62 if(cchMultiByte == -1) 63 cchMultiByte = strlen(lpMultiByteStr) + 1; 64 65 len = min(cchWideChar, cchMultiByte); 66 for(i=0;i<=len;i++) { //including 0 terminator 67 lpWideCharStr[i] = lpMultiByteStr[i]; 68 } 69 return(len); 70 } 71 //****************************************************************************** 72 //****************************************************************************** 73 //Not identical, close enough 74 //Forget about characters that can't be mapped; just do it 75 //****************************************************************************** 76 int WIN32API WideCharToMultiByte(UINT uCodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, 77 int cchWideChar, LPSTR lpMultiByteStr, 78 int cchMultiByte, LPCSTR lpDefaultChar, 79 LPBOOL lpfUsedDefaultChar) 80 { 81 int i, len; 82 83 // dprintf(("WideCharToMultiByte\n")); 84 85 if((int)lpMultiByteStr == (int)lpWideCharStr) {//not allowed 86 SetLastError(ERROR_INVALID_PARAMETER); 87 return(FALSE); 88 } 89 if(cchMultiByte == 0) {//return space required for conversion 90 if(cchWideChar == -1) cchWideChar = UniStrlen((UniChar *)lpWideCharStr); 91 return(cchWideChar); 92 } 93 if(cchWideChar == -1) 94 cchWideChar = UniStrlen((UniChar*)lpWideCharStr); 95 96 len = min(cchWideChar, cchMultiByte); 97 for(i=0;i<=len;i++) { //including 0 terminator 98 lpMultiByteStr[i] = (UCHAR)lpWideCharStr[i]; 99 } 100 return(len); 43 /*********************************************************************** 44 * MultiByteToWideChar (KERNEL32.534) 45 * 46 * PARAMS 47 * page [in] Codepage character set to convert from 48 * flags [in] Character mapping flags 49 * src [in] Source string buffer 50 * srclen [in] Length of source string buffer 51 * dst [in] Destination buffer 52 * dstlen [in] Length of destination buffer 53 * 54 * NOTES 55 * The returned length includes the null terminator character. 56 * 57 * RETURNS 58 * Success: If dstlen > 0, number of characters written to destination 59 * buffer. If dstlen == 0, number of characters needed to do 60 * conversion. 61 * Failure: 0. Occurs if not enough space is available. 62 * 63 * ERRORS 64 * ERROR_INSUFFICIENT_BUFFER 65 * ERROR_INVALID_FLAGS (not yet implemented) 66 * ERROR_INVALID_PARAMETER (not yet implemented) 67 * 68 * BUGS 69 * Does not properly handle codepage conversions. 70 * Does not properly handle flags. 71 * 72 */ 73 INT WINAPI MultiByteToWideChar(UINT page, DWORD flags, 74 LPCSTR src, INT srclen, 75 LPWSTR dst, INT dstlen) 76 { 77 int ret; 78 79 if (srclen == -1) 80 srclen = lstrlenA(src)+1; 81 if (!dstlen || !dst) 82 return srclen; 83 84 ret = srclen; 85 while (srclen && dstlen) { 86 *dst = (WCHAR)(unsigned char)*src; 87 dst++; src++; 88 dstlen--; srclen--; 89 } 90 if (!dstlen && srclen) { 91 SetLastError(ERROR_INSUFFICIENT_BUFFER); 92 return 0; 93 } 94 return ret; 95 } 96 97 /*********************************************************************** 98 * WideCharToMultiByte (KERNEL32.727) 99 * 100 * PARAMS 101 * page [in] Codepage character set to convert to 102 * flags [in] Character mapping flags 103 * src [in] Source string buffer 104 * srclen [in] Length of source string buffer 105 * dst [in] Destination buffer 106 * dstlen [in] Length of destination buffer 107 * defchar [in] Default character to use for conversion if no exact 108 * conversion can be made 109 * used [out] Set if default character was used in the conversion 110 * 111 * NOTES 112 * The returned length includes the null terminator character. 113 * 114 * RETURNS 115 * Success: If dstlen > 0, number of characters written to destination 116 * buffer. If dstlen == 0, number of characters needed to do 117 * conversion. 118 * Failure: 0. Occurs if not enough space is available. 119 * 120 * ERRORS 121 * ERROR_INSUFFICIENT_BUFFER 122 * ERROR_INVALID_FLAGS (not yet implemented) 123 * 124 * BUGS 125 * Does not properly handle codepage conversions. 126 * Does not properly handle flags. 127 * 128 */ 129 INT WIN32API WideCharToMultiByte(UINT page, DWORD flags, LPCWSTR src, 130 INT srclen,LPSTR dst, INT dstlen, 131 LPCSTR defchar, BOOL *used) 132 { 133 int count = 0; 134 int eos = 0; 135 int care_for_eos=0; 136 int dont_copy= (dstlen==0); 137 138 if ((!src) || ((!dst) && (!dont_copy)) ) 139 { SetLastError(ERROR_INVALID_PARAMETER); 140 return 0; 141 } 142 143 if (page!=GetACP() && page!=CP_OEMCP && page!=CP_ACP) 144 dprintf(("WideCharToMultiByte, Conversion in CP %d not supported\n",page)); 145 #if 0 146 if (flags) 147 dprintf(("WideCharToMultiByte, flags %lx not supported\n",flags)); 148 #endif 149 if(used) 150 *used=0; 151 if (srclen == -1) 152 { 153 srclen = lstrlenW(src)+1; 154 care_for_eos=1; 155 } 156 while(srclen && (dont_copy || dstlen)) 157 { 158 if(!dont_copy){ 159 if(*src<256) 160 *dst = *src; 161 else 162 { 163 /* ??? The WC_DEFAULTCHAR flag only gets used in 164 * combination with the WC_COMPOSITECHECK flag or at 165 * least this is what it seems from using the function 166 * on NT4.0 in combination with reading the documentation. 167 */ 168 *dst = defchar ? *defchar : '?'; 169 if(used)*used=1; 170 } 171 dstlen--; 172 dst++; 173 } 174 count++; 175 srclen--; 176 if((!*src) && care_for_eos) { 177 eos = 1; 178 break; 179 } 180 src++; 181 } 182 if (dont_copy) 183 return count; 184 185 if (!eos && srclen > 0) { 186 SetLastError(ERROR_INSUFFICIENT_BUFFER); 187 return 0; 188 } 189 return count; 101 190 } 102 191 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.