Skip to content

Commit

Permalink
Enhancements
Browse files Browse the repository at this point in the history
Fix crash when using WireGuard as type filter rule.
Fix support for compiler older than gcc-10 or clang-10.
Optimize codes.
  • Loading branch information
tindy2013 committed Nov 13, 2023
1 parent 7ea43f9 commit b71cd1e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/generator/config/subexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool applyMatcher(const std::string &rule, std::string &real_rule, const Proxy &
std::string target, ret_real_rule;
static const std::string groupid_regex = R"(^!!(?:GROUPID|INSERT)=([\d\-+!,]+)(?:!!(.*))?$)", group_regex = R"(^!!(?:GROUP)=(.+?)(?:!!(.*))?$)";
static const std::string type_regex = R"(^!!(?:TYPE)=(.+?)(?:!!(.*))?$)", port_regex = R"(^!!(?:PORT)=(.+?)(?:!!(.*))?$)", server_regex = R"(^!!(?:SERVER)=(.+?)(?:!!(.*))?$)";
static const string_array types = {"", "SS", "SSR", "VMESS", "TROJAN", "SNELL", "HTTP", "HTTPS", "SOCKS5"};
static const string_array types = {"", "SS", "SSR", "VMESS", "TROJAN", "SNELL", "HTTP", "HTTPS", "SOCKS5", "WIREGUARD"};
if(startsWith(rule, "!!GROUP="))
{
regGetMatch(rule, group_regex, 3, 0, &target, &ret_real_rule);
Expand Down Expand Up @@ -155,7 +155,7 @@ bool applyMatcher(const std::string &rule, std::string &real_rule, const Proxy &
return true;
}

void processRemark(std::string &remark, string_array &remarks_list, bool proc_comma = true)
void processRemark(std::string &remark, const string_array &remarks_list, bool proc_comma = true)
{
// Replace every '=' with '-' in the remark string to avoid parse errors from the clients.
// Surge is tested to yield an error when handling '=' in the remark string,
Expand All @@ -172,7 +172,7 @@ void processRemark(std::string &remark, string_array &remarks_list, bool proc_co
}
std::string tempRemark = remark;
int cnt = 2;
while(std::find(remarks_list.begin(), remarks_list.end(), tempRemark) != remarks_list.end())
while(std::find(remarks_list.cbegin(), remarks_list.cend(), tempRemark) != remarks_list.cbegin())
{
tempRemark = remark + " " + std::to_string(cnt);
cnt++;
Expand Down
22 changes: 10 additions & 12 deletions src/utils/rapidjson_extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ namespace rapidjson_ext {
{
return (*this)(root);
};

friend ReturnType operator| (rapidjson::Value &root, const ExtensionFunction<ReturnType> &func)
{
return func(root);
}

friend ReturnType operator| (rapidjson::Value &&root, const ExtensionFunction<ReturnType> &func)
{
return func(root);
}
};

struct AddMemberOrReplace : public ExtensionFunction<rapidjson::Value &> {
Expand Down Expand Up @@ -165,18 +175,6 @@ namespace rapidjson_ext {
return buffer.GetString();
}
};

template <typename ReturnType>
inline ReturnType operator| (rapidjson::Value &root, const ExtensionFunction<ReturnType> &func)
{
return func(root);
}

template <typename ReturnType>
inline ReturnType operator| (rapidjson::Value &&root, const ExtensionFunction<ReturnType> &func)
{
return func(root);
}
}


Expand Down
24 changes: 18 additions & 6 deletions src/utils/stl_extra.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,37 @@ template <typename T> inline void eraseElements(T &target)
T().swap(target);
}

template <typename Container, typename Element>
concept ConstIterable = requires(Container a, Element b) {
#if __cpp_concepts >= 201907L // C++20 concepts supported (g++-10 or clang++-10)

template <typename Container>
concept ConstIterable = requires(Container a) {
{ a.cbegin() } -> std::same_as<typename Container::const_iterator>;
{ a.cend() } -> std::same_as<typename Container::const_iterator>;
typename Container::const_reference;
};

template <typename Container, typename Element>
concept Iterable = requires(Container a, Element b) {
template <typename Container>
concept Iterable = requires(Container a) {
{ a.begin() } -> std::same_as<typename Container::iterator>;
{ a.end() } -> std::same_as<typename Container::iterator>;
typename Container::reference;
};

template <typename ConstIterableContainer>
requires ConstIterable<ConstIterableContainer, typename ConstIterableContainer::value_type>
inline bool none_of(ConstIterableContainer &container, std::function<bool(typename ConstIterableContainer::const_reference)> func)
requires ConstIterable<ConstIterableContainer>
inline bool none_of(const ConstIterableContainer &container, std::function<bool(typename ConstIterableContainer::const_reference)> func)
{
return std::none_of(container.cbegin(), container.cend(), func);
}

#else // __cpp_concepts >= 201907L

template <typename Container>
inline bool none_of(const Container &container, std::function<bool(typename Container::const_reference)> func)
{
return std::none_of(container.cbegin(), container.cend(), func);
}

#endif // __cpp_concepts >= 201907L

#endif // STL_EXTRA_H_INCLUDED

0 comments on commit b71cd1e

Please sign in to comment.