mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 18:01:26 +08:00
更新json库,修复转义字符导致的崩溃问题
This commit is contained in:
@@ -18,16 +18,16 @@ namespace json
|
||||
using const_reverse_iterator = raw_array::const_reverse_iterator;
|
||||
|
||||
array() = default;
|
||||
array(const array &rhs) = default;
|
||||
array(array &&rhs) noexcept = default;
|
||||
array(const raw_array &arr);
|
||||
array(raw_array &&arr) noexcept;
|
||||
array(const array& rhs) = default;
|
||||
array(array&& rhs) noexcept = default;
|
||||
array(const raw_array& arr);
|
||||
array(raw_array&& arr) noexcept;
|
||||
array(std::initializer_list<raw_array::value_type> init_list);
|
||||
template<typename EleType>
|
||||
array(std::vector<EleType> vec) {
|
||||
static_assert(
|
||||
std::is_constructible<json::value, EleType>::value,
|
||||
"Parameter can't be used to construct a json::value");
|
||||
static_assert(
|
||||
std::is_constructible<json::value, EleType>::value,
|
||||
"Parameter can't be used to construct a json::value");
|
||||
for (auto&& ele : vec) {
|
||||
_array_data.emplace_back(std::move(ele));
|
||||
}
|
||||
@@ -38,7 +38,7 @@ namespace json
|
||||
bool empty() const noexcept { return _array_data.empty(); }
|
||||
size_t size() const noexcept { return _array_data.size(); }
|
||||
bool exist(size_t pos) const { return _array_data.size() < pos; }
|
||||
const value &at(size_t pos) const;
|
||||
const value& at(size_t pos) const;
|
||||
const std::string to_string() const;
|
||||
const std::string format(std::string shift_str = " ", size_t basic_shift_count = 0) const;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace json
|
||||
const double get(size_t pos, double default_value) const;
|
||||
const long double get(size_t pos, long double default_value) const;
|
||||
const std::string get(size_t pos, std::string default_value) const;
|
||||
const std::string get(size_t pos, const char * default_value) const;
|
||||
const std::string get(size_t pos, const char* default_value) const;
|
||||
|
||||
template <typename... Args>
|
||||
decltype(auto) emplace_back(Args &&... args)
|
||||
@@ -76,11 +76,11 @@ namespace json
|
||||
const_reverse_iterator crbegin() const noexcept;
|
||||
const_reverse_iterator crend() const noexcept;
|
||||
|
||||
const value &operator[](size_t pos) const;
|
||||
value &operator[](size_t pos);
|
||||
const value& operator[](size_t pos) const;
|
||||
value& operator[](size_t pos);
|
||||
|
||||
array &operator=(const array &) = default;
|
||||
array &operator=(array &&) noexcept = default;
|
||||
array& operator=(const array&) = default;
|
||||
array& operator=(array&&) noexcept = default;
|
||||
|
||||
// const raw_array &raw_data() const;
|
||||
|
||||
@@ -88,6 +88,6 @@ namespace json
|
||||
raw_array _array_data;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const array &arr);
|
||||
std::ostream& operator<<(std::ostream& out, const array& arr);
|
||||
|
||||
} // namespace json
|
||||
0
3rdPart/include/meojson/json_aux.cpp
Normal file
0
3rdPart/include/meojson/json_aux.cpp
Normal file
97
3rdPart/include/meojson/json_aux.h
Normal file
97
3rdPart/include/meojson/json_aux.h
Normal file
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "json_value.h"
|
||||
|
||||
namespace json
|
||||
{
|
||||
static std::string unescape_string(std::string&& str)
|
||||
{
|
||||
std::string replace_str;
|
||||
std::string escape_str = std::move(str);
|
||||
|
||||
for (size_t pos = 0; pos < escape_str.size(); ++pos)
|
||||
{
|
||||
switch (escape_str[pos]) {
|
||||
case '\"':
|
||||
replace_str = R"(\")";
|
||||
break;
|
||||
case '\\':
|
||||
replace_str = R"(\\)";
|
||||
break;
|
||||
case '\b':
|
||||
replace_str = R"(\b)";
|
||||
break;
|
||||
case '\f':
|
||||
replace_str = R"(\f)";
|
||||
break;
|
||||
case '\n':
|
||||
replace_str = R"(\n)";
|
||||
break;
|
||||
case '\r':
|
||||
replace_str = R"(\r)";
|
||||
break;
|
||||
case '\t':
|
||||
replace_str = R"(\t)";
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
escape_str.replace(pos, 1, replace_str);
|
||||
++pos;
|
||||
}
|
||||
return escape_str;
|
||||
}
|
||||
|
||||
static std::string unescape_string(const std::string& str)
|
||||
{
|
||||
return unescape_string(std::string(str));
|
||||
}
|
||||
|
||||
static std::string escape_string(std::string&& str)
|
||||
{
|
||||
std::string escape_str = std::move(str);
|
||||
|
||||
for (size_t pos = 0; pos + 1 < escape_str.size(); ++pos)
|
||||
{
|
||||
if (escape_str[pos] != '\\') {
|
||||
continue;
|
||||
}
|
||||
std::string replace_str;
|
||||
switch (escape_str[pos+1]) {
|
||||
case '"':
|
||||
replace_str = "\"";
|
||||
break;
|
||||
case '\\':
|
||||
replace_str = "\\";
|
||||
break;
|
||||
case 'b':
|
||||
replace_str = "\b";
|
||||
break;
|
||||
case 'f':
|
||||
replace_str = "\f";
|
||||
break;
|
||||
case 'n':
|
||||
replace_str = "\n";
|
||||
break;
|
||||
case 'r':
|
||||
replace_str = "\r";
|
||||
break;
|
||||
case 't':
|
||||
replace_str = "\r";
|
||||
break;
|
||||
default:
|
||||
return std::string();
|
||||
break;
|
||||
}
|
||||
escape_str.replace(pos, 2, replace_str);
|
||||
}
|
||||
return escape_str;
|
||||
}
|
||||
|
||||
static std::string escape_string(const std::string& str)
|
||||
{
|
||||
return escape_string(std::string(str));
|
||||
}
|
||||
}
|
||||
@@ -9,16 +9,16 @@ namespace json
|
||||
{
|
||||
public:
|
||||
exception() = default;
|
||||
exception(const std::string &msg);
|
||||
exception(const std::string& msg);
|
||||
|
||||
exception(const exception &) = default;
|
||||
exception &operator=(const exception &) = default;
|
||||
exception(exception &&) = default;
|
||||
exception &operator=(exception &&) = default;
|
||||
exception(const exception&) = default;
|
||||
exception& operator=(const exception&) = default;
|
||||
exception(exception&&) = default;
|
||||
exception& operator=(exception&&) = default;
|
||||
|
||||
virtual ~exception() noexcept override = default;
|
||||
|
||||
virtual const char *what() const noexcept override;
|
||||
virtual const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
std::string m_msg;
|
||||
|
||||
@@ -15,12 +15,12 @@ namespace json
|
||||
public:
|
||||
~parser() noexcept = default;
|
||||
|
||||
static std::optional<value> parse(const std::string &content);
|
||||
static std::optional<value> parse(const std::string& content);
|
||||
|
||||
private:
|
||||
parser(
|
||||
const std::string::const_iterator &cbegin,
|
||||
const std::string::const_iterator &cend) noexcept
|
||||
const std::string::const_iterator& cbegin,
|
||||
const std::string::const_iterator& cend) noexcept
|
||||
: _cur(cbegin), _end(cend) {}
|
||||
|
||||
std::optional<value> parse();
|
||||
@@ -44,4 +44,7 @@ namespace json
|
||||
std::string::const_iterator _cur;
|
||||
std::string::const_iterator _end;
|
||||
};
|
||||
|
||||
std::optional<value> parse(const std::string& content);
|
||||
|
||||
} // namespace json
|
||||
@@ -29,8 +29,8 @@ namespace json
|
||||
|
||||
public:
|
||||
value();
|
||||
value(const value &rhs);
|
||||
value(value &&rhs) noexcept;
|
||||
value(const value& rhs);
|
||||
value(value&& rhs) noexcept;
|
||||
|
||||
value(bool b);
|
||||
|
||||
@@ -44,24 +44,24 @@ namespace json
|
||||
value(double num);
|
||||
value(long double num);
|
||||
|
||||
value(const char *str);
|
||||
value(const std::string &str);
|
||||
value(std::string &&str);
|
||||
value(const char* str);
|
||||
value(const std::string& str);
|
||||
value(std::string&& str);
|
||||
|
||||
value(const array &arr);
|
||||
value(array &&arr);
|
||||
value(const array& arr);
|
||||
value(array&& arr);
|
||||
// value(std::initializer_list<value> init_list); // for array
|
||||
|
||||
value(const object &obj);
|
||||
value(object &&obj);
|
||||
value(const object& obj);
|
||||
value(object&& obj);
|
||||
// error: conversion from ‘<brace-enclosed initializer list>’ to ‘json::value’ is ambiguous
|
||||
// value(std::initializer_list<std::pair<std::string, value>> init_list); // for object
|
||||
|
||||
// Constructed from raw data
|
||||
template <typename... Args>
|
||||
value(value_type type, Args &&... args)
|
||||
value(value_type type, Args &&...args)
|
||||
: _type(type),
|
||||
_raw_data(std::forward<Args>(args)...)
|
||||
_raw_data(std::forward<Args>(args)...)
|
||||
{
|
||||
static_assert(
|
||||
std::is_constructible<std::string, Args...>::value,
|
||||
@@ -85,15 +85,17 @@ namespace json
|
||||
bool exist(const std::string& key) const;
|
||||
bool exist(size_t pos) const;
|
||||
value_type type() const noexcept { return _type; }
|
||||
const value &at(size_t pos) const;
|
||||
const value &at(const std::string &key) const;
|
||||
const value& at(size_t pos) const;
|
||||
const value& at(const std::string& key) const;
|
||||
|
||||
template<typename Type>
|
||||
decltype(auto) get(const std::string& key, Type default_value) const {
|
||||
template <typename Type>
|
||||
decltype(auto) get(const std::string& key, Type default_value) const
|
||||
{
|
||||
return is_object() ? as_object().get(key, default_value) : default_value;
|
||||
}
|
||||
template<typename Type>
|
||||
decltype(auto) get(size_t pos, Type default_value) const {
|
||||
template <typename Type>
|
||||
decltype(auto) get(size_t pos, Type default_value) const
|
||||
{
|
||||
return is_array() ? as_array().get(pos, default_value) : default_value;
|
||||
}
|
||||
|
||||
@@ -108,8 +110,8 @@ namespace json
|
||||
const double as_double() const;
|
||||
const long double as_long_double() const;
|
||||
const std::string as_string() const;
|
||||
const array & as_array() const;
|
||||
const object & as_object() const;
|
||||
const array& as_array() const;
|
||||
const object& as_object() const;
|
||||
|
||||
array& as_array();
|
||||
object& as_object();
|
||||
@@ -118,13 +120,13 @@ namespace json
|
||||
const std::string to_string() const;
|
||||
const std::string format(std::string shift_str = " ", size_t basic_shift_count = 0) const;
|
||||
|
||||
value &operator=(const value &rhs);
|
||||
value &operator=(value &&) noexcept;
|
||||
value& operator=(const value& rhs);
|
||||
value& operator=(value&&) noexcept;
|
||||
|
||||
const value &operator[](size_t pos) const;
|
||||
value &operator[](size_t pos);
|
||||
value &operator[](const std::string &key);
|
||||
value &operator[](std::string &&key);
|
||||
const value& operator[](size_t pos) const;
|
||||
value& operator[](size_t pos);
|
||||
value& operator[](const std::string& key);
|
||||
value& operator[](std::string&& key);
|
||||
//explicit operator bool() const noexcept { return valid(); }
|
||||
|
||||
explicit operator bool() const { return as_boolean(); }
|
||||
@@ -140,7 +142,7 @@ namespace json
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
static std::unique_ptr<T> copy_unique_ptr(const std::unique_ptr<T> &t)
|
||||
static std::unique_ptr<T> copy_unique_ptr(const std::unique_ptr<T>& t)
|
||||
{
|
||||
return t == nullptr ? nullptr : std::make_unique<T>(*t);
|
||||
}
|
||||
@@ -152,7 +154,7 @@ namespace json
|
||||
};
|
||||
|
||||
const value invalid_value();
|
||||
std::ostream &operator<<(std::ostream &out, const value &val);
|
||||
std::ostream& operator<<(std::ostream& out, const value& val);
|
||||
// std::istream &operator>>(std::istream &in, value &val);
|
||||
|
||||
} // namespace json
|
||||
@@ -250,8 +250,8 @@ bool asst::Configer::_load(const std::string& filename)
|
||||
}
|
||||
if (emulator_json.exist("adb")) {
|
||||
emulator_info.is_adb = true;
|
||||
// meojson的bug,暂时没空修,先转个字符串
|
||||
emulator_info.adb.path = StringReplaceAll(emulator_json["adb"]["path"].as_string(), "\\\\", "\\");
|
||||
std::cout << emulator_json.to_string() << std::endl;
|
||||
emulator_info.adb.path = emulator_json["adb"]["path"].as_string();
|
||||
emulator_info.adb.connect = emulator_json["adb"]["connect"].as_string();
|
||||
emulator_info.adb.click = emulator_json["adb"]["click"].as_string();
|
||||
emulator_info.adb.display = emulator_json["adb"]["display"].as_string();
|
||||
|
||||
@@ -118,7 +118,7 @@ bool AbstractTask::print_window(const std::string& dir)
|
||||
bool ret = cv::imwrite(filename.c_str(), image(rect));
|
||||
|
||||
json::value callback_json;
|
||||
callback_json["filename"] = StringReplaceAll(filename, "\\", "\\\\");
|
||||
callback_json["filename"] = filename;
|
||||
callback_json["ret"] = ret;
|
||||
callback_json["offset"] = offset;
|
||||
m_callback(AsstMsg::PrintWindow, callback_json, m_callback_arg);
|
||||
|
||||
@@ -100,7 +100,7 @@ bool WinMacro::findHandle()
|
||||
std::string connect_cmd = adb_dir + m_emulator_info.adb.connect;
|
||||
|
||||
if (!callCmd(connect_cmd)) {
|
||||
DebugTraceError("Connect Adb Error");
|
||||
DebugTraceError("Connect Adb Error", connect_cmd);
|
||||
return false;
|
||||
}
|
||||
auto&& display_ret = callCmd(adb_dir + m_emulator_info.adb.display);
|
||||
|
||||
@@ -169,35 +169,6 @@
|
||||
"xOffset": 1,
|
||||
"yOffset": 42
|
||||
},
|
||||
"MuMuAsst": {
|
||||
"window": [
|
||||
{
|
||||
"class": "Qt5QWindowIcon",
|
||||
"window": "明日方舟 - 星云引擎"
|
||||
}
|
||||
],
|
||||
"view": [
|
||||
{
|
||||
"class": "Qt5QWindowIcon",
|
||||
"window": "明日方舟 - 星云引擎"
|
||||
}
|
||||
],
|
||||
"control": [
|
||||
{
|
||||
"class": "Qt5QWindowIcon",
|
||||
"window": "明日方舟 - 星云引擎"
|
||||
}
|
||||
],
|
||||
"adb": {
|
||||
"path": "[EmulatorPath]..\\vmonitor\\bin\\adb_server.exe",
|
||||
"connect": " connect 127.0.0.1:7555",
|
||||
"click": " shell input tap [x] [y]",
|
||||
"display": " shell dumpsys window displays | grep init= | awk ' { print $3 } '",
|
||||
"displayRegex": "cur=%dx%d"
|
||||
},
|
||||
"xOffset": 0,
|
||||
"yOffset": 36
|
||||
},
|
||||
"MuMuEmulator": {
|
||||
"window": [
|
||||
{
|
||||
@@ -218,7 +189,7 @@
|
||||
}
|
||||
],
|
||||
"adb": {
|
||||
"path": "[EmulatorPath]..\\vmonitor\\bin\\adb_server.exe",
|
||||
"path": "[EmulatorPath]..\\\\vmonitor\\\\bin\\\\adb_server.exe",
|
||||
"connect": " connect 127.0.0.1:7555",
|
||||
"click": " shell input tap [x] [y]",
|
||||
"display": " shell dumpsys window displays | grep init= | awk ' { print $3 } '",
|
||||
@@ -455,8 +426,8 @@
|
||||
"next": [
|
||||
"VisitLimited",
|
||||
"VisitNext",
|
||||
"VisitNextOcr",
|
||||
"VisitNextBlack"
|
||||
"VisitNextBlack",
|
||||
"VisitNextOcr"
|
||||
]
|
||||
},
|
||||
"VisitNextOcr": {
|
||||
@@ -464,14 +435,15 @@
|
||||
"text": [ "访问下位" ],
|
||||
"type": "clickSelf",
|
||||
"maxTimes": 21,
|
||||
"rearDealy": 3000,
|
||||
"exceededNext": [
|
||||
"ReturnToMall"
|
||||
],
|
||||
"next": [
|
||||
"VisitLimited",
|
||||
"VisitNext",
|
||||
"VisitNextOcr",
|
||||
"VisitNextBlack"
|
||||
"VisitNextBlack",
|
||||
"VisitNextOcr"
|
||||
]
|
||||
},
|
||||
"ReturnToMall": {
|
||||
|
||||
Reference in New Issue
Block a user