From d2bab3c370fca9fa5216d97495810faaeeaebc2d Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Fri, 24 Mar 2017 10:46:49 -0700 Subject: Rework Paragraph parsing error handling. Add single paragraph functions --- toolsrc/include/Paragraphs.h | 6 ++++-- toolsrc/include/paragraph_parse_result.h | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 toolsrc/include/paragraph_parse_result.h (limited to 'toolsrc/include') diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h index 79b66a67f..74f8218ca 100644 --- a/toolsrc/include/Paragraphs.h +++ b/toolsrc/include/Paragraphs.h @@ -8,8 +8,10 @@ namespace vcpkg::Paragraphs { - std::vector> get_paragraphs(const fs::path& control_path); - std::vector> parse_paragraphs(const std::string& str); + expected> get_single_paragraph(const fs::path& control_path); + expected>> get_paragraphs(const fs::path& control_path); + expected> parse_single_paragraph(const std::string& str); + expected>> parse_paragraphs(const std::string& str); expected try_load_port(const fs::path& control_path); diff --git a/toolsrc/include/paragraph_parse_result.h b/toolsrc/include/paragraph_parse_result.h new file mode 100644 index 000000000..47f20c08e --- /dev/null +++ b/toolsrc/include/paragraph_parse_result.h @@ -0,0 +1,35 @@ +#pragma once +#include + +namespace vcpkg +{ + enum class paragraph_parse_result + { + SUCCESS = 0, + EXPECTED_ONE_PARAGRAPH + }; + + struct paragraph_parse_result_category_impl final : std::error_category + { + virtual const char* name() const noexcept override; + + virtual std::string message(int ev) const noexcept override; + }; + + const std::error_category& paragraph_parse_result_category(); + + std::error_code make_error_code(paragraph_parse_result e); + + paragraph_parse_result to_paragraph_parse_result(int i); + + paragraph_parse_result to_paragraph_parse_result(std::error_code ec); +} + +// Enable implicit conversion to std::error_code +namespace std +{ + template <> + struct is_error_code_enum : ::std::true_type + { + }; +} -- cgit v1.2.3