OSDN Git Service

[Refactor] #3529 pval_info_type::pval_desc をchar[] からstd::string に変えた
authorHourier <66951241+Hourier@users.noreply.github.com>
Sun, 9 Jul 2023 10:07:26 +0000 (19:07 +0900)
committerHourier <66951241+Hourier@users.noreply.github.com>
Tue, 11 Jul 2023 11:43:33 +0000 (20:43 +0900)
src/io-dump/random-art-info-dumper.cpp
src/wizard/artifact-analyzer.cpp
src/wizard/fixed-artifacts-spoiler.cpp
src/wizard/fixed-artifacts-spoiler.h
src/wizard/spoiler-util.h

index 6d4e675..d9b0c00 100644 (file)
@@ -11,6 +11,7 @@
 #include "wizard/artifact-analyzer.h"
 #include "wizard/fixed-artifacts-spoiler.h"
 #include "wizard/spoiler-util.h"
+#include <sstream>
 
 /*!
  * @brief ランダムアーティファクト1件をスポイラー出力する /
  */
 static void spoiler_print_randart(ItemEntity *o_ptr, obj_desc_list *art_ptr)
 {
-    pval_info_type *pval_ptr = &art_ptr->pval_info;
+    const auto *pval_ptr = &art_ptr->pval_info;
     fprintf(spoiler_file, "%s\n", art_ptr->description);
     if (!o_ptr->is_fully_known()) {
         fprintf(spoiler_file, _("%s不明\n", "%sUnknown\n"), spoiler_indent);
     } else {
-        if (pval_ptr->pval_desc[0]) {
-            spoiler_outlist(std::string(pval_ptr->pval_desc).append(_("の修正:", " to")).data(), pval_ptr->pval_affects, item_separator);
+        if (!pval_ptr->pval_desc.empty()) {
+            std::stringstream ss;
+            ss << pval_ptr->pval_desc << _("の修正:", " to");
+            spoiler_outlist(ss.str(), pval_ptr->pval_affects, item_separator);
         }
 
         spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator);
index bb23f5d..f0326cb 100644 (file)
@@ -85,12 +85,11 @@ static std::string analyze_general(PlayerType *player_ptr, ItemEntity *o_ptr)
 static void analyze_pval(ItemEntity *o_ptr, pval_info_type *pi_ptr)
 {
     if (!o_ptr->pval) {
-        pi_ptr->pval_desc[0] = '\0';
         return;
     }
 
     auto flags = object_flags(o_ptr);
-    strnfmt(pi_ptr->pval_desc, sizeof(pi_ptr->pval_desc), "%s%d", o_ptr->pval >= 0 ? "+" : "", o_ptr->pval);
+    pi_ptr->pval_desc = format("%s%d", o_ptr->pval >= 0 ? "+" : "", o_ptr->pval);
     std::vector<std::string> pval_descriptions;
     if (flags.has_all_of(EnumRange(TR_STR, TR_CHR))) {
         pval_descriptions.push_back(_("全能力", "All stats"));
index 927c5a9..f4223e3 100644 (file)
@@ -10,6 +10,7 @@
 #include "view/display-messages.h"
 #include "wizard/artifact-analyzer.h"
 #include "wizard/spoiler-util.h"
+#include <sstream>
 
 /*!
  * @brief フラグ名称を出力する汎用関数
@@ -17,7 +18,7 @@
  * @param descriptions フラグ名リスト
  * @param separator フラグ表示の区切り記号
  */
-void spoiler_outlist(std::string_view header, std::vector<std::string> &descriptions, char separator)
+void spoiler_outlist(std::string_view header, const std::vector<std::string> &descriptions, char separator)
 {
     if (descriptions.empty()) {
         return;
@@ -143,10 +144,12 @@ static bool make_fake_artifact(ItemEntity *o_ptr, FixedArtifactId fixed_artifact
  */
 static void spoiler_print_art(obj_desc_list *art_ptr)
 {
-    pval_info_type *pval_ptr = &art_ptr->pval_info;
+    const auto *pval_ptr = &art_ptr->pval_info;
     fprintf(spoiler_file, "%s\n", art_ptr->description);
-    if (pval_ptr->pval_desc[0]) {
-        spoiler_outlist(std::string(pval_ptr->pval_desc).append(_("の修正:", " to")).data(), pval_ptr->pval_affects, item_separator);
+    if (!pval_ptr->pval_desc.empty()) {
+        std::stringstream ss;
+        ss << pval_ptr->pval_desc << _("の修正:", " to");
+        spoiler_outlist(ss.str(), pval_ptr->pval_affects, item_separator);
     }
 
     spoiler_outlist(_("対:", "Slay"), art_ptr->slays, item_separator);
index e24ad63..d14a598 100644 (file)
@@ -3,6 +3,6 @@
 #include "system/angband.h"
 #include "wizard/spoiler-util.h"
 
-void spoiler_outlist(std::string_view header, std::vector<std::string> &descriptions, char seperator);
+void spoiler_outlist(std::string_view header, const std::vector<std::string> &descriptions, char seperator);
 void spoiler_outlist(concptr header, concptr *list, char separator);
 SpoilerOutputResultType spoil_fixed_artifact(concptr fname);
index 70af4ab..7b60564 100644 (file)
@@ -23,7 +23,7 @@ enum class SpoilerOutputResultType {
 struct pval_info_type {
     pval_info_type() = default;
 
-    char pval_desc[12]{}; /* This will contain a string such as "+2", "-10", etc. */
+    std::string pval_desc = ""; /* This will contain a string such as "+2", "-10", etc. */
 
     /* A list of various player traits affected by an object's pval such as stats, speed, stealth, etc. */
     std::vector<std::string> pval_affects{};