Chromium Code Reviews| 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/child/dwrite_font_proxy/dwrite_localized_strings_win.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 DWriteLocalizedStrings::~DWriteLocalizedStrings() {} | |
| 12 | |
| 13 HRESULT DWriteLocalizedStrings::FindLocaleName(const WCHAR* locale_name, | |
| 14 UINT32* index, | |
| 15 BOOL* exists) { | |
| 16 for (unsigned int n = 0; n < strings_.size(); ++n) { | |
|
Alexei Svitkine (slow)
2015/11/25 20:17:45
Convention is to use size_t for std::vector indexe
Ilya Kulshin
2015/12/02 02:23:01
Done.
| |
| 17 if (_wcsicmp(strings_[n].first.data(), locale_name) == 0) { | |
| 18 *index = n; | |
| 19 *exists = TRUE; | |
| 20 return S_OK; | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 *index = UINT_MAX; | |
| 25 *exists = FALSE; | |
| 26 return S_OK; | |
| 27 } | |
| 28 | |
| 29 UINT32 DWriteLocalizedStrings::GetCount() { | |
| 30 return strings_.size(); | |
| 31 } | |
| 32 | |
| 33 HRESULT DWriteLocalizedStrings::GetLocaleName(UINT32 index, | |
| 34 WCHAR* locale_name, | |
| 35 UINT32 size) { | |
| 36 if (index >= strings_.size()) | |
| 37 return E_INVALIDARG; | |
| 38 if (size <= strings_[index].first.size()) | |
|
Alexei Svitkine (slow)
2015/11/25 20:17:45
If it's equal, shouldn't it be OK? Or is this to a
Ilya Kulshin
2015/12/02 02:23:01
Done.
| |
| 39 return E_INVALIDARG; | |
| 40 wcsncpy(locale_name, strings_[index].first.data(), size); | |
|
Alexei Svitkine (slow)
2015/11/25 20:17:45
This isn't correct. You're copying |size| bytes, b
Ilya Kulshin
2015/12/02 02:23:01
wcsncpy will not overread the source (it will inst
| |
| 41 return S_OK; | |
| 42 } | |
| 43 | |
| 44 HRESULT DWriteLocalizedStrings::GetLocaleNameLength(UINT32 index, | |
| 45 UINT32* length) { | |
| 46 if (index >= strings_.size()) | |
| 47 return E_INVALIDARG; | |
| 48 *length = strings_[index].first.size(); | |
| 49 return S_OK; | |
| 50 } | |
| 51 | |
| 52 HRESULT DWriteLocalizedStrings::GetString(UINT32 index, | |
| 53 WCHAR* string_buffer, | |
| 54 UINT32 size) { | |
| 55 if (index >= strings_.size()) | |
| 56 return E_INVALIDARG; | |
| 57 if (size <= strings_[index].second.size()) | |
| 58 return E_INVALIDARG; | |
| 59 wcsncpy(string_buffer, strings_[index].second.data(), size); | |
| 60 return S_OK; | |
| 61 } | |
| 62 | |
| 63 HRESULT DWriteLocalizedStrings::GetStringLength(UINT32 index, UINT32* length) { | |
| 64 if (index >= strings_.size()) | |
| 65 return E_INVALIDARG; | |
| 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 |