2020-09-28 23:49:14 +02:00
|
|
|
#include "files.h"
|
|
|
|
|
|
|
|
void mrbesen::Files::parent(const std::string& child, std::string& out) {
|
|
|
|
//letzten path trenner finden
|
|
|
|
size_t pos = child.rfind('/', child.length() -2); //das erste Zeichen überspringen (könnte ein / sein)
|
|
|
|
if(pos == std::string::npos)
|
|
|
|
pos = child.rfind('\\');
|
|
|
|
if(pos != std::string::npos)
|
|
|
|
out = child.substr(0, pos+1);
|
|
|
|
else
|
|
|
|
out = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void mrbesen::Files::file(const std::string& path, std::string& out) {
|
|
|
|
//letzten path trenner finden
|
|
|
|
size_t pos = path.rfind('/', path.length() -2); //das erste Zeichen überspringen (könnte ein / sein)
|
|
|
|
if(pos == std::string::npos)
|
|
|
|
pos = path.rfind('\\');
|
|
|
|
if(pos != std::string::npos)
|
|
|
|
out = path.substr(pos+1);
|
|
|
|
else
|
|
|
|
out = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mrbesen::Files::extention(const std::string& path, std::string& ext) {
|
2020-09-29 14:04:19 +02:00
|
|
|
std::string filestr;
|
|
|
|
file(path, filestr);
|
|
|
|
size_t pos = filestr.rfind('.');
|
|
|
|
|
|
|
|
if(pos == std::string::npos || pos+1 == filestr.size()) {
|
2020-09-28 23:49:14 +02:00
|
|
|
ext = "";
|
|
|
|
return;
|
|
|
|
}
|
2020-09-29 14:04:19 +02:00
|
|
|
|
|
|
|
ext = filestr.substr(pos+1);
|
2020-09-28 23:49:14 +02:00
|
|
|
|
|
|
|
//TODO:
|
|
|
|
//was ist mit dotfiles?? -> prüfen auf '/' for '.'? oder auf string position (damit der punkt icht ganz links sei kann)?
|
|
|
|
|
|
|
|
//problem: "a.b/file" würde .b/file zurückgeben -> muss also auch auf '/' geprüft werden!
|
|
|
|
}
|
|
|
|
|