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

Side by Side Diff: Source/modules/filesystem/DOMFilePath.cpp

Issue 124943003: Remove 'String::append' from some of the blink source. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Incorporated review comments Created 6 years, 11 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "modules/filesystem/DOMFilePath.h" 32 #include "modules/filesystem/DOMFilePath.h"
33 33
34 #include "wtf/Vector.h" 34 #include "wtf/Vector.h"
35 #include "wtf/text/CString.h" 35 #include "wtf/text/CString.h"
36 #include "wtf/text/StringBuilder.h"
36 37
37 namespace WebCore { 38 namespace WebCore {
38 39
39 const char DOMFilePath::separator = '/'; 40 const char DOMFilePath::separator = '/';
40 const char DOMFilePath::root[] = "/"; 41 const char DOMFilePath::root[] = "/";
41 42
42 String DOMFilePath::append(const String& base, const String& components) 43 String DOMFilePath::append(const String& base, const String& components)
43 { 44 {
44 return ensureDirectoryPath(base) + components; 45 return ensureDirectoryPath(base) + components;
45 } 46 }
46 47
47 String DOMFilePath::ensureDirectoryPath(const String& path) 48 String DOMFilePath::ensureDirectoryPath(const String& path)
48 { 49 {
49 if (!DOMFilePath::endsWithSeparator(path)) { 50 if (!DOMFilePath::endsWithSeparator(path)) {
50 String newPath = path; 51 String newPath = path + DOMFilePath::separator;
51 newPath.append(DOMFilePath::separator);
52 return newPath; 52 return newPath;
abarth-chromium 2014/01/09 15:48:24 I'd just merge these two lines.
53 } 53 }
54 return path; 54 return path;
55 } 55 }
56 56
57 String DOMFilePath::getName(const String& path) 57 String DOMFilePath::getName(const String& path)
58 { 58 {
59 int index = path.reverseFind(DOMFilePath::separator); 59 int index = path.reverseFind(DOMFilePath::separator);
60 if (index != -1) 60 if (index != -1)
61 return path.substring(index + 1); 61 return path.substring(index + 1);
62 return path; 62 return path;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 continue; 96 continue;
97 if (components[i] == "..") { 97 if (components[i] == "..") {
98 if (canonicalized.size() > 0) 98 if (canonicalized.size() > 0)
99 canonicalized.removeLast(); 99 canonicalized.removeLast();
100 continue; 100 continue;
101 } 101 }
102 canonicalized.append(components[i]); 102 canonicalized.append(components[i]);
103 } 103 }
104 if (canonicalized.isEmpty()) 104 if (canonicalized.isEmpty())
105 return DOMFilePath::root; 105 return DOMFilePath::root;
106 String result; 106 StringBuilder result;
107 for (size_t i = 0; i < canonicalized.size(); ++i) { 107 for (size_t i = 0; i < canonicalized.size(); ++i) {
108 result.append(DOMFilePath::separator); 108 result.append(DOMFilePath::separator);
109 result.append(canonicalized[i]); 109 result.append(canonicalized[i]);
110 } 110 }
111 return result; 111 return result.toString();
112 } 112 }
113 113
114 bool DOMFilePath::isValidPath(const String& path) 114 bool DOMFilePath::isValidPath(const String& path)
115 { 115 {
116 if (path.isEmpty() || path == DOMFilePath::root) 116 if (path.isEmpty() || path == DOMFilePath::root)
117 return true; 117 return true;
118 118
119 // Embedded NULs are not allowed. 119 // Embedded NULs are not allowed.
120 if (path.find(static_cast<UChar>(0)) != WTF::kNotFound) 120 if (path.find(static_cast<UChar>(0)) != WTF::kNotFound)
121 return false; 121 return false;
(...skipping 18 matching lines...) Expand all
140 { 140 {
141 if (name.isEmpty()) 141 if (name.isEmpty())
142 return true; 142 return true;
143 // '/' is not allowed in name. 143 // '/' is not allowed in name.
144 if (name.contains('/')) 144 if (name.contains('/'))
145 return false; 145 return false;
146 return isValidPath(name); 146 return isValidPath(name);
147 } 147 }
148 148
149 } // namespace WebCore 149 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698