00001
00002
00003 #ifndef FILEUTILS_H
00004 #define FILEUTILS_H
00005
00006
00007 #include <string>
00008
00009
00010 namespace pge {
00011 namespace fileutils {
00012
00013
00015 static std::string getFilename(const std::string &path, const char &delimiter = '/') {
00016
00017
00018
00019 size_t pos = 0;
00020 size_t len = 0;
00021
00022
00023
00024
00025
00026 pos = path.find_last_of(delimiter);
00027 if(pos == std::string::npos) {
00028 return path;
00029 }
00030 len = path.size() - pos - 1;
00031 std::string sub = path.substr(pos + 1, len);
00032 return sub;
00033 }
00034
00035
00037 static std::string getExtension(const std::string &path, const char delimiter = '/') {
00038
00039
00040
00041 size_t pos = 0;
00042 size_t len = 0;
00043
00044
00045 pos = path.find_last_of('.');
00046 if(pos == std::string::npos) {
00047 return "not_found";
00048 }
00049 len = path.length() - pos;
00050 std::string sub = path.substr(pos + 1, len);
00051 return sub;
00052 }
00053 };
00054 };
00055
00056 #endif