Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
Helpers.cpp
Go to the documentation of this file.
1#include "Helpers.h"
2
3#include <algorithm>
4#include <cctype>
5#include <locale>
6
7namespace API
8{
9 void MergePdbConfig(nlohmann::json& left, const nlohmann::json& right)
10 {
11 nlohmann::json pdb_config_result({});
12
13 pdb_config_result["structures"] = MergeStringArrays(left.value("structures", std::vector<std::string>{}),
14 right.value("structures", std::vector<std::string>{}));
15 pdb_config_result["functions"] = MergeStringArrays(left.value("functions", std::vector<std::string>{}),
16 right.value("functions", std::vector<std::string>{}));
17 pdb_config_result["globals"] = MergeStringArrays(left.value("globals", std::vector<std::string>{}),
18 right.value("globals", std::vector<std::string>{}));
19
20 left = pdb_config_result;
21 }
22
23 std::vector<std::string> MergeStringArrays(std::vector<std::string> first, std::vector<std::string> second)
24 {
25 std::vector<std::string> merged, unique;
26 std::sort(first.begin(), first.end());
27 std::sort(second.begin(), second.end());
28 std::set_union(
29 first.begin(),
30 first.end(),
31 second.begin(),
32 second.end(),
33 std::back_inserter(merged),
34 [](std::string s1, std::string s2)
35 {
36 return std::lexicographical_compare(
37 s1.begin(),
38 s1.end(),
39 s2.begin(),
40 s2.end(),
41 [](char c1, char c2)
42 {
43 return std::tolower(c1) < std::tolower(c2);
44 }
45 );
46 }
47 );
48
49 std::unique_copy(
50 merged.begin(),
51 merged.end(),
52 std::back_inserter(unique),
53 [](std::string s1, std::string s2)
54 {
55 return std::equal(
56 s1.begin(),
57 s1.end(),
58 s2.begin(),
59 s2.end(),
60 [](char c1, char c2)
61 {
62 return std::tolower(c1) == std::tolower(c2);
63 }
64 );
65 }
66 );
67
68 return unique;
69 }
70
71 std::string ReplaceString(std::string subject, const std::string& search, const std::string& replace)
72 {
73 size_t pos = 0;
74 while ((pos = subject.find(search, pos)) != std::string::npos)
75 {
76 subject.replace(pos, search.length(), replace);
77 pos += replace.length();
78 }
79
80 return subject;
81 }
82} // namespace API
Definition IBaseApi.h:9
std::vector< std::string > MergeStringArrays(std::vector< std::string > first, std::vector< std::string > second)
Definition Helpers.cpp:23
std::string ReplaceString(std::string subject, const std::string &search, const std::string &replace)
Definition Helpers.cpp:71
void MergePdbConfig(nlohmann::json &left, const nlohmann::json &right)
Definition Helpers.cpp:9
namespace for Niels Lohmann
Definition json.hpp:89
Definition json.hpp:4518