| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/translate/core/common/translate_util.h" | 5 #include "components/translate/core/common/translate_util.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| 11 #include "components/translate/core/common/translate_switches.h" | 11 #include "components/translate/core/common/translate_switches.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Split the |language| into two parts. For example, if |language| is 'en-US', | 16 // Split the |language| into two parts. For example, if |language| is 'en-US', |
| 17 // this will be split into the main part 'en' and the tail part '-US'. | 17 // this will be split into the main part 'en' and the tail part '-US'. |
| 18 void SplitIntoMainAndTail(const std::string& language, | 18 void SplitIntoMainAndTail(const std::string& language, |
| 19 std::string* main_part, | 19 std::string* main_part, |
| 20 std::string* tail_part) { | 20 std::string* tail_part) { |
| 21 DCHECK(main_part); | 21 DCHECK(main_part); |
| 22 DCHECK(tail_part); | 22 DCHECK(tail_part); |
| 23 | 23 |
| 24 std::vector<std::string> chunks; | 24 std::vector<base::StringPiece> chunks = base::SplitStringPiece( |
| 25 base::SplitString(language, '-', &chunks); | 25 language, "-", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 26 if (chunks.size() == 0u) | 26 if (chunks.empty()) |
| 27 return; | 27 return; |
| 28 | 28 |
| 29 *main_part = chunks[0]; | 29 chunks[0].CopyToString(main_part); |
| 30 *tail_part = language.substr(main_part->size()); | 30 *tail_part = language.substr(main_part->size()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace translate { | 35 namespace translate { |
| 36 | 36 |
| 37 struct LanguageCodePair { | 37 struct LanguageCodePair { |
| 38 // Code used in supporting list of Translate. | 38 // Code used in supporting list of Translate. |
| 39 const char* const translate_language; | 39 const char* const translate_language; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 std::string security_origin(kSecurityOrigin); | 139 std::string security_origin(kSecurityOrigin); |
| 140 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 140 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 141 if (command_line->HasSwitch(switches::kTranslateSecurityOrigin)) { | 141 if (command_line->HasSwitch(switches::kTranslateSecurityOrigin)) { |
| 142 security_origin = | 142 security_origin = |
| 143 command_line->GetSwitchValueASCII(switches::kTranslateSecurityOrigin); | 143 command_line->GetSwitchValueASCII(switches::kTranslateSecurityOrigin); |
| 144 } | 144 } |
| 145 return GURL(security_origin); | 145 return GURL(security_origin); |
| 146 } | 146 } |
| 147 | 147 |
| 148 } // namespace translate | 148 } // namespace translate |
| OLD | NEW |