From 9a33210144d5e313926171da929553254c7082e9 Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Sat, 14 Jul 2018 19:52:21 +1200 Subject: [PATCH] Resolve warnings about global ctors and an unused variable -- while unlikely to become an issue, ordering of ctors across source files is undefined and debugging issues related to it is not easy so just avoid that issue --- source/cell/rich_text.cpp | 11 ++++- source/detail/serialization/xlsx_producer.cpp | 10 +---- source/styles/font.cpp | 12 ++++-- source/worksheet/phonetic_pr.cpp | 41 +++++++++++-------- 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/source/cell/rich_text.cpp b/source/cell/rich_text.cpp index ad5cccbd..820bba5d 100644 --- a/source/cell/rich_text.cpp +++ b/source/cell/rich_text.cpp @@ -26,15 +26,22 @@ #include #include +namespace { +bool has_trailing_whitespace(const std::string &s) +{ + return !s.empty() && (s.front() == ' ' || s.back() == ' '); +}; +} + namespace xlnt { rich_text::rich_text(const std::string &plain_text) - : rich_text(rich_text_run{plain_text, optional(), false}) + : rich_text(rich_text_run{plain_text, optional(), has_trailing_whitespace(plain_text)}) { } rich_text::rich_text(const std::string &plain_text, const class font &text_font) - : rich_text(rich_text_run{plain_text, optional(text_font), false}) + : rich_text(rich_text_run{plain_text, optional(text_font), has_trailing_whitespace(plain_text)}) { } diff --git a/source/detail/serialization/xlsx_producer.cpp b/source/detail/serialization/xlsx_producer.cpp index aef2a050..d2c27a92 100644 --- a/source/detail/serialization/xlsx_producer.cpp +++ b/source/detail/serialization/xlsx_producer.cpp @@ -816,7 +816,6 @@ void xlsx_producer::write_pivot_table(const relationship & /*rel*/) void xlsx_producer::write_shared_string_table(const relationship & /*rel*/) { static const auto &xmlns = constants::ns("spreadsheetml"); - static const auto &xmlns_xml = constants::ns("xml"); write_start_element(xmlns, "sst"); write_namespace(xmlns, ""); @@ -853,18 +852,13 @@ void xlsx_producer::write_shared_string_table(const relationship & /*rel*/) write_attribute("count", string_count); write_attribute("uniqueCount", source_.shared_strings().size()); - auto has_trailing_whitespace = [](const std::string &s) - { - return !s.empty() && (s.front() == ' ' || s.back() == ' '); - }; - for (const auto &string : source_.shared_strings()) { if (string.runs().size() == 1 && !string.runs().at(0).second.is_set()) { write_start_element(xmlns, "si"); write_start_element(xmlns, "t"); - write_characters(string.plain_text(),string.runs().front().preserve_space); + write_characters(string.plain_text(), string.runs().front().preserve_space); write_end_element(xmlns, "t"); write_end_element(xmlns, "si"); @@ -926,7 +920,7 @@ void xlsx_producer::write_shared_string_table(const relationship & /*rel*/) } write_start_element(xmlns, "t"); - write_characters(run.first, has_trailing_whitespace(run.first)); + write_characters(run.first, run.preserve_space); write_end_element(xmlns, "t"); write_end_element(xmlns, "r"); } diff --git a/source/styles/font.cpp b/source/styles/font.cpp index b474ab07..6bd31783 100644 --- a/source/styles/font.cpp +++ b/source/styles/font.cpp @@ -27,7 +27,11 @@ #include namespace { -const std::string Default_Name = "Calibri"; +const std::string &Default_Name() +{ + static const std::string Default("Calibri"); + return Default; +} constexpr double Default_Size = 12.0; } // namespace @@ -161,13 +165,13 @@ font &font::name(const std::string &name) return *this; } -const std::string& font::name() const +const std::string &font::name() const { if (name_.is_set()) { return name_.get(); } - return Default_Name; + return Default_Name(); } bool font::has_color() const @@ -229,7 +233,7 @@ std::size_t font::family() const return family_.get(); } -const std::string& font::scheme() const +const std::string &font::scheme() const { return scheme_.get(); } diff --git a/source/worksheet/phonetic_pr.cpp b/source/worksheet/phonetic_pr.cpp index 97efe752..602fa01c 100644 --- a/source/worksheet/phonetic_pr.cpp +++ b/source/worksheet/phonetic_pr.cpp @@ -25,18 +25,27 @@ #include namespace { // Order of elements defined by phonetic_pr::Type enum -const std::array Types{ - "fullwidthKatakana", - "halfwidthKatakana", - "Hiragana", - "noConversion"}; +const std::array& Types() +{ + static const std::array types{ + "fullwidthKatakana", + "halfwidthKatakana", + "Hiragana", + "noConversion" + }; + return types; +} // Order of elements defined by phonetic_pr::alignment enum -const std::array alignments{ - "Center", - "Distributed", - "Left", - "NoControl"}; +const std::array &Alignments() +{ + static const std::array alignments{ + "Center", + "Distributed", + "Left", + "NoControl"}; + return alignments; +} } // namespace @@ -108,14 +117,14 @@ void phonetic_pr::alignment(align align) // serialisation const std::string &phonetic_pr::type_as_string(phonetic_pr::phonetic_type type) { - return Types[static_cast(type)]; + return Types()[static_cast(type)]; } phonetic_pr::phonetic_type phonetic_pr::type_from_string(const std::string &str) { - for (std::size_t i = 0; i < Types.size(); ++i) + for (std::size_t i = 0; i < Types().size(); ++i) { - if (str == Types[i]) + if (str == Types()[i]) { return static_cast(i); } @@ -125,14 +134,14 @@ phonetic_pr::phonetic_type phonetic_pr::type_from_string(const std::string &str) const std::string &phonetic_pr::alignment_as_string(align type) { - return alignments[static_cast(type)]; + return Alignments()[static_cast(type)]; } phonetic_pr::align phonetic_pr::alignment_from_string(const std::string &str) { - for (std::size_t i = 0; i < alignments.size(); ++i) + for (std::size_t i = 0; i < Alignments().size(); ++i) { - if (str == alignments[i]) + if (str == Alignments()[i]) { return static_cast(i); }