OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/sys_string_conversions.h" | 5 #include "base/sys_string_conversions.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 encoding, | 54 encoding, |
55 0, // lossByte | 55 0, // lossByte |
56 false, // isExternalRepresentation | 56 false, // isExternalRepresentation |
57 reinterpret_cast<UInt8*>(&out_buffer[0]), | 57 reinterpret_cast<UInt8*>(&out_buffer[0]), |
58 out_size, | 58 out_size, |
59 NULL); // usedBufLen | 59 NULL); // usedBufLen |
60 if (converted == 0) | 60 if (converted == 0) |
61 return StringType(); | 61 return StringType(); |
62 | 62 |
63 out_buffer[elements - 1] = '\0'; | 63 out_buffer[elements - 1] = '\0'; |
64 return StringType(&out_buffer[0]); | 64 StringType ret(&out_buffer[0], elements - 1); |
Mark Mentovai
2008/10/22 20:02:31
Good catch!
But can't we just do return StringTyp
| |
65 return ret; | |
65 } | 66 } |
66 | 67 |
67 // Given an STL string |in| with an encoding specified by |in_encoding|, | 68 // Given an STL string |in| with an encoding specified by |in_encoding|, |
68 // convert it to |out_encoding| and return it as an STL string of the | 69 // convert it to |out_encoding| and return it as an STL string of the |
69 // |OutStringType| template type. Returns an empty string on failure. | 70 // |OutStringType| template type. Returns an empty string on failure. |
70 // | 71 // |
71 // Do not assert in this function since it is used by the asssertion code! | 72 // Do not assert in this function since it is used by the asssertion code! |
72 template<typename InStringType, typename OutStringType> | 73 template<typename InStringType, typename OutStringType> |
73 static OutStringType STLStringToSTLStringWithEncodingsT( | 74 static OutStringType STLStringToSTLStringWithEncodingsT( |
74 const InStringType& in, | 75 const InStringType& in, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 | 179 |
179 std::string SysNSStringToUTF8(NSString* nsstring) { | 180 std::string SysNSStringToUTF8(NSString* nsstring) { |
180 return SysCFStringRefToUTF8(reinterpret_cast<CFStringRef>(nsstring)); | 181 return SysCFStringRefToUTF8(reinterpret_cast<CFStringRef>(nsstring)); |
181 } | 182 } |
182 | 183 |
183 std::wstring SysNSStringToWide(NSString* nsstring) { | 184 std::wstring SysNSStringToWide(NSString* nsstring) { |
184 return SysCFStringRefToWide(reinterpret_cast<CFStringRef>(nsstring)); | 185 return SysCFStringRefToWide(reinterpret_cast<CFStringRef>(nsstring)); |
185 } | 186 } |
186 | 187 |
187 } // namespace base | 188 } // namespace base |
OLD | NEW |