bsnes-libretro/nall/string/path.hpp
Tim Allen 0b923489dd Update to 20160106 OS X Preview for Developers release.
byuu says:

New update. Most of the work today went into eliminating hiro::Image
from all objects in all ports, replacing with nall::image. That took an
eternity.

Changelog:
- fixed crashing bug when loading games [thanks endrift!!]
- toggling "show status bar" option adjusts window geometry (not
  supposed to recenter the window, though)
- button sizes improved; icon-only button icons no longer being cut off
2016-01-07 19:17:15 +11:00

73 lines
2.2 KiB
C++

#pragma once
namespace nall {
// (/parent/child.type/)
// (/parent/child.type/)name.type
auto pathname(rstring self) -> string {
const char* p = self.data() + self.size() - 1;
for(signed offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/') return slice(self, 0, offset + 1);
}
return "";
}
// /parent/child.type/()
// /parent/child.type/(name.type)
auto filename(rstring self) -> string {
const char* p = self.data() + self.size() - 1;
for(signed offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/') return slice(self, offset + 1);
}
return "";
}
// (/parent/)child.type/
// (/parent/child.type/)name.type
auto dirname(rstring self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(signed offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') return slice(self, 0, offset + 1);
}
return self.data(); //this is the root directory
}
// /parent/(child.type/)
// /parent/child.type/(name.type)
auto basename(rstring self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(signed offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') return slice(self, offset + 1);
}
return "";
}
// /parent/(child).type/
// /parent/child.type/(name).type
auto prefixname(rstring self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(signed 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).rtrim("/");
if(*p == '.' && suffix == -1) { suffix = offset; continue; }
if(offset == 0) return slice(self, offset, suffix).rtrim("/");
}
return "";
}
// /parent/child(.type)/
// /parent/child.type/name(.type)
auto suffixname(rstring self) -> string {
const char* p = self.data() + self.size() - 1, *last = p;
for(signed offset = self.size() - 1; offset >= 0; offset--, p--) {
if(*p == '/' && p == last) continue;
if(*p == '/') break;
if(*p == '.') return slice(self, offset).rtrim("/");
}
return "";
}
}