bsnes-libretro/nall/location.hpp
Tim Allen 559a6585ef Update to v106r81 release.
byuu says:

First 32 instructions implemented in the TLCS900H disassembler. Only 992
to go!

I removed the use of anonymous namespaces in nall. It was something I
rarely used, because it rarely did what I wanted.

I updated all nested namespaces to use C++17-style namespace Foo::Bar {}
syntax instead of classic C++-style namespace Foo { namespace Bar {}}.

I updated ruby::Video::acquire() to return a struct, so we can use C++17
structured bindings. Long term, I want to get away from all functions
that take references for output only. Even though C++ botched structured
bindings by not allowing you to bind to existing variables, it's even
worse to have function calls that take arguments by reference and then
write to them. From the caller side, you can't tell the value is being
written, nor that the value passed in doesn't matter, which is terrible.
2019-01-16 13:02:24 +11:00

79 lines
2.4 KiB
C++

#pragma once
#include <nall/string.hpp>
namespace nall::Location {
// (/parent/child.type/)
// (/parent/child.type/)name.type
inline auto path(string_view self) -> string {
const char* p = self.data() + self.size() - 1;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/') return slice(self, 0, offset + 1);
}
return ""; //no path found
}
// /parent/child.type/()
// /parent/child.type/(name.type)
inline auto file(string_view self) -> string {
const char* p = self.data() + self.size() - 1;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/') return slice(self, offset + 1);
}
return self; //no path found
}
// (/parent/)child.type/
// (/parent/child.type/)name.type
inline auto dir(string_view self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') return slice(self, 0, offset + 1);
}
return ""; //no path found
}
// /parent/(child.type/)
// /parent/child.type/(name.type)
inline auto base(string_view self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') return slice(self, offset + 1);
}
return self; //no path found
}
// /parent/(child).type/
// /parent/child.type/(name).type
inline auto prefix(string_view self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(int offset = self.size() - 1, suffix = -1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') return slice(self, offset + 1, suffix >= 0 ? suffix - offset - 1 : 0).trimRight("/");
if(*p == '.' && suffix == -1) { suffix = offset; continue; }
if(offset == 0) return slice(self, offset, suffix).trimRight("/");
}
return ""; //no prefix found
}
// /parent/child(.type)/
// /parent/child.type/name(.type)
inline auto suffix(string_view self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(int offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') break;
if(*p == '.') return slice(self, offset).trimRight("/");
}
return ""; //no suffix found
}
inline auto notsuffix(string_view self) -> string {
return {path(self), prefix(self)};
}
}