Chromium Code Reviews| 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_io/path.h" | 5 #include "nacl_io/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 26 matching lines...) Expand all Loading... | |
| 37 size_t Path::Size() const { | 37 size_t Path::Size() const { |
| 38 return paths_.size(); | 38 return paths_.size(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool Path::Top() const { | 41 bool Path::Top() const { |
| 42 return (paths_.size() == 0) || (paths_.size() == 1 && paths_[0] == "/"); | 42 return (paths_.size() == 0) || (paths_.size() == 1 && paths_[0] == "/"); |
| 43 } | 43 } |
| 44 | 44 |
| 45 Path& Path::Append(const std::string& path) { | 45 Path& Path::Append(const std::string& path) { |
| 46 StringArray_t paths = Split(path); | 46 StringArray_t paths = Split(path); |
| 47 if (paths.size() == 0) | |
|
binji
2014/06/09 20:54:29
I prefer paths.empty() for this, but it looks like
Sam Clegg
2014/06/10 17:20:59
Done.
| |
| 48 return *this; | |
| 47 | 49 |
| 48 for (size_t index = 0; index < paths.size(); index++) { | 50 for (size_t index = 0; index < paths.size(); index++) { |
| 49 // Skip ROOT | 51 // Skip ROOT |
| 50 if (paths_.size() && index == 0 && paths[0] == "/") | 52 if (paths_.size() && index == 0 && paths[0] == "/") |
| 51 continue; | 53 continue; |
| 52 paths_.push_back(paths[index]); | 54 paths_.push_back(paths[index]); |
| 53 } | 55 } |
| 54 | 56 |
| 55 paths_ = Normalize(paths_); | 57 paths_ = Normalize(paths_); |
| 56 return *this; | 58 return *this; |
| 57 } | 59 } |
| 58 | 60 |
| 59 Path& Path::Prepend(const std::string& path) { | 61 Path& Path::Prepend(const std::string& path) { |
| 60 StringArray_t paths = Split(path); | 62 StringArray_t paths = Split(path); |
| 63 if (paths.size() == 0) | |
| 64 return *this; | |
| 61 | 65 |
| 62 for (size_t index = 0; index < paths_.size(); index++) { | 66 for (size_t index = 0; index < paths_.size(); index++) { |
| 63 // Skip ROOT | 67 // Skip ROOT |
| 64 if (index == 0 && paths_[0] == "/") | 68 if (index == 0 && paths_[0] == "/") |
| 65 continue; | 69 continue; |
| 66 paths.push_back(paths[index]); | 70 paths.push_back(paths_[index]); |
|
binji
2014/06/09 20:54:29
why? If needed, be consistent with same in Path::A
Sam Clegg
2014/06/10 17:20:59
This is simply a bug.
Append is pushing all the p
binji
2014/06/10 18:00:58
I see.
| |
| 67 } | 71 } |
| 72 | |
| 68 paths_ = Normalize(paths); | 73 paths_ = Normalize(paths); |
| 69 return *this; | 74 return *this; |
| 70 } | 75 } |
| 71 | 76 |
| 72 Path& Path::Set(const std::string& path) { | 77 Path& Path::Set(const std::string& path) { |
| 73 StringArray_t paths = Split(path); | 78 StringArray_t paths = Split(path); |
| 74 paths_ = Normalize(paths); | 79 paths_ = Normalize(paths); |
| 75 return *this; | 80 return *this; |
| 76 } | 81 } |
| 77 | 82 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 Path& Path::operator=(const Path& p) { | 208 Path& Path::operator=(const Path& p) { |
| 204 paths_ = p.paths_; | 209 paths_ = p.paths_; |
| 205 return *this; | 210 return *this; |
| 206 } | 211 } |
| 207 | 212 |
| 208 Path& Path::operator=(const std::string& p) { | 213 Path& Path::operator=(const std::string& p) { |
| 209 return Set(p); | 214 return Set(p); |
| 210 } | 215 } |
| 211 | 216 |
| 212 } // namespace nacl_io | 217 } // namespace nacl_io |
| OLD | NEW |