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
This commit is contained in:
Crzyrndm 2018-07-14 19:52:21 +12:00
parent d4cc538faf
commit 9a33210144
4 changed files with 44 additions and 30 deletions

View File

@ -26,15 +26,22 @@
#include <xlnt/cell/rich_text.hpp>
#include <xlnt/cell/rich_text_run.hpp>
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<font>(), false})
: rich_text(rich_text_run{plain_text, optional<font>(), 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<font>(text_font), false})
: rich_text(rich_text_run{plain_text, optional<font>(text_font), has_trailing_whitespace(plain_text)})
{
}

View File

@ -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,11 +852,6 @@ 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())
@ -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");
}

View File

@ -27,7 +27,11 @@
#include <xlnt/styles/font.hpp>
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
@ -167,7 +171,7 @@ const std::string& font::name() const
{
return name_.get();
}
return Default_Name;
return Default_Name();
}
bool font::has_color() const

View File

@ -25,18 +25,27 @@
#include <array>
namespace {
// Order of elements defined by phonetic_pr::Type enum
const std::array<std::string, 4> Types{
const std::array<std::string, 4>& Types()
{
static const std::array<std::string, 4> types{
"fullwidthKatakana",
"halfwidthKatakana",
"Hiragana",
"noConversion"};
"noConversion"
};
return types;
}
// Order of elements defined by phonetic_pr::alignment enum
const std::array<std::string, 4> alignments{
const std::array<std::string, 4> &Alignments()
{
static const std::array<std::string, 4> 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<int>(type)];
return Types()[static_cast<int>(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<phonetic_type>(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<int>(type)];
return Alignments()[static_cast<int>(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<align>(i);
}