summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2022-05-17 18:40:02 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2022-05-17 18:40:02 -0400
commit9161baed625c59e5fccc5c2db49aa52a02a63608 (patch)
treee02e9067892fc854861e27b8480af6866b4b9c87
parentd55b84e81c0a8c3d67ce91facb3c724dbb67be54 (diff)
downloadorcus-155-debug-state-output-format.tar.gz
Dump misc document properties 155-debug-state-output-format
Also fix date_time_t::to_string() to ensure correct width for each date component value.
-rw-r--r--src/parser/types.cpp16
-rw-r--r--src/spreadsheet/debug_state_dumper.cpp15
-rw-r--r--src/spreadsheet/debug_state_dumper.hpp1
3 files changed, 31 insertions, 1 deletions
diff --git a/src/parser/types.cpp b/src/parser/types.cpp
index 5f6ee746..2b39b988 100644
--- a/src/parser/types.cpp
+++ b/src/parser/types.cpp
@@ -12,8 +12,11 @@
#include <limits>
#include <sstream>
#include <string_view>
+#include <iomanip>
#include <mdds/sorted_string_map.hpp>
+#include "ostream_utils.hpp"
+
namespace orcus {
const xmlns_id_t XMLNS_UNKNOWN_ID = nullptr;
@@ -275,7 +278,18 @@ bool date_time_t::operator< (const date_time_t& other) const
std::string date_time_t::to_string() const
{
std::ostringstream os;
- os << year << "-" << month << "-" << day << "T" << hour << ":" << minute << ":" << second;
+
+ // NB: setfill is sticky for the entire run whereas setw gets reset for each
+ // value.
+ os << std::setfill('0');
+
+ os << std::setw(4) << year
+ << "-" << std::setw(2) << month
+ << "-" << std::setw(2) << day
+ << "T" << std::setw(2) << hour
+ << ":" << std::setw(2) << minute
+ << ":" << std::setw(2) << second;
+
return os.str();
}
diff --git a/src/spreadsheet/debug_state_dumper.cpp b/src/spreadsheet/debug_state_dumper.cpp
index e991f3f4..0bcd62ee 100644
--- a/src/spreadsheet/debug_state_dumper.cpp
+++ b/src/spreadsheet/debug_state_dumper.cpp
@@ -20,9 +20,24 @@ doc_debug_state_dumper::doc_debug_state_dumper(const document_impl& doc) : m_doc
void doc_debug_state_dumper::dump(const fs::path& outdir) const
{
+ dump_properties(outdir);
dump_styles(outdir);
}
+void doc_debug_state_dumper::dump_properties(const fs::path& outdir) const
+{
+ const fs::path outpath = outdir / "properties.yaml";
+ std::ofstream of{outpath};
+ if (!of)
+ return;
+
+ ::orcus::detail::ostream_format_guard guard{of};
+
+ of << "formula-grammar: " << m_doc.grammar << std::endl;
+ of << "origin-date: " << m_doc.origin_date << std::endl;
+ of << "output-precision: " << short(m_doc.doc_config.output_precision) << std::endl;
+}
+
void doc_debug_state_dumper::dump_styles(const fs::path& outdir) const
{
const fs::path outpath = outdir / "styles.yaml";
diff --git a/src/spreadsheet/debug_state_dumper.hpp b/src/spreadsheet/debug_state_dumper.hpp
index 30a5fab2..07e45e92 100644
--- a/src/spreadsheet/debug_state_dumper.hpp
+++ b/src/spreadsheet/debug_state_dumper.hpp
@@ -28,6 +28,7 @@ public:
void dump(const boost::filesystem::path& outdir) const;
private:
+ void dump_properties(const boost::filesystem::path& outdir) const;
void dump_styles(const boost::filesystem::path& outdir) const;
};