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 "nacl_mounts/path.h" |
5 | 6 |
6 #include <stdio.h> | 7 #include <stdio.h> |
7 #include <string.h> | 8 #include <string.h> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "nacl_mounts/path.h" | |
11 | |
12 Path::Path() {} | 11 Path::Path() {} |
13 | 12 |
14 Path::Path(const Path& path) { | 13 Path::Path(const Path& path) { |
15 paths_ = path.paths_; | 14 paths_ = path.paths_; |
16 } | 15 } |
17 | 16 |
18 Path::Path(const std::string& path) { | 17 Path::Path(const std::string& path) { |
19 Set(path); | 18 Set(path); |
20 } | 19 } |
21 | 20 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 return Range(paths_, start, end); | 83 return Range(paths_, start, end); |
85 } | 84 } |
86 | 85 |
87 StringArray_t Path::Split() const { | 86 StringArray_t Path::Split() const { |
88 return paths_; | 87 return paths_; |
89 } | 88 } |
90 | 89 |
91 // static | 90 // static |
92 StringArray_t Path::Normalize(const StringArray_t& paths) { | 91 StringArray_t Path::Normalize(const StringArray_t& paths) { |
93 StringArray_t path_out; | 92 StringArray_t path_out; |
94 int back = 0; | |
95 | 93 |
96 for (size_t index = 0; index < paths.size(); index++) { | 94 for (size_t index = 0; index < paths.size(); index++) { |
97 const std::string &curr = paths[index]; | 95 const std::string &curr = paths[index]; |
98 | 96 |
99 // Check if '/' was used excessively in the path. | 97 // Check if '/' was used excessively in the path. |
100 // For example, in cd Desktop///// | 98 // For example, in cd Desktop///// |
101 if (curr == "/" && index != 0) continue; | 99 if (curr == "/" && index != 0) continue; |
102 | 100 |
103 // Check for '.' in the path and remove it | 101 // Check for '.' in the path and remove it |
104 if (curr == ".") continue; | 102 if (curr == ".") continue; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 157 } |
160 | 158 |
161 return out_path; | 159 return out_path; |
162 } | 160 } |
163 | 161 |
164 // static | 162 // static |
165 StringArray_t Path::Split(const std::string& path) { | 163 StringArray_t Path::Split(const std::string& path) { |
166 StringArray_t components; | 164 StringArray_t components; |
167 size_t offs = 0; | 165 size_t offs = 0; |
168 size_t next = 0; | 166 size_t next = 0; |
169 ssize_t cnt = 0; | |
170 | 167 |
171 if (path[0] == '/') { | 168 if (path[0] == '/') { |
172 offs = 1; | 169 offs = 1; |
173 components.push_back("/"); | 170 components.push_back("/"); |
174 } | 171 } |
175 | 172 |
176 while (next != std::string::npos) { | 173 while (next != std::string::npos) { |
177 next = path.find('/', offs); | 174 next = path.find('/', offs); |
178 | 175 |
179 // Remove extra seperators | 176 // Remove extra seperators |
180 if (next == offs) { | 177 if (next == offs) { |
181 ++offs; | 178 ++offs; |
182 continue; | 179 continue; |
183 } | 180 } |
184 | 181 |
185 std::string part = path.substr(offs, next - offs); | 182 std::string part = path.substr(offs, next - offs); |
186 if (!part.empty()) components.push_back(part); | 183 if (!part.empty()) components.push_back(part); |
187 offs = next + 1; | 184 offs = next + 1; |
188 } | 185 } |
189 return components; | 186 return components; |
190 } | 187 } |
191 | 188 |
192 Path& Path::operator =(const Path& p) { | 189 Path& Path::operator =(const Path& p) { |
193 paths_ = p.paths_; | 190 paths_ = p.paths_; |
194 return *this; | 191 return *this; |
195 } | 192 } |
196 | 193 |
197 Path& Path::operator =(const std::string& p) { | 194 Path& Path::operator =(const std::string& p) { |
198 return Set(p); | 195 return Set(p); |
199 } | 196 } |
OLD | NEW |