Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: third_party/lzma/v4_65/files/CPP/Common/StringConvert.cpp

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Common/StringConvert.cpp
2
3 #include "StdAfx.h"
4
5 #include "StringConvert.h"
6
7 #ifndef _WIN32
8 #include <stdlib.h>
9 #endif
10
11 #ifdef _WIN32
12 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_WCE
21 if (numChars == 0)
22 throw 282228;
23 #endif
24 resultString.ReleaseBuffer(numChars);
25 }
26 return resultString;
27 }
28
29 AString UnicodeStringToMultiByte(const UString &s, UINT codePage, char defaultCh ar, 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_WCE
42 if (numChars == 0)
43 throw 282229;
44 #endif
45 dest.ReleaseBuffer(numChars);
46 }
47 return dest;
48 }
49
50 AString UnicodeStringToMultiByte(const UString &srcString, UINT codePage)
51 {
52 bool defaultCharWasUsed;
53 return UnicodeStringToMultiByte(srcString, codePage, '_', defaultCharWasUsed);
54 }
55
56 #ifndef _WIN32_WCE
57 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 #endif
65
66 #else
67
68 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()), srcStrin g, srcString.Length() + 1);
77 if (numChars < 0) throw "Your environment does not support UNICODE";
78 resultString.ReleaseBuffer(numChars);
79 }
80 */
81 return resultString;
82 }
83
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 }
100
101 #endif
102
OLDNEW
« no previous file with comments | « third_party/lzma/v4_65/files/CPP/Common/StringConvert.h ('k') | third_party/lzma/v4_65/files/CPP/Common/StringToInt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698