mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-06 05:08:45 +08:00
Add new functions
This commit is contained in:
10
fileop.cpp
10
fileop.cpp
@@ -1,4 +1,4 @@
|
|||||||
#if HAVE_UTILS_CONFIG_H
|
#if HAVE_UTILS_CONFIG_H
|
||||||
#include "utils_config.h"
|
#include "utils_config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -700,3 +700,11 @@ FILE* fileop::fopen(std::string path, std::string mode) {
|
|||||||
return ::fopen(path.c_str(), mode.c_str());
|
return ::fopen(path.c_str(), mode.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string fileop::extname(std::string path) {
|
||||||
|
auto loc = path.find_last_of('.');
|
||||||
|
if (loc == std::string::npos) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return path.substr(loc + 1, path.length() - loc - 1);
|
||||||
|
}
|
||||||
|
|||||||
8
fileop.h
8
fileop.h
@@ -1,4 +1,4 @@
|
|||||||
#ifndef _UTIL_FILEOP_H
|
#ifndef _UTIL_FILEOP_H
|
||||||
#define _UTIL_FILEOP_H
|
#define _UTIL_FILEOP_H
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -199,5 +199,11 @@ namespace fileop {
|
|||||||
*/
|
*/
|
||||||
std::string relpath(std::string path, std::string start = "");
|
std::string relpath(std::string path, std::string start = "");
|
||||||
FILE* fopen(std::string path, std::string mode);
|
FILE* fopen(std::string path, std::string mode);
|
||||||
|
/**
|
||||||
|
* @brief Get file extension name
|
||||||
|
* @param path Path
|
||||||
|
* @return File extension name. If no extension, will return empty string.
|
||||||
|
*/
|
||||||
|
std::string extname(std::string path);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user