Mercurial > vba-clojure
view src/win32/7zip/7z/CPP/Common/StringConvert.cpp @ 6:458a4f18f3cd
working on lua generation
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:48:33 -0600 |
parents | f9f4f1b99eed |
children |
line wrap: on
line source
1 // Common/StringConvert.cpp3 #include "StdAfx.h"5 #include "StringConvert.h"7 #ifndef _WIN328 #include <stdlib.h>9 #endif11 #ifdef _WIN3212 UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)13 {14 UString resultString;15 if (!srcString.IsEmpty())16 {17 int numChars = MultiByteToWideChar(codePage, 0, srcString,18 srcString.Length(), resultString.GetBuffer(srcString.Length()),19 srcString.Length() + 1);20 #ifndef _WIN32_WCE21 if (numChars == 0)22 throw 282228;23 #endif24 resultString.ReleaseBuffer(numChars);25 }26 return resultString;27 }29 AString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultChar, bool &defaultCharWasUsed)30 {31 AString dest;32 defaultCharWasUsed = false;33 if (!s.IsEmpty())34 {35 int numRequiredBytes = s.Length() * 2;36 BOOL defUsed;37 int numChars = WideCharToMultiByte(codePage, 0, s, s.Length(),38 dest.GetBuffer(numRequiredBytes), numRequiredBytes + 1,39 &defaultChar, &defUsed);40 defaultCharWasUsed = (defUsed != FALSE);41 #ifndef _WIN32_WCE42 if (numChars == 0)43 throw 282229;44 #endif45 dest.ReleaseBuffer(numChars);46 }47 return dest;48 }50 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)51 {52 bool defaultCharWasUsed;53 return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);54 }56 #ifndef _WIN32_WCE57 AString SystemStringToOemString(const CSysString &srcString)58 {59 AString result;60 CharToOem(srcString, result.GetBuffer(srcString.Length() * 2));61 result.ReleaseBuffer();62 return result;63 }64 #endif66 #else68 UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)69 {70 UString resultString;71 for (int i = 0; i < srcString.Length(); i++)72 resultString += wchar_t(srcString[i]);73 /*74 if (!srcString.IsEmpty())75 {76 int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);77 if (numChars < 0) throw "Your environment does not support UNICODE";78 resultString.ReleaseBuffer(numChars);79 }80 */81 return resultString;82 }84 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)85 {86 AString resultString;87 for (int i = 0; i < srcString.Length(); i++)88 resultString += char(srcString[i]);89 /*90 if (!srcString.IsEmpty())91 {92 int numRequiredBytes = srcString.Length() * 6 + 1;93 int numChars = wcstombs(resultString.GetBuffer(numRequiredBytes), srcString, numRequiredBytes);94 if (numChars < 0) throw "Your environment does not support UNICODE";95 resultString.ReleaseBuffer(numChars);96 }97 */98 return resultString;99 }101 #endif