From 42323833d134f3faad10bd81fa6d14100ab15d21 Mon Sep 17 00:00:00 2001 From: Hourier <66951241+Hourier@users.noreply.github.com> Date: Mon, 8 May 2023 22:43:18 +0900 Subject: [PATCH] =?utf8?q?[Refactor]=20#3281=20path=5Fparse()=20=E3=81=AE?= =?utf8?q?=E5=BC=95=E6=95=B0=E3=82=92string=5Fview=20=E3=81=8B=E3=82=89pat?= =?utf8?q?h=20=E3=81=AB=E5=A4=89=E3=81=88=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/util/angband-files.cpp | 13 +++++++------ src/util/angband-files.h | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/util/angband-files.cpp b/src/util/angband-files.cpp index ad7a0cb2e..bb3b85409 100644 --- a/src/util/angband-files.cpp +++ b/src/util/angband-files.cpp @@ -69,7 +69,7 @@ void user_name(char *buf, int id) #endif /* SET_UID */ -std::filesystem::path path_parse(std::string_view file) +std::filesystem::path path_parse(const std::filesystem::path &path) #ifdef SET_UID { /* @@ -79,6 +79,7 @@ std::filesystem::path path_parse(std::string_view file) * Replace "~user/" by the home directory of the user named "user" * Replace "~/" by the home directory of the current user */ + const auto &file = path.string(); if (file.empty() || (file[0] != '~')) { return file; } @@ -125,7 +126,7 @@ std::filesystem::path path_parse(std::string_view file) } #else { - return file; + return path; } #endif /* SET_UID */ @@ -196,16 +197,16 @@ static std::string make_file_mode(const FileOpenMode mode, const bool is_binary) /*! * @brief OSごとの差異を吸収してファイルを開く - * @param file ファイルの相対パスまたは絶対パス + * @param path ファイルの相対パスまたは絶対パス * @param mode ファイルを開くモード * @param is_binary バイナリモードか否か (無指定の場合false:テキストモード) * @return ファイルポインタ */ -FILE *angband_fopen(const std::filesystem::path &file, const FileOpenMode mode, const bool is_binary) +FILE *angband_fopen(const std::filesystem::path &path, const FileOpenMode mode, const bool is_binary) { - const auto &path = path_parse(file.string()); + const auto &parsed_path = path_parse(path); const auto &open_mode = make_file_mode(mode, is_binary); - return fopen(path.string().data(), open_mode.data()); + return fopen(parsed_path.string().data(), open_mode.data()); } /* diff --git a/src/util/angband-files.h b/src/util/angband-files.h index 238607ec5..3ade8ba26 100644 --- a/src/util/angband-files.h +++ b/src/util/angband-files.h @@ -41,9 +41,9 @@ enum class FileOpenMode { APPEND, }; -std::filesystem::path path_parse(std::string_view file); +std::filesystem::path path_parse(const std::filesystem::path &path); std::filesystem::path path_build(const std::filesystem::path &path, std::string_view file); -FILE *angband_fopen(const std::filesystem::path &file, const FileOpenMode mode, const bool is_binary = false); +FILE *angband_fopen(const std::filesystem::path &path, const FileOpenMode mode, const bool is_binary = false); FILE *angband_fopen_temp(char *buf, int max); errr angband_fgets(FILE *fff, char *buf, ulong n); errr angband_fputs(FILE *fff, concptr buf, ulong n); -- 2.11.0