Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: base/environment.cc

Issue 1171973003: Move StringToUpperASCII to base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/files/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/environment.h" 5 #include "base/environment.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 12
13 #if defined(OS_POSIX) 13 #if defined(OS_POSIX)
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #elif defined(OS_WIN) 15 #elif defined(OS_WIN)
16 #include <windows.h> 16 #include <windows.h>
17 #endif 17 #endif
18 18
19 namespace base { 19 namespace base {
20 20
21 namespace { 21 namespace {
22 22
23 class EnvironmentImpl : public base::Environment { 23 class EnvironmentImpl : public Environment {
24 public: 24 public:
25 bool GetVar(const char* variable_name, std::string* result) override { 25 bool GetVar(const char* variable_name, std::string* result) override {
26 if (GetVarImpl(variable_name, result)) 26 if (GetVarImpl(variable_name, result))
27 return true; 27 return true;
28 28
29 // Some commonly used variable names are uppercase while others 29 // Some commonly used variable names are uppercase while others
30 // are lowercase, which is inconsistent. Let's try to be helpful 30 // are lowercase, which is inconsistent. Let's try to be helpful
31 // and look for a variable name with the reverse case. 31 // and look for a variable name with the reverse case.
32 // I.e. HTTP_PROXY may be http_proxy for some users/systems. 32 // I.e. HTTP_PROXY may be http_proxy for some users/systems.
33 char first_char = variable_name[0]; 33 char first_char = variable_name[0];
34 std::string alternate_case_var; 34 std::string alternate_case_var;
35 if (first_char >= 'a' && first_char <= 'z') 35 if (first_char >= 'a' && first_char <= 'z')
36 alternate_case_var = StringToUpperASCII(std::string(variable_name)); 36 alternate_case_var = StringToUpperASCII(std::string(variable_name));
37 else if (first_char >= 'A' && first_char <= 'Z') 37 else if (first_char >= 'A' && first_char <= 'Z')
38 alternate_case_var = base::StringToLowerASCII(std::string(variable_name)); 38 alternate_case_var = StringToLowerASCII(std::string(variable_name));
39 else 39 else
40 return false; 40 return false;
41 return GetVarImpl(alternate_case_var.c_str(), result); 41 return GetVarImpl(alternate_case_var.c_str(), result);
42 } 42 }
43 43
44 bool SetVar(const char* variable_name, 44 bool SetVar(const char* variable_name,
45 const std::string& new_value) override { 45 const std::string& new_value) override {
46 return SetVarImpl(variable_name, new_value); 46 return SetVarImpl(variable_name, new_value);
47 } 47 }
48 48
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 for (size_t i = 0; i < result_indices.size(); i++) 227 for (size_t i = 0; i < result_indices.size(); i++)
228 result[i] = &storage_data[result_indices[i]]; 228 result[i] = &storage_data[result_indices[i]];
229 result[result_indices.size()] = 0; // Null terminator. 229 result[result_indices.size()] = 0; // Null terminator.
230 230
231 return result.Pass(); 231 return result.Pass();
232 } 232 }
233 233
234 #endif // OS_POSIX 234 #endif // OS_POSIX
235 235
236 } // namespace base 236 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/files/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698