OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/dwrite_localized_strings_win.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 HRESULT DWriteLocalizedStrings::FindLocaleName(const WCHAR* localeName, |
| 12 UINT32* index, |
| 13 BOOL* exists) { |
| 14 for (unsigned int n = 0; n < strings_.size(); n++) { |
| 15 if (_wcsicmp(strings_[n].first.data(), localeName) == 0) { |
| 16 *index = n; |
| 17 *exists = TRUE; |
| 18 return S_OK; |
| 19 } |
| 20 } |
| 21 |
| 22 *index = UINT_MAX; |
| 23 *exists = FALSE; |
| 24 return S_OK; |
| 25 } |
| 26 |
| 27 UINT32 DWriteLocalizedStrings::GetCount() { |
| 28 return strings_.size(); |
| 29 } |
| 30 |
| 31 HRESULT DWriteLocalizedStrings::GetLocaleName(UINT32 index, |
| 32 WCHAR* localeName, |
| 33 UINT32 size) { |
| 34 if (index >= strings_.size()) |
| 35 return E_INVALIDARG; |
| 36 if (size <= strings_[index].first.size()) |
| 37 return E_INVALIDARG; |
| 38 wcsncpy(localeName, strings_[index].first.data(), size); |
| 39 return S_OK; |
| 40 } |
| 41 |
| 42 HRESULT DWriteLocalizedStrings::GetLocaleNameLength(UINT32 index, |
| 43 UINT32* length) { |
| 44 if (index >= strings_.size()) { |
| 45 return E_INVALIDARG; |
| 46 } |
| 47 *length = strings_[index].first.size(); |
| 48 return S_OK; |
| 49 } |
| 50 |
| 51 HRESULT DWriteLocalizedStrings::GetString(UINT32 index, |
| 52 WCHAR* stringBuffer, |
| 53 UINT32 size) { |
| 54 if (index >= strings_.size()) |
| 55 return E_INVALIDARG; |
| 56 if (size <= strings_[index].second.size()) |
| 57 return E_INVALIDARG; |
| 58 wcsncpy(stringBuffer, strings_[index].second.data(), size); |
| 59 return S_OK; |
| 60 } |
| 61 |
| 62 HRESULT DWriteLocalizedStrings::GetStringLength(UINT32 index, UINT32* length) { |
| 63 if (index >= strings_.size()) { |
| 64 return E_INVALIDARG; |
| 65 } |
| 66 *length = strings_[index].second.size(); |
| 67 return S_OK; |
| 68 } |
| 69 |
| 70 HRESULT DWriteLocalizedStrings::RuntimeClassInitialize( |
| 71 std::vector<std::pair<base::string16, base::string16>>* strings) { |
| 72 strings_.swap(*strings); |
| 73 return S_OK; |
| 74 } |
| 75 |
| 76 } // namespace content |
OLD | NEW |