From 9b3cfda291a89ca92cfc2910274c3a7dd62b88bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Wed, 13 Jul 2022 12:22:45 -0400 Subject: [PATCH] fileutils: fix warning, cleanup Change-Id: I5c7386cf216404121bfe5f5364152e3b40fb8b53 --- src/fileutils.cpp | 15 ++++++++++----- src/fileutils.h | 7 ++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/fileutils.cpp b/src/fileutils.cpp index 3295f7d2bd..d3e2dad6cf 100644 --- a/src/fileutils.cpp +++ b/src/fileutils.cpp @@ -89,7 +89,12 @@ #include <pj/ctype.h> #include <pjlib-util/md5.h> -#define USE_STD_FILESYSTEM (defined __ANDROID__ || defined _WIN32) +#if (defined __ANDROID__ || defined _WIN32) +#define USE_STD_FILESYSTEM 1 +#else +#define USE_STD_FILESYSTEM 0 +#endif + #if USE_STD_FILESYSTEM #include <filesystem> #endif @@ -361,12 +366,12 @@ createFileLink(const std::string& linkFile, const std::string& target, bool hard createSymlink(linkFile, target); } -std::string -getFileExtension(const std::string& filename) +std::string_view +getFileExtension(std::string_view filename) { - std::string result = ""; + std::string_view result; auto sep = filename.find_last_of('.'); - if (sep != std::string::npos && sep != filename.size() - 1) + if (sep != std::string_view::npos && sep != filename.size() - 1) result = filename.substr(sep + 1); if (result.size() >= 8) return {}; diff --git a/src/fileutils.h b/src/fileutils.h index 5af214db08..3b798758b4 100644 --- a/src/fileutils.h +++ b/src/fileutils.h @@ -18,8 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef FILEUTILS_H_ -#define FILEUTILS_H_ +#pragma once #include <string> #include <vector> @@ -87,7 +86,7 @@ std::chrono::system_clock::time_point writeTime(const std::string& path); void createFileLink(const std::string& src, const std::string& dest, bool hard = false); -std::string getFileExtension(const std::string& filename); +std::string_view getFileExtension(std::string_view filename); /** * Read content of the directory. @@ -158,5 +157,3 @@ int accessFile(const std::string& file, int mode); } // namespace fileutils } // namespace jami - -#endif // FILEUTILS_H_ -- GitLab