OSDN Git Service

[Refactor] #3281 path_parse() の引数をstring_view からpath に変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Mon, 8 May 2023 13:43:18 +0000 (22:43 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Sat, 13 May 2023 04:38:44 +0000 (13:38 +0900)
src/util/angband-files.cpp
src/util/angband-files.h

index ad7a0cb..bb3b854 100644 (file)
@@ -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());
 }
 
 /*
index 238607e..3ade8ba 100644 (file)
@@ -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);