MCPcopy Create free account
hub / github.com/ByConity/ByConity / argsToConfig

Function argsToConfig

base/common/argsToConfig.cpp:7–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5
6
7void argsToConfig(const Poco::Util::Application::ArgVec & argv, Poco::Util::LayeredConfiguration & config, int priority)
8{
9 /// Parsing all args and converting to config layer
10 /// Test: -- --1=1 --1=2 --3 5 7 8 -9 10 -11=12 14= 15== --16==17 --=18 --19= --20 21 22 --23 --24 25 --26 -27 28 ---29=30 -- ----31 32 --33 3-4
11 Poco::AutoPtr<Poco::Util::MapConfiguration> map_config = new Poco::Util::MapConfiguration;
12 std::string key;
13 for (const auto & arg : argv)
14 {
15 auto key_start = arg.find_first_not_of('-');
16 auto pos_minus = arg.find('-');
17 auto pos_eq = arg.find('=');
18
19 // old saved '--key', will set to some true value "1"
20 if (!key.empty() && pos_minus != std::string::npos && pos_minus < key_start)
21 {
22 map_config->setString(key, "1");
23 key = "";
24 }
25
26 if (pos_eq == std::string::npos)
27 {
28 if (!key.empty())
29 {
30 if (pos_minus == std::string::npos || pos_minus > key_start)
31 {
32 map_config->setString(key, arg);
33 }
34 key = "";
35 }
36 if (pos_minus != std::string::npos && key_start != std::string::npos && pos_minus < key_start)
37 key = arg.substr(key_start);
38 continue;
39 }
40 else
41 {
42 key = "";
43 }
44
45 if (key_start == std::string::npos)
46 continue;
47
48 if (pos_minus > key_start)
49 continue;
50
51 key = arg.substr(key_start, pos_eq - key_start);
52 if (key.empty())
53 continue;
54 std::string value;
55 if (arg.size() > pos_eq)
56 value = arg.substr(pos_eq + 1);
57
58 map_config->setString(key, value);
59 key = "";
60 }
61
62 Poco::Util::MapConfiguration::Keys keys;
63 map_config->keys(keys);
64

Callers 3

initializeMethod · 0.85
initMethod · 0.85
initMethod · 0.85

Calls 6

setStringMethod · 0.80
findMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
keysMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected