Skip to content

Commit

Permalink
IOS: Moves the helper function were it is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Bénony committed Jan 6, 2016
1 parent a56c587 commit 16605a3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
15 changes: 14 additions & 1 deletion backends/fs/chroot/chroot-fs.cpp
Expand Up @@ -39,7 +39,7 @@ ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, POSIXFile

ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, const Common::String &path) {
_root = Common::normalizePath(root, '/');
_realNode = new POSIXFilesystemNode(root.stringByAppendingPathComponent(path));
_realNode = new POSIXFilesystemNode(addPathComponent(root, path));
}

ChRootFilesystemNode::~ChRootFilesystemNode() {
Expand Down Expand Up @@ -108,4 +108,17 @@ Common::WriteStream *ChRootFilesystemNode::createWriteStream() {
return _realNode->createWriteStream();
}

Common::String ChRootFilesystemNode::addPathComponent(const Common::String &path, const Common::String &component) {
const char sep = '/';
if (path.lastChar() == sep && component.firstChar() == sep) {
return Common::String::format("%s%s", path.c_str(), component.c_str() + 1);
}

if (path.lastChar() == sep || component.firstChar() == sep) {
return Common::String::format("%s%s", path.c_str(), component.c_str());
}

return Common::String::format("%s%c%s", path.c_str(), sep, component.c_str());
}

#endif
3 changes: 3 additions & 0 deletions backends/fs/chroot/chroot-fs.h
Expand Up @@ -49,6 +49,9 @@ class ChRootFilesystemNode : public AbstractFSNode {

virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();

private:
static Common::String addPathComponent(const Common::String &path, const Common::String &component);
};

#endif /* CHROOT_FS_H */
12 changes: 0 additions & 12 deletions common/str.cpp
Expand Up @@ -665,18 +665,6 @@ String lastPathComponent(const String &path, const char sep) {
return String(first, last);
}

String String::stringByAppendingPathComponent(String component, char sep) const {
if (lastChar() == sep && component.firstChar() == sep) {
return String::format("%s%s", c_str(), component.c_str() + 1);
}

if (lastChar() == sep || component.firstChar() == sep) {
return String::format("%s%s", c_str(), component.c_str());
}

return String::format("%s%c%s", c_str(), sep, component.c_str());
}

String normalizePath(const String &path, const char sep) {
if (path.empty())
return path;
Expand Down
5 changes: 0 additions & 5 deletions common/str.h
Expand Up @@ -218,11 +218,6 @@ class String {
*/
void trim();

/**
* Add a path component
*/
String stringByAppendingPathComponent(String component, char sep = '/') const;

uint hash() const;

/**
Expand Down

0 comments on commit 16605a3

Please sign in to comment.