Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/plugin/PluginSystem.cpp

Issue 5163581322559488: Issue 1283 - wrong usage of memset, fix sizeof, make proper initializing (Closed)
Left Patch Set: fix diff direction Created Oct. 8, 2014, 9:12 p.m.
Right Patch Set: remove intializating call Created Oct. 13, 2014, 9:47 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/plugin/PluginSettings.cpp ('k') | src/shared/Communication.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 #include "PluginSystem.h" 2 #include "PluginSystem.h"
3 #include "PluginClient.h" 3 #include "PluginClient.h"
4 #include <array> 4 #include <array>
5 5
6 std::wstring GetBrowserLanguage() 6 std::wstring GetBrowserLanguage()
7 { 7 {
8 LANGID lcid = GetUserDefaultLangID(); 8 LANGID lcid = GetUserDefaultLangID();
9 std::wstring lang; 9 std::wstring lang;
10 // we use `size() - 1` here to avoid additional calls to get the required size or to get the 10 // According to http://msdn.microsoft.com/en-us/library/windows/desktop/dd3738 48(v=vs.85).aspx
11 // number of retrieved characters. 11 // The maximum number of characters allowed for this string is nine, including a terminating null character.
12 { 12 {
13 std::array<wchar_t, 9> localeLanguage; 13 std::array<wchar_t, 9> localeLanguage;
14 localeLanguage.fill(L'\0'); 14 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data() , localeLanguage.size());
Oleksandr 2014/10/17 07:09:07 We could use std::wstring for localeLanguage here
15 int res = GetLocaleInfoW(lcid, LOCALE_SISO639LANGNAME, localeLanguage.data() , localeLanguage.size() - 1);
16 if (res == 0) 15 if (res == 0)
17 { 16 {
18 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed"); 17 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - Failed");
19 } 18 }
20 else 19 else
21 { 20 {
22 lang += localeLanguage.data(); 21 lang += localeLanguage.data();
23 } 22 }
24 } 23 }
25 lang += L"-"; 24 lang += L"-";
26 { 25 {
27 std::array<wchar_t, 9> localeCountry; 26 std::array<wchar_t, 9> localeCountry;
28 localeCountry.fill(L'\0'); 27 int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data() , localeCountry.size());
29 int res = GetLocaleInfoW(lcid, LOCALE_SISO3166CTRYNAME, localeCountry.data() , localeCountry.size() - 1);
30 if (res == 0) 28 if (res == 0)
31 { 29 {
32 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country"); 30 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_BROWSER_LANGUAGE, "System::GetBrowserLang - failed to retrieve country");
33 } 31 }
34 else 32 else
35 { 33 {
36 lang += localeCountry.data(); 34 lang += localeCountry.data();
37 } 35 }
38 } 36 }
39 return lang; 37 return lang;
40 } 38 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld