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

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

Issue 1172183002: Move StartsWith[ASCII] to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string_util3
Patch Set: merger 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 | « mojo/runner/shell_apptest.cc ('k') | net/base/net_util.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 <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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 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 const std::string left(base_pattern.substr(0, star)); 283 const std::string left(base_pattern.substr(0, star));
284 const std::string right(base_pattern.substr(star + 1)); 284 const std::string right(base_pattern.substr(star + 1));
285 285
286 if (!StartsWithASCII(base_type, left, false)) 286 if (!base::StartsWithASCII(base_type, left, false))
287 return false; 287 return false;
288 288
289 if (!right.empty() && !EndsWith(base_type, right, false)) 289 if (!right.empty() && !EndsWith(base_type, right, false))
290 return false; 290 return false;
291 291
292 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); 292 return MatchesMimeTypeParameters(mime_type_pattern, mime_type);
293 } 293 }
294 294
295 // See http://www.iana.org/assignments/media-types/media-types.xhtml 295 // See http://www.iana.org/assignments/media-types/media-types.xhtml
296 static const char* const legal_top_level_types[] = { 296 static const char* const legal_top_level_types[] = {
(...skipping 26 matching lines...) Expand all
323 return true; 323 return true;
324 } 324 }
325 325
326 bool MimeUtil::IsValidTopLevelMimeType(const std::string& type_string) const { 326 bool MimeUtil::IsValidTopLevelMimeType(const std::string& type_string) const {
327 std::string lower_type = base::StringToLowerASCII(type_string); 327 std::string lower_type = base::StringToLowerASCII(type_string);
328 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { 328 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) {
329 if (lower_type.compare(legal_top_level_types[i]) == 0) 329 if (lower_type.compare(legal_top_level_types[i]) == 0)
330 return true; 330 return true;
331 } 331 }
332 332
333 return type_string.size() > 2 && StartsWithASCII(type_string, "x-", false); 333 return type_string.size() > 2 &&
334 base::StartsWithASCII(type_string, "x-", false);
334 } 335 }
335 336
336 //---------------------------------------------------------------------------- 337 //----------------------------------------------------------------------------
337 // Wrappers for the singleton 338 // Wrappers for the singleton
338 //---------------------------------------------------------------------------- 339 //----------------------------------------------------------------------------
339 340
340 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, 341 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
341 std::string* mime_type) { 342 std::string* mime_type) {
342 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); 343 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type);
343 } 344 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 { "video/", kStandardVideoTypes, arraysize(kStandardVideoTypes) }, 451 { "video/", kStandardVideoTypes, arraysize(kStandardVideoTypes) },
451 { NULL, NULL, 0 } 452 { NULL, NULL, 0 }
452 }; 453 };
453 454
454 void GetExtensionsFromHardCodedMappings( 455 void GetExtensionsFromHardCodedMappings(
455 const MimeInfo* mappings, 456 const MimeInfo* mappings,
456 size_t mappings_len, 457 size_t mappings_len,
457 const std::string& leading_mime_type, 458 const std::string& leading_mime_type,
458 base::hash_set<base::FilePath::StringType>* extensions) { 459 base::hash_set<base::FilePath::StringType>* extensions) {
459 for (size_t i = 0; i < mappings_len; ++i) { 460 for (size_t i = 0; i < mappings_len; ++i) {
460 if (StartsWithASCII(mappings[i].mime_type, leading_mime_type, false)) { 461 if (base::StartsWithASCII(mappings[i].mime_type, leading_mime_type,
462 false)) {
461 std::vector<string> this_extensions; 463 std::vector<string> this_extensions;
462 base::SplitString(mappings[i].extensions, ',', &this_extensions); 464 base::SplitString(mappings[i].extensions, ',', &this_extensions);
463 for (size_t j = 0; j < this_extensions.size(); ++j) { 465 for (size_t j = 0; j < this_extensions.size(); ++j) {
464 #if defined(OS_WIN) 466 #if defined(OS_WIN)
465 base::FilePath::StringType extension( 467 base::FilePath::StringType extension(
466 base::UTF8ToWide(this_extensions[j])); 468 base::UTF8ToWide(this_extensions[j]));
467 #else 469 #else
468 base::FilePath::StringType extension(this_extensions[j]); 470 base::FilePath::StringType extension(this_extensions[j]);
469 #endif 471 #endif
470 extensions->insert(extension); 472 extensions->insert(extension);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 post_data->append("\r\n" + value + "\r\n"); 577 post_data->append("\r\n" + value + "\r\n");
576 } 578 }
577 579
578 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 580 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
579 std::string* post_data) { 581 std::string* post_data) {
580 DCHECK(post_data); 582 DCHECK(post_data);
581 post_data->append("--" + mime_boundary + "--\r\n"); 583 post_data->append("--" + mime_boundary + "--\r\n");
582 } 584 }
583 585
584 } // namespace net 586 } // namespace net
OLDNEW
« no previous file with comments | « mojo/runner/shell_apptest.cc ('k') | net/base/net_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698