libmrbesen/src/Files.cpp

39 lines
1.1 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) {
size_t pos = path.rfind('.');
if(pos == std::string::npos || pos+1 == path.size()) {
ext = "";
return;
}
ext = path.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!
}