Merge pull request #2338 from lioncash/fs
filesystem: Use a std::string_view in OpenFile()
This commit is contained in:
commit
d6b7195192
|
@ -197,13 +197,16 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa
|
||||||
|
|
||||||
ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
|
ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
|
||||||
FileSys::Mode mode) const {
|
FileSys::Mode mode) const {
|
||||||
std::string path(FileUtil::SanitizePath(path_));
|
const std::string path(FileUtil::SanitizePath(path_));
|
||||||
auto npath = path;
|
std::string_view npath = path;
|
||||||
while (npath.size() > 0 && (npath[0] == '/' || npath[0] == '\\'))
|
while (!npath.empty() && (npath[0] == '/' || npath[0] == '\\')) {
|
||||||
npath = npath.substr(1);
|
npath.remove_prefix(1);
|
||||||
|
}
|
||||||
|
|
||||||
auto file = backing->GetFileRelative(npath);
|
auto file = backing->GetFileRelative(npath);
|
||||||
if (file == nullptr)
|
if (file == nullptr) {
|
||||||
return FileSys::ERROR_PATH_NOT_FOUND;
|
return FileSys::ERROR_PATH_NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == FileSys::Mode::Append) {
|
if (mode == FileSys::Mode::Append) {
|
||||||
return MakeResult<FileSys::VirtualFile>(
|
return MakeResult<FileSys::VirtualFile>(
|
||||||
|
|
Reference in New Issue