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

Side by Side Diff: url/url_canon_internal_file.h

Issue 1878083002: Implement IsAsciiUpper and IsAsciiLower in base/strings/string_util.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git sync Created 4 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef URL_URL_CANON_INTERNAL_FILE_H_ 5 #ifndef URL_URL_CANON_INTERNAL_FILE_H_
6 #define URL_URL_CANON_INTERNAL_FILE_H_ 6 #define URL_URL_CANON_INTERNAL_FILE_H_
7 7
8 // As with url_canon_internal.h, this file is intended to be included in 8 // As with url_canon_internal.h, this file is intended to be included in
9 // another C++ file where the template types are defined. This allows the 9 // another C++ file where the template types are defined. This allows the
10 // programmer to use this to use these functions for their own strings 10 // programmer to use this to use these functions for their own strings
11 // types, without bloating the code by having inline templates used in 11 // types, without bloating the code by having inline templates used in
12 // every call site. 12 // every call site.
13 // 13 //
14 // *** This file must be included after url_canon_internal as we depend on some 14 // *** This file must be included after url_canon_internal as we depend on some
15 // functions in it. *** 15 // functions in it. ***
16 16
17 17 #include "base/strings/string_util.h"
18 #include "url/url_file.h" 18 #include "url/url_file.h"
19 #include "url/url_parse_internal.h" 19 #include "url/url_parse_internal.h"
20 20
21 namespace url { 21 namespace url {
22 22
23 // Given a pointer into the spec, this copies and canonicalizes the drive 23 // Given a pointer into the spec, this copies and canonicalizes the drive
24 // letter and colon to the output, if one is found. If there is not a drive 24 // letter and colon to the output, if one is found. If there is not a drive
25 // spec, it won't do anything. The index of the next character in the input 25 // spec, it won't do anything. The index of the next character in the input
26 // spec is returned (after the colon when a drive spec is found, the begin 26 // spec is returned (after the colon when a drive spec is found, the begin
27 // offset if one is not). 27 // offset if one is not).
28 template<typename CHAR> 28 template<typename CHAR>
29 static int FileDoDriveSpec(const CHAR* spec, int begin, int end, 29 static int FileDoDriveSpec(const CHAR* spec, int begin, int end,
30 CanonOutput* output) { 30 CanonOutput* output) {
31 // The path could be one of several things: /foo/bar, c:/foo/bar, /c:/foo, 31 // The path could be one of several things: /foo/bar, c:/foo/bar, /c:/foo,
32 // (with backslashes instead of slashes as well). 32 // (with backslashes instead of slashes as well).
33 int num_slashes = CountConsecutiveSlashes(spec, begin, end); 33 int num_slashes = CountConsecutiveSlashes(spec, begin, end);
34 int after_slashes = begin + num_slashes; 34 int after_slashes = begin + num_slashes;
35 35
36 if (!DoesBeginWindowsDriveSpec(spec, after_slashes, end)) 36 if (!DoesBeginWindowsDriveSpec(spec, after_slashes, end))
37 return begin; // Haven't consumed any characters 37 return begin; // Haven't consumed any characters
38 38
39 // DoesBeginWindowsDriveSpec will ensure that the drive letter is valid 39 // DoesBeginWindowsDriveSpec will ensure that the drive letter is valid
40 // and that it is followed by a colon/pipe. 40 // and that it is followed by a colon/pipe.
41 41
42 // Normalize Windows drive letters to uppercase 42 // Normalize Windows drive letters to uppercase
43 if (spec[after_slashes] >= 'a' && spec[after_slashes] <= 'z') 43 if (base::IsAsciiLower(spec[after_slashes]))
44 output->push_back(spec[after_slashes] - 'a' + 'A'); 44 output->push_back(spec[after_slashes] - 'a' + 'A');
45 else 45 else
46 output->push_back(static_cast<char>(spec[after_slashes])); 46 output->push_back(static_cast<char>(spec[after_slashes]));
47 47
48 // Normalize the character following it to a colon rather than pipe. 48 // Normalize the character following it to a colon rather than pipe.
49 output->push_back(':'); 49 output->push_back(':');
50 output->push_back('/'); 50 output->push_back('/');
51 return after_slashes + 2; 51 return after_slashes + 2;
52 } 52 }
53 53
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 source.query, parsed.query, output, &new_parsed->query); 126 source.query, parsed.query, output, &new_parsed->query);
127 success &= URLCanonInternal<CHAR, UCHAR>::DoRef( 127 success &= URLCanonInternal<CHAR, UCHAR>::DoRef(
128 source.ref, parsed.ref, output, &new_parsed->ref); 128 source.ref, parsed.ref, output, &new_parsed->ref);
129 129
130 return success; 130 return success;
131 } 131 }
132 132
133 } // namespace url 133 } // namespace url
134 134
135 #endif // URL_URL_CANON_INTERNAL_FILE_H_ 135 #endif // URL_URL_CANON_INTERNAL_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698