From 2b7ac6f12d47220e399833e4a94b102c9fe82d44 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sun, 27 Jul 2025 10:23:33 +0800 Subject: [PATCH] Add new functions --- fileop.cpp | 10 +++++++++- fileop.h | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fileop.cpp b/fileop.cpp index 977ce98..10ec138 100644 --- a/fileop.cpp +++ b/fileop.cpp @@ -1,4 +1,4 @@ -#if HAVE_UTILS_CONFIG_H +#if HAVE_UTILS_CONFIG_H #include "utils_config.h" #endif @@ -700,3 +700,11 @@ FILE* fileop::fopen(std::string path, std::string mode) { return ::fopen(path.c_str(), mode.c_str()); #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); +} diff --git a/fileop.h b/fileop.h index 35f3743..7f814f0 100644 --- a/fileop.h +++ b/fileop.h @@ -1,4 +1,4 @@ -#ifndef _UTIL_FILEOP_H +#ifndef _UTIL_FILEOP_H #define _UTIL_FILEOP_H #include #include @@ -199,5 +199,11 @@ namespace fileop { */ std::string relpath(std::string path, std::string start = ""); 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