Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
tonic::PackagesMap Class Reference

#include <packages_map.h>

Public Member Functions

 PackagesMap ()
 
 ~PackagesMap ()
 
bool Parse (const std::string &source, std::string *error)
 
std::string Resolve (const std::string &package_name)
 

Detailed Description

Definition at line 13 of file packages_map.h.

Constructor & Destructor Documentation

◆ PackagesMap()

tonic::PackagesMap::PackagesMap ( )

Definition at line 20 of file packages_map.cc.

20{}

◆ ~PackagesMap()

tonic::PackagesMap::~PackagesMap ( )

Definition at line 22 of file packages_map.cc.

22{}

Member Function Documentation

◆ Parse()

bool tonic::PackagesMap::Parse ( const std::string &  source,
std::string *  error 
)

Definition at line 24 of file packages_map.cc.

24 {
25 map_.clear();
26 const auto end = source.end();
27 for (auto it = source.begin(); it != end; ++it) {
28 const char c = *it;
29
30 // Skip blank lines.
31 if (isLineBreak(c))
32 continue;
33
34 // Skip comments.
35 if (c == '#') {
36 while (it != end && !isLineBreak(*it))
37 ++it;
38 continue;
39 }
40
41 if (c == ':') {
42 map_.clear();
43 *error = "Packages file contains a line that begins with ':'.";
44 return false;
45 }
46
47 auto package_name_begin = it;
48 auto package_name_end = end;
49 bool found_separator = false;
50 for (; it != end; ++it) {
51 const char c = *it;
52 if (c == ':' && !found_separator) {
53 found_separator = true;
54 package_name_end = it;
55 continue;
56 }
57 if (isLineBreak(c))
58 break;
59 }
60
61 if (!found_separator) {
62 map_.clear();
63 *error = "Packages file contains non-comment line that lacks a ':'.";
64 return false;
65 }
66
67 std::string package_name(package_name_begin, package_name_end);
68 std::string package_path(package_name_end + 1, it);
69
70 auto result = map_.emplace(package_name, package_path);
71 if (!result.second) {
72 map_.clear();
73 *error =
74 std::string("Packages file contains multiple entries for package '") +
75 package_name + "'.";
76 return false;
77 }
78 }
79
80 return true;
81}
SkBitmap source
Definition: examples.cpp:28
glong glong end
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result

◆ Resolve()

std::string tonic::PackagesMap::Resolve ( const std::string &  package_name)

Definition at line 83 of file packages_map.cc.

83 {
84 return map_[package_name];
85}

The documentation for this class was generated from the following files: