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

Side by Side Diff: net/base/mime_util.cc

Issue 1224553010: Replace base::str[n]casecmp with helper functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 years, 5 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
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 <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
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 // The length check is required to prevent the StringPiece below from
119 // including uninitialized memory if ext is longer than extensions.
118 if (end_pos == ext.size() && 120 if (end_pos == ext.size() &&
119 base::strncasecmp(extensions, ext.data(), ext.size()) == 0) 121 base::EqualsCaseInsensitiveASCII(
122 base::StringPiece(extensions, ext.size()), ext))
120 return mappings[i].mime_type; 123 return mappings[i].mime_type;
121 extensions += end_pos; 124 extensions += end_pos;
122 if (!*extensions) 125 if (!*extensions)
123 break; 126 break;
124 extensions += 1; // skip over comma 127 extensions += 1; // skip over comma
125 } 128 }
126 } 129 }
127 return NULL; 130 return NULL;
128 } 131 }
129 132
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 std::string::size_type semicolon = mime_type_pattern.find(';'); 263 std::string::size_type semicolon = mime_type_pattern.find(';');
261 const std::string base_pattern(mime_type_pattern.substr(0, semicolon)); 264 const std::string base_pattern(mime_type_pattern.substr(0, semicolon));
262 semicolon = mime_type.find(';'); 265 semicolon = mime_type.find(';');
263 const std::string base_type(mime_type.substr(0, semicolon)); 266 const std::string base_type(mime_type.substr(0, semicolon));
264 267
265 if (base_pattern == "*" || base_pattern == "*/*") 268 if (base_pattern == "*" || base_pattern == "*/*")
266 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); 269 return MatchesMimeTypeParameters(mime_type_pattern, mime_type);
267 270
268 const std::string::size_type star = base_pattern.find('*'); 271 const std::string::size_type star = base_pattern.find('*');
269 if (star == std::string::npos) { 272 if (star == std::string::npos) {
270 if (base_pattern.size() == base_type.size() && 273 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); 274 return MatchesMimeTypeParameters(mime_type_pattern, mime_type);
274 } else { 275 else
275 return false; 276 return false;
276 }
277 } 277 }
278 278
279 // Test length to prevent overlap between |left| and |right|. 279 // Test length to prevent overlap between |left| and |right|.
280 if (base_type.length() < base_pattern.length() - 1) 280 if (base_type.length() < base_pattern.length() - 1)
281 return false; 281 return false;
282 282
283 base::StringPiece base_pattern_piece(base_pattern); 283 base::StringPiece base_pattern_piece(base_pattern);
284 base::StringPiece left(base_pattern_piece.substr(0, star)); 284 base::StringPiece left(base_pattern_piece.substr(0, star));
285 base::StringPiece right(base_pattern_piece.substr(star + 1)); 285 base::StringPiece right(base_pattern_piece.substr(star + 1));
286 286
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 post_data->append("\r\n" + value + "\r\n"); 578 post_data->append("\r\n" + value + "\r\n");
579 } 579 }
580 580
581 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 581 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
582 std::string* post_data) { 582 std::string* post_data) {
583 DCHECK(post_data); 583 DCHECK(post_data);
584 post_data->append("--" + mime_boundary + "--\r\n"); 584 post_data->append("--" + mime_boundary + "--\r\n");
585 } 585 }
586 586
587 } // namespace net 587 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698