Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <iterator> | 6 #include <iterator> |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 { "application/x-mpegurl", "m3u8" }, | 108 { "application/x-mpegurl", "m3u8" }, |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 const char* FindMimeType(const MimeInfo* mappings, | 111 const char* FindMimeType(const MimeInfo* mappings, |
| 112 size_t mappings_len, | 112 size_t mappings_len, |
| 113 const std::string& ext) { | 113 const std::string& ext) { |
| 114 for (size_t i = 0; i < mappings_len; ++i) { | 114 for (size_t i = 0; i < mappings_len; ++i) { |
| 115 const char* extensions = mappings[i].extensions; | 115 const char* extensions = mappings[i].extensions; |
| 116 for (;;) { | 116 for (;;) { |
| 117 size_t end_pos = strcspn(extensions, ","); | 117 size_t end_pos = strcspn(extensions, ","); |
| 118 if (end_pos == ext.size() && | 118 if (end_pos == ext.size() && |
|
Nico
2015/07/08 21:58:23
I was about to say that EqualsCase...() already do
brettw
2015/07/08 22:35:17
Yeah, I added a comment for clarity.
| |
| 119 base::strncasecmp(extensions, ext.data(), ext.size()) == 0) | 119 base::EqualsCaseInsensitiveASCII( |
| 120 base::StringPiece(extensions, ext.size()), ext)) | |
| 120 return mappings[i].mime_type; | 121 return mappings[i].mime_type; |
| 121 extensions += end_pos; | 122 extensions += end_pos; |
| 122 if (!*extensions) | 123 if (!*extensions) |
| 123 break; | 124 break; |
| 124 extensions += 1; // skip over comma | 125 extensions += 1; // skip over comma |
| 125 } | 126 } |
| 126 } | 127 } |
| 127 return NULL; | 128 return NULL; |
| 128 } | 129 } |
| 129 | 130 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 std::string::size_type semicolon = mime_type_pattern.find(';'); | 261 std::string::size_type semicolon = mime_type_pattern.find(';'); |
| 261 const std::string base_pattern(mime_type_pattern.substr(0, semicolon)); | 262 const std::string base_pattern(mime_type_pattern.substr(0, semicolon)); |
| 262 semicolon = mime_type.find(';'); | 263 semicolon = mime_type.find(';'); |
| 263 const std::string base_type(mime_type.substr(0, semicolon)); | 264 const std::string base_type(mime_type.substr(0, semicolon)); |
| 264 | 265 |
| 265 if (base_pattern == "*" || base_pattern == "*/*") | 266 if (base_pattern == "*" || base_pattern == "*/*") |
| 266 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 267 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); |
| 267 | 268 |
| 268 const std::string::size_type star = base_pattern.find('*'); | 269 const std::string::size_type star = base_pattern.find('*'); |
| 269 if (star == std::string::npos) { | 270 if (star == std::string::npos) { |
| 270 if (base_pattern.size() == base_type.size() && | 271 if (base::EqualsCaseInsensitiveASCII(base_pattern, base_type)) |
| 271 base::strncasecmp(base_pattern.data(), base_type.data(), | |
| 272 base_pattern.size()) == 0) { | |
| 273 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 272 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); |
| 274 } else { | 273 else |
| 275 return false; | 274 return false; |
| 276 } | |
| 277 } | 275 } |
| 278 | 276 |
| 279 // Test length to prevent overlap between |left| and |right|. | 277 // Test length to prevent overlap between |left| and |right|. |
| 280 if (base_type.length() < base_pattern.length() - 1) | 278 if (base_type.length() < base_pattern.length() - 1) |
| 281 return false; | 279 return false; |
| 282 | 280 |
| 283 base::StringPiece base_pattern_piece(base_pattern); | 281 base::StringPiece base_pattern_piece(base_pattern); |
| 284 base::StringPiece left(base_pattern_piece.substr(0, star)); | 282 base::StringPiece left(base_pattern_piece.substr(0, star)); |
| 285 base::StringPiece right(base_pattern_piece.substr(star + 1)); | 283 base::StringPiece right(base_pattern_piece.substr(star + 1)); |
| 286 | 284 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 post_data->append("\r\n" + value + "\r\n"); | 576 post_data->append("\r\n" + value + "\r\n"); |
| 579 } | 577 } |
| 580 | 578 |
| 581 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 579 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
| 582 std::string* post_data) { | 580 std::string* post_data) { |
| 583 DCHECK(post_data); | 581 DCHECK(post_data); |
| 584 post_data->append("--" + mime_boundary + "--\r\n"); | 582 post_data->append("--" + mime_boundary + "--\r\n"); |
| 585 } | 583 } |
| 586 | 584 |
| 587 } // namespace net | 585 } // namespace net |
| OLD | NEW |