libmrbesen/src/Files.cpp

43 lines
1.2 KiB
C++

#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) {
std::string filestr;
file(path, filestr);
size_t pos = filestr.rfind('.');
if(pos == std::string::npos || pos+1 == filestr.size()) {
ext = "";
return;
}
ext = filestr.substr(pos+1);
//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!
}