From 47f74fd4c1b50be7c1a463a7e6eca9de13c4a38f Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Tue, 5 Jul 2016 00:09:51 +0800 Subject: [PATCH] fix some windows build problems and warnings --- cmake/xlnt.cmake | 1 + source/detail/excel_serializer.cpp | 3 +-- source/detail/number_formatter.cpp | 5 +++-- source/detail/style_serializer.cpp | 8 ++------ source/detail/worksheet_serializer.cpp | 10 +++++----- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/cmake/xlnt.cmake b/cmake/xlnt.cmake index e3e54ea3..388cae4e 100644 --- a/cmake/xlnt.cmake +++ b/cmake/xlnt.cmake @@ -71,6 +71,7 @@ if(SHARED) target_compile_definitions(xlnt.shared PRIVATE XLNT_SHARED=1) if(MSVC) target_compile_definitions(xlnt.shared PRIVATE XLNT_EXPORT=1) + target_compile_definitions(xlnt.shared PRIVATE PUGIXML_API=__declspec\(dllexport\)) set_target_properties(xlnt.shared PROPERTIES COMPILE_FLAGS "/wd\"4251\" /wd\"4275\"") endif() install(TARGETS xlnt.shared diff --git a/source/detail/excel_serializer.cpp b/source/detail/excel_serializer.cpp index cba36670..b6baed78 100644 --- a/source/detail/excel_serializer.cpp +++ b/source/detail/excel_serializer.cpp @@ -268,8 +268,7 @@ void excel_serializer::write_data(bool /*as_template*/) { const auto &strings = workbook_.get_shared_strings(); pugi::xml_document shared_strings_xml; - shared_strings_serializer strings_serializer; - strings_serializer.write_shared_strings(strings, shared_strings_xml); + shared_strings_serializer::write_shared_strings(strings, shared_strings_xml); shared_strings_xml.save(ss); archive_.writestr(constants::ArcSharedString(), ss.str()); diff --git a/source/detail/number_formatter.cpp b/source/detail/number_formatter.cpp index 1456793a..e995578e 100644 --- a/source/detail/number_formatter.cpp +++ b/source/detail/number_formatter.cpp @@ -160,6 +160,7 @@ bool format_condition::satisfied_by(long double number) const case condition_type::not_equal: return number != value; case condition_type::none: + default: return false; } } @@ -471,11 +472,11 @@ void number_format_parser::finalize() if (part.type == template_part::template_type::month_number || part.type == template_part::template_type::month_number_leading_zero) { - if (i < code.parts.size() - 2) + if (code.parts.size() > 1 && i < code.parts.size() - 2) { const auto &next = code.parts[i + 1]; const auto &after_next = code.parts[i + 2]; - + if (next.type == template_part::template_type::text && next.string == ":" && (after_next.type == template_part::template_type::second || diff --git a/source/detail/style_serializer.cpp b/source/detail/style_serializer.cpp index 003b4f72..80e933e5 100644 --- a/source/detail/style_serializer.cpp +++ b/source/detail/style_serializer.cpp @@ -411,17 +411,13 @@ xlnt::alignment read_alignment(const pugi::xml_node alignment_node) align.set_wrap_text(is_true(alignment_node.attribute("wrapText").value())); align.set_shrink_to_fit(is_true(alignment_node.attribute("shrinkToFit").value())); - bool has_vertical = alignment_node.attribute("vertical"); - - if (has_vertical) + if (alignment_node.attribute("vertical")) { std::string vertical = alignment_node.attribute("vertical").value(); align.set_vertical(vertical_alignment_from_string(vertical)); } - bool has_horizontal = alignment_node.attribute("horizontal"); - - if (has_horizontal) + if (alignment_node.attribute("horizontal")) { std::string horizontal = alignment_node.attribute("horizontal").value(); align.set_horizontal(horizontal_alignment_from_string(horizontal)); diff --git a/source/detail/worksheet_serializer.cpp b/source/detail/worksheet_serializer.cpp index 58b766c6..a6bd1e73 100644 --- a/source/detail/worksheet_serializer.cpp +++ b/source/detail/worksheet_serializer.cpp @@ -129,17 +129,17 @@ bool worksheet_serializer::read_worksheet(const pugi::xml_document &xml, detail: if (cell_found) { - bool has_value = cell_node.child("v"); + bool has_value = cell_node.child("v") != nullptr; std::string value_string = has_value ? cell_node.child("v").text().get() : ""; - bool has_type = cell_node.attribute("t"); + bool has_type = cell_node.attribute("t") != nullptr; std::string type = has_type ? cell_node.attribute("t").value() : ""; - bool has_format = cell_node.attribute("s"); + bool has_format = cell_node.attribute("s") != nullptr; auto format_id = static_cast(has_format ? std::stoull(cell_node.attribute("s").value()) : 0LL); - bool has_formula = cell_node.child("f"); - bool has_shared_formula = has_formula && cell_node.child("f").attribute("t") + bool has_formula = cell_node.child("f") != nullptr; + bool has_shared_formula = has_formula && cell_node.child("f").attribute("t") != nullptr && cell_node.child("f").attribute("t").value() == std::string("shared"); auto cell = sheet_.get_cell(address);