aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/include/vcpkg_Parse.h
blob: 2dda033b3d358ecb5d6406ae0bba8592e58f7d67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include <memory>
#include <unordered_map>

#include "vcpkg_expected.h"
#include "vcpkg_optional.h"

namespace vcpkg::Parse
{
    struct ParseControlErrorInfo
    {
        std::string name;
        std::vector<std::string> missing_fields;
        std::vector<std::string> extra_fields;
        std::error_code error;
    };

    template<class P>
    using ParseExpected = ExpectedT<std::unique_ptr<P>, std::unique_ptr<ParseControlErrorInfo>>;

    using RawParagraph = std::unordered_map<std::string, std::string>;

    struct ParagraphParser
    {
        ParagraphParser(RawParagraph&& fields) : fields(std::move(fields)) {}

        void required_field(const std::string& fieldname, std::string& out);
        std::string optional_field(const std::string& fieldname) const;
        std::unique_ptr<ParseControlErrorInfo> error_info(const std::string& name) const;

    private:
        RawParagraph&& fields;
        std::vector<std::string> missing_fields;
    };

    std::vector<std::string> parse_comma_list(const std::string& str);
}