| 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 #include "nacl_mounts/path.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 return Range(paths, 0, paths.size()); | 139 return Range(paths, 0, paths.size()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 // static | 142 // static |
| 143 std::string Path::Range(const StringArray_t& paths, size_t start, size_t end) { | 143 std::string Path::Range(const StringArray_t& paths, size_t start, size_t end) { |
| 144 std::string out_path; | 144 std::string out_path; |
| 145 size_t index = start; | 145 size_t index = start; |
| 146 | 146 |
| 147 if (end > paths.size()) end = paths.size(); | 147 if (end > paths.size()) end = paths.size(); |
| 148 | 148 |
| 149 // If this is an absolute path, paths[0] == "/". In this case, we don't want |
| 150 // to add an additional / separator. |
| 149 if (start == 0 && end > 0 && paths[0] == "/") { | 151 if (start == 0 && end > 0 && paths[0] == "/") { |
| 150 if (end == 1) return std::string("/"); | 152 out_path += "/"; |
| 151 index++; | 153 index++; |
| 152 } | 154 } |
| 153 | 155 |
| 154 for (; index < end; index++) { | 156 for (; index < end; index++) { |
| 155 if (index) out_path += "/"; | |
| 156 out_path += paths[index]; | 157 out_path += paths[index]; |
| 158 if (index < end - 1) |
| 159 out_path += "/"; |
| 157 } | 160 } |
| 158 | 161 |
| 159 return out_path; | 162 return out_path; |
| 160 } | 163 } |
| 161 | 164 |
| 162 // static | 165 // static |
| 163 StringArray_t Path::Split(const std::string& path) { | 166 StringArray_t Path::Split(const std::string& path) { |
| 164 StringArray_t components; | 167 StringArray_t components; |
| 165 size_t offs = 0; | 168 size_t offs = 0; |
| 166 size_t next = 0; | 169 size_t next = 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 187 } | 190 } |
| 188 | 191 |
| 189 Path& Path::operator =(const Path& p) { | 192 Path& Path::operator =(const Path& p) { |
| 190 paths_ = p.paths_; | 193 paths_ = p.paths_; |
| 191 return *this; | 194 return *this; |
| 192 } | 195 } |
| 193 | 196 |
| 194 Path& Path::operator =(const std::string& p) { | 197 Path& Path::operator =(const std::string& p) { |
| 195 return Set(p); | 198 return Set(p); |
| 196 } | 199 } |
| OLD | NEW |