Changeset View
Changeset View
Standalone View
Standalone View
source/lib/path.h
Show All 33 Lines | |||||
// native and VFS paths. | // native and VFS paths. | ||||
// when reading, both '/' and SYS_DIR_SEP are accepted; '/' is written. | // when reading, both '/' and SYS_DIR_SEP are accepted; '/' is written. | ||||
#ifndef INCLUDED_PATH | #ifndef INCLUDED_PATH | ||||
#define INCLUDED_PATH | #define INCLUDED_PATH | ||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include <algorithm> | |||||
#include <cstring> | #include <cstring> | ||||
#include <functional> | #include <functional> | ||||
namespace ERR | namespace ERR | ||||
{ | { | ||||
const Status PATH_CHARACTER_ILLEGAL = -100300; | const Status PATH_CHARACTER_ILLEGAL = -100300; | ||||
const Status PATH_CHARACTER_UNSAFE = -100301; | const Status PATH_CHARACTER_UNSAFE = -100301; | ||||
const Status PATH_NOT_FOUND = -100302; | const Status PATH_NOT_FOUND = -100302; | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | #endif | ||||
Path BeforeCommon(Path other) const | Path BeforeCommon(Path other) const | ||||
{ | { | ||||
Path ret = *this; | Path ret = *this; | ||||
if(ret.empty() || other.empty()) | if(ret.empty() || other.empty()) | ||||
return L""; | return L""; | ||||
// Convert the separator to allow for string comparison | // Convert the separator to allow for string comparison | ||||
if(other.separator != ret.separator) | if(other.separator != ret.separator) | ||||
replace(other.path.begin(), other.path.end(), other.separator, ret.separator); | std::replace(other.path.begin(), other.path.end(), other.separator, ret.separator); | ||||
const size_t idx = ret.path.rfind(other.path); | const size_t idx = ret.path.rfind(other.path); | ||||
if(idx == String::npos) | if(idx == String::npos) | ||||
return L""; | return L""; | ||||
return path.substr(0, idx); | return path.substr(0, idx); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator