Update toml11 to v4.3.0

This commit is contained in:
Tindy X
2025-01-16 17:26:52 +08:00
parent 05959b09b4
commit 691193731f
5 changed files with 45 additions and 45 deletions

View File

@@ -34,7 +34,7 @@ cmake -DCMAKE_BUILD_TYPE=Release .
make libcron install -j3 make libcron install -j3
cd .. cd ..
git clone https://github.com/ToruNiina/toml11 --branch="v3.7.1" --depth=1 git clone https://github.com/ToruNiina/toml11 --branch="v4.3.0" --depth=1
cd toml11 cd toml11
cmake -DCMAKE_CXX_STANDARD=11 . cmake -DCMAKE_CXX_STANDARD=11 .
make install -j4 make install -j4

View File

@@ -41,7 +41,7 @@ sudo install -d /usr/local/include/date/
sudo install -m644 libcron/externals/date/include/date/* /usr/local/include/date/ sudo install -m644 libcron/externals/date/include/date/* /usr/local/include/date/
cd .. cd ..
git clone https://github.com/ToruNiina/toml11 --branch="v3.7.1" --depth=1 git clone https://github.com/ToruNiina/toml11 --branch="v4.3.0" --depth=1
cd toml11 cd toml11
cmake -DCMAKE_CXX_STANDARD=11 . cmake -DCMAKE_CXX_STANDARD=11 .
sudo make install -j6 > /dev/null sudo make install -j6 > /dev/null

View File

@@ -38,7 +38,7 @@ cmake -DRAPIDJSON_BUILD_DOC=OFF -DRAPIDJSON_BUILD_EXAMPLES=OFF -DRAPIDJSON_BUILD
make install -j4 make install -j4
cd .. cd ..
git clone https://github.com/ToruNiina/toml11 --branch v3.8.1 --depth=1 git clone https://github.com/ToruNiina/toml11 --branch "v4.3.0" --depth=1
cd toml11 cd toml11
cmake -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=11 . cmake -DCMAKE_INSTALL_PREFIX="$MINGW_PREFIX" -G "Unix Makefiles" -DCMAKE_CXX_STANDARD=11 .
make install -j4 make install -j4

View File

@@ -17,9 +17,9 @@ namespace toml
static ProxyGroupConfig from_toml(const value& v) static ProxyGroupConfig from_toml(const value& v)
{ {
ProxyGroupConfig conf; ProxyGroupConfig conf;
conf.Name = toml::find<String>(v, "name"); conf.Name = find<String>(v, "name");
String type = toml::find<String>(v, "type"); String type = find<String>(v, "type");
String strategy = toml::find_or<String>(v, "strategy", ""); String strategy = find_or<String>(v, "strategy", "");
switch(hash_(type)) switch(hash_(type))
{ {
case "select"_hash: case "select"_hash:
@@ -27,18 +27,18 @@ namespace toml
break; break;
case "url-test"_hash: case "url-test"_hash:
conf.Type = ProxyGroupType::URLTest; conf.Type = ProxyGroupType::URLTest;
conf.Url = toml::find<String>(v, "url"); conf.Url = find<String>(v, "url");
conf.Interval = toml::find<Integer>(v, "interval"); conf.Interval = find<Integer>(v, "interval");
conf.Tolerance = toml::find_or<Integer>(v, "tolerance", 0); conf.Tolerance = find_or<Integer>(v, "tolerance", 0);
if(v.contains("lazy")) if(v.contains("lazy"))
conf.Lazy = toml::find_or<bool>(v, "lazy", false); conf.Lazy = find_or<bool>(v, "lazy", false);
if(v.contains("evaluate-before-use")) if(v.contains("evaluate-before-use"))
conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); conf.EvaluateBeforeUse = find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get());
break; break;
case "load-balance"_hash: case "load-balance"_hash:
conf.Type = ProxyGroupType::LoadBalance; conf.Type = ProxyGroupType::LoadBalance;
conf.Url = toml::find<String>(v, "url"); conf.Url = find<String>(v, "url");
conf.Interval = toml::find<Integer>(v, "interval"); conf.Interval = find<Integer>(v, "interval");
switch(hash_(strategy)) switch(hash_(strategy))
{ {
case "consistent-hashing"_hash: case "consistent-hashing"_hash:
@@ -49,14 +49,14 @@ namespace toml
break; break;
} }
if(v.contains("persistent")) if(v.contains("persistent"))
conf.Persistent = toml::find_or(v, "persistent", conf.Persistent.get()); conf.Persistent = find_or(v, "persistent", conf.Persistent.get());
break; break;
case "fallback"_hash: case "fallback"_hash:
conf.Type = ProxyGroupType::Fallback; conf.Type = ProxyGroupType::Fallback;
conf.Url = toml::find<String>(v, "url"); conf.Url = find<String>(v, "url");
conf.Interval = toml::find<Integer>(v, "interval"); conf.Interval = find<Integer>(v, "interval");
if(v.contains("evaluate-before-use")) if(v.contains("evaluate-before-use"))
conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); conf.EvaluateBeforeUse = find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get());
break; break;
case "relay"_hash: case "relay"_hash:
conf.Type = ProxyGroupType::Relay; conf.Type = ProxyGroupType::Relay;
@@ -66,24 +66,24 @@ namespace toml
break; break;
case "smart"_hash: case "smart"_hash:
conf.Type = ProxyGroupType::Smart; conf.Type = ProxyGroupType::Smart;
conf.Url = toml::find<String>(v, "url"); conf.Url = find<String>(v, "url");
conf.Interval = toml::find<Integer>(v, "interval"); conf.Interval = find<Integer>(v, "interval");
conf.Tolerance = toml::find_or<Integer>(v, "tolerance", 0); conf.Tolerance = find_or<Integer>(v, "tolerance", 0);
if(v.contains("lazy")) if(v.contains("lazy"))
conf.Lazy = toml::find_or<bool>(v, "lazy", false); conf.Lazy = find_or<bool>(v, "lazy", false);
if(v.contains("evaluate-before-use")) if(v.contains("evaluate-before-use"))
conf.EvaluateBeforeUse = toml::find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get()); conf.EvaluateBeforeUse = find_or(v, "evaluate-before-use", conf.EvaluateBeforeUse.get());
break; break;
default: default:
throw toml::syntax_error("Proxy Group has incorrect type, should be one of following:\n select, url-test, load-balance, fallback, relay, ssid", v.at("type").location()); throw serialization_error(format_error("Proxy Group has unsupported type!", v.at("type").location(), "should be one of following: select, url-test, load-balance, fallback, relay, ssid"), v.at("type").location());
} }
conf.Timeout = toml::find_or(v, "timeout", 5); conf.Timeout = find_or(v, "timeout", 5);
conf.Proxies = toml::find_or<StrArray>(v, "rule", {}); conf.Proxies = find_or<StrArray>(v, "rule", {});
conf.UsingProvider = toml::find_or<StrArray>(v, "use", {}); conf.UsingProvider = find_or<StrArray>(v, "use", {});
if(conf.Proxies.empty() && conf.UsingProvider.empty()) if(conf.Proxies.empty() && conf.UsingProvider.empty())
throw toml::syntax_error("Proxy Group must contains at least one of proxy match rule or provider", v.location()); throw serialization_error(format_error("Proxy Group must contains at least one of proxy match rule or provider!", v.location(), "here"), v.location());
if(v.contains("disable-udp")) if(v.contains("disable-udp"))
conf.DisableUdp = toml::find_or(v, "disable-udp", conf.DisableUdp.get()); conf.DisableUdp = find_or(v, "disable-udp", conf.DisableUdp.get());
return conf; return conf;
} }
}; };
@@ -94,8 +94,8 @@ namespace toml
static RulesetConfig from_toml(const value& v) static RulesetConfig from_toml(const value& v)
{ {
RulesetConfig conf; RulesetConfig conf;
conf.Group = toml::find<String>(v, "group"); conf.Group = find<String>(v, "group");
String type = toml::find_or<String>(v, "type", "surge-ruleset"); String type = find_or<String>(v, "type", "surge-ruleset");
switch(hash_(type)) switch(hash_(type))
{ {
/* /*
@@ -132,10 +132,10 @@ namespace toml
conf.Url = type + ":"; conf.Url = type + ":";
break; break;
default: default:
throw toml::syntax_error("Ruleset has incorrect type, should be one of following:\n surge-ruleset, quantumultx, clash-domain, clash-ipcidr, clash-classic", v.at("type").location()); throw serialization_error(format_error("Ruleset has unsupported type!", v.at("type").location(), "should be one of following: surge-ruleset, quantumultx, clash-domain, clash-ipcidr, clash-classic"), v.at("type").location());
} }
conf.Url += toml::find<String>(v, "ruleset"); conf.Url += find<String>(v, "ruleset");
conf.Interval = toml::find_or<Integer>(v, "interval", 86400); conf.Interval = find_or<Integer>(v, "interval", 86400);
return conf; return conf;
} }
}; };
@@ -148,14 +148,14 @@ namespace toml
RegexMatchConfig conf; RegexMatchConfig conf;
if(v.contains("script")) if(v.contains("script"))
{ {
conf.Script = toml::find<String>(v, "script"); conf.Script = find<String>(v, "script");
return conf; return conf;
} }
conf.Match = toml::find<String>(v, "match"); conf.Match = find<String>(v, "match");
if(v.contains("emoji")) if(v.contains("emoji"))
conf.Replace = toml::find<String>(v, "emoji"); conf.Replace = find<String>(v, "emoji");
else else
conf.Replace = toml::find<String>(v, "replace"); conf.Replace = find<String>(v, "replace");
return conf; return conf;
} }
}; };
@@ -166,10 +166,10 @@ namespace toml
static CronTaskConfig from_toml(const value& v) static CronTaskConfig from_toml(const value& v)
{ {
CronTaskConfig conf; CronTaskConfig conf;
conf.Name = toml::find<String>(v, "name"); conf.Name = find<String>(v, "name");
conf.CronExp = toml::find<String>(v, "cronexp"); conf.CronExp = find<String>(v, "cronexp");
conf.Path = toml::find<String>(v, "path"); conf.Path = find<String>(v, "path");
conf.Timeout = toml::find_or<Integer>(v, "timeout", 0); conf.Timeout = find_or<Integer>(v, "timeout", 0);
return conf; return conf;
} }
}; };

View File

@@ -567,13 +567,13 @@ void readYAMLConf(YAML::Node &node)
} }
template <class T, class... U> template <class T, class... U>
void find_if_exist(const toml::value &v, const toml::key &k, T& target, U&&... args) void find_if_exist(const toml::value &v, const toml::value::key_type &k, T& target, U&&... args)
{ {
if(v.contains(k)) target = toml::find<T>(v, k); if(v.contains(k)) target = toml::find<T>(v, k);
if constexpr (sizeof...(args) > 0) find_if_exist(v, std::forward<U>(args)...); if constexpr (sizeof...(args) > 0) find_if_exist(v, std::forward<U>(args)...);
} }
void operate_toml_kv_table(const std::vector<toml::table> &arr, const toml::key &key_name, const toml::key &value_name, std::function<void (const toml::value&, const toml::value&)> binary_op) void operate_toml_kv_table(const std::vector<toml::table> &arr, const toml::value::key_type &key_name, const toml::value::key_type &value_name, std::function<void (const toml::value&, const toml::value&)> binary_op)
{ {
for(const toml::table &table : arr) for(const toml::table &table : arr)
{ {
@@ -803,7 +803,7 @@ void readConf()
return readYAMLConf(yaml); return readYAMLConf(yaml);
} }
toml::value conf = parseToml(prefdata, global.prefPath); toml::value conf = parseToml(prefdata, global.prefPath);
if(!conf.is_uninitialized() && toml::find_or<int>(conf, "version", 0)) if(!conf.is_empty() && toml::find_or<int>(conf, "version", 0))
return readTOMLConf(conf); return readTOMLConf(conf);
} }
catch (YAML::Exception &e) catch (YAML::Exception &e)
@@ -1213,7 +1213,7 @@ int loadExternalConfig(std::string &path, ExternalConfig &ext)
if(yaml.size() && yaml["custom"].IsDefined()) if(yaml.size() && yaml["custom"].IsDefined())
return loadExternalYAML(yaml, ext); return loadExternalYAML(yaml, ext);
toml::value conf = parseToml(base_content, path); toml::value conf = parseToml(base_content, path);
if(!conf.is_uninitialized() && toml::find_or<int>(conf, "version", 0)) if(!conf.is_empty() && toml::find_or<int>(conf, "version", 0))
return loadExternalTOML(conf, ext); return loadExternalTOML(conf, ext);
} }
catch (YAML::Exception &e) catch (YAML::Exception &e)