| 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/search_engines/template_url_parser.h" | 5 #include "components/search_engines/template_url_parser.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 return std::string(reinterpret_cast<const char*>(value)); | 56 return std::string(reinterpret_cast<const char*>(value)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Returns true if input_encoding contains a valid input encoding string. This | 59 // Returns true if input_encoding contains a valid input encoding string. This |
| 60 // doesn't verify that we have a valid encoding for the string, just that the | 60 // doesn't verify that we have a valid encoding for the string, just that the |
| 61 // string contains characters that constitute a valid input encoding. | 61 // string contains characters that constitute a valid input encoding. |
| 62 bool IsValidEncodingString(const std::string& input_encoding) { | 62 bool IsValidEncodingString(const std::string& input_encoding) { |
| 63 if (input_encoding.empty()) | 63 if (input_encoding.empty()) |
| 64 return false; | 64 return false; |
| 65 | 65 |
| 66 if (!IsAsciiAlpha(input_encoding[0])) | 66 if (!base::IsAsciiAlpha(input_encoding[0])) |
| 67 return false; | 67 return false; |
| 68 | 68 |
| 69 for (size_t i = 1, max = input_encoding.size(); i < max; ++i) { | 69 for (size_t i = 1, max = input_encoding.size(); i < max; ++i) { |
| 70 char c = input_encoding[i]; | 70 char c = input_encoding[i]; |
| 71 if (!IsAsciiAlpha(c) && !IsAsciiDigit(c) && c != '.' && c != '_' && | 71 if (!base::IsAsciiAlpha(c) && !base::IsAsciiDigit(c) && |
| 72 c != '-') { | 72 c != '.' && c != '_' && c != '-') { |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 return true; | 76 return true; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void AppendParamToQuery(const std::string& key, | 79 void AppendParamToQuery(const std::string& key, |
| 80 const std::string& value, | 80 const std::string& value, |
| 81 std::string* query) { | 81 std::string* query) { |
| 82 if (!query->empty()) | 82 if (!query->empty()) |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; | 503 sax_handler.startElement = &TemplateURLParsingContext::StartElementImpl; |
| 504 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; | 504 sax_handler.endElement = &TemplateURLParsingContext::EndElementImpl; |
| 505 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; | 505 sax_handler.characters = &TemplateURLParsingContext::CharactersImpl; |
| 506 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, | 506 int error = xmlSAXUserParseMemory(&sax_handler, &context, data, |
| 507 static_cast<int>(length)); | 507 static_cast<int>(length)); |
| 508 xmlSubstituteEntitiesDefault(last_sub_entities_value); | 508 xmlSubstituteEntitiesDefault(last_sub_entities_value); |
| 509 | 509 |
| 510 return error ? | 510 return error ? |
| 511 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); | 511 NULL : context.GetTemplateURL(search_terms_data, show_in_default_list); |
| 512 } | 512 } |
| OLD | NEW |