| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/shared_impl/ppb_char_set_shared.h" | 5 #include "ppapi/shared_impl/ppb_char_set_shared.h" |
| 6 | 6 |
| 7 #include "base/i18n/icu_string_conversions.h" | 7 #include "base/i18n/icu_string_conversions.h" |
| 8 #include "ppapi/c/dev/ppb_memory_dev.h" | 8 #include "ppapi/c/dev/ppb_memory_dev.h" |
| 9 #include "ppapi/thunk/thunk.h" | 9 #include "ppapi/thunk/thunk.h" |
| 10 #include "unicode/ucnv.h" | 10 #include "unicode/ucnv.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 ucnv_setFromUCallBack(converter, UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0, | 96 ucnv_setFromUCallBack(converter, UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0, |
| 97 NULL, NULL, &status); | 97 NULL, NULL, &status); |
| 98 break; | 98 break; |
| 99 } | 99 } |
| 100 default: | 100 default: |
| 101 return NULL; | 101 return NULL; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // ucnv_fromUChars returns size not including terminating null. | 104 // ucnv_fromUChars returns size not including terminating null. |
| 105 char* encoded = static_cast<char*>( | 105 char* encoded = static_cast<char*>( |
| 106 thunk::GetPPB_Memory_Dev_Thunk()->MemAlloc(encoded_max_length + 1)); | 106 thunk::GetPPB_Memory_Dev_0_1_Thunk()->MemAlloc(encoded_max_length + 1)); |
| 107 int actual_size = ucnv_fromUChars(converter, encoded, | 107 int actual_size = ucnv_fromUChars(converter, encoded, |
| 108 encoded_max_length, reinterpret_cast<const UChar*>(utf16), utf16_len, | 108 encoded_max_length, reinterpret_cast<const UChar*>(utf16), utf16_len, |
| 109 &status); | 109 &status); |
| 110 ucnv_close(converter); | 110 ucnv_close(converter); |
| 111 if (!U_SUCCESS(status)) { | 111 if (!U_SUCCESS(status)) { |
| 112 thunk::GetPPB_Memory_Dev_Thunk()->MemFree(encoded); | 112 thunk::GetPPB_Memory_Dev_0_1_Thunk()->MemFree(encoded); |
| 113 return NULL; | 113 return NULL; |
| 114 } | 114 } |
| 115 encoded[actual_size] = 0; | 115 encoded[actual_size] = 0; |
| 116 *output_length = actual_size; | 116 *output_length = actual_size; |
| 117 return encoded; | 117 return encoded; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // static | 120 // static |
| 121 uint16_t* PPB_CharSet_Shared::CharSetToUTF16( | 121 uint16_t* PPB_CharSet_Shared::CharSetToUTF16( |
| 122 const char* input, | 122 const char* input, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 return NULL; // Invalid enum value. | 134 return NULL; // Invalid enum value. |
| 135 | 135 |
| 136 // We can convert this call to the implementation in base to avoid code | 136 // We can convert this call to the implementation in base to avoid code |
| 137 // duplication, although this does introduce an extra copy of the data. | 137 // duplication, although this does introduce an extra copy of the data. |
| 138 string16 output; | 138 string16 output; |
| 139 if (!base::CodepageToUTF16(std::string(input, input_len), input_char_set, | 139 if (!base::CodepageToUTF16(std::string(input, input_len), input_char_set, |
| 140 base_on_error, &output)) | 140 base_on_error, &output)) |
| 141 return NULL; | 141 return NULL; |
| 142 | 142 |
| 143 uint16_t* ret_buf = static_cast<uint16_t*>( | 143 uint16_t* ret_buf = static_cast<uint16_t*>( |
| 144 thunk::GetPPB_Memory_Dev_Thunk()->MemAlloc( | 144 thunk::GetPPB_Memory_Dev_0_1_Thunk()->MemAlloc( |
| 145 (output.size() + 1) * sizeof(uint16_t))); | 145 (output.size() + 1) * sizeof(uint16_t))); |
| 146 if (!ret_buf) | 146 if (!ret_buf) |
| 147 return NULL; | 147 return NULL; |
| 148 | 148 |
| 149 *output_length = static_cast<uint32_t>(output.size()); | 149 *output_length = static_cast<uint32_t>(output.size()); |
| 150 memcpy(ret_buf, output.c_str(), (output.size() + 1) * sizeof(uint16_t)); | 150 memcpy(ret_buf, output.c_str(), (output.size() + 1) * sizeof(uint16_t)); |
| 151 return ret_buf; | 151 return ret_buf; |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace ppapi | 154 } // namespace ppapi |
| OLD | NEW |