Bug fixes

Fix broken UTF-8-BOM remover.
Fix Gist upload for Clash/ClashR.
Optimize codes.
This commit is contained in:
Tindy X committed 2019-12-21 21:10:26 +08:00
1 parent d31bdd9597
commit 889af53215
4 files changed
+19 -4

No files matched your search

+16 -1
View File
@@ -1,10 +1,14 @@
#ifndef INI_READER_H_INCLUDED #ifndef INI_READER_H_INCLUDED
#define INI_READER_H_INCLUDED #define INI_READER_H_INCLUDED
#include <string>
#include <sstream>
#include <map> #include <map>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include "misc.h"
typedef std::map<std::string, std::multimap<std::string, std::string>> ini_data_struct; typedef std::map<std::string, std::multimap<std::string, std::string>> ini_data_struct;
typedef std::multimap<std::string, std::string> string_multimap; typedef std::multimap<std::string, std::string> string_multimap;
typedef std::vector<std::string> string_array; typedef std::vector<std::string> string_array;
@@ -119,7 +123,8 @@ public:
return -1; return -1;
//remove UTF-8 BOM //remove UTF-8 BOM
removeUTF8BOM(content); if(content.compare(0, 3, "\xEF\xBB\xBF") == 0)
content = content.substr(3);
bool inExcludedSection = false; bool inExcludedSection = false;
std::string strLine, thisSection, curSection, itemName, itemVal; std::string strLine, thisSection, curSection, itemName, itemVal;
@@ -615,6 +620,16 @@ public:
return current_section.size() ? SetArray(current_section, itemName, separator, Array) : -1; return current_section.size() ? SetArray(current_section, itemName, separator, Array) : -1;
} }
int RenameSection(std::string oldName, std::string newName)
{
if(!SectionExist(oldName))
return -1;
auto nodeHandler = ini_content.extract(oldName);
nodeHandler.key() = newName;
ini_content.insert(std::move(nodeHandler));
return 0;
}
/** /**
* @brief Erase all items with the given name. * @brief Erase all items with the given name.
*/ */
+1 -1
View File
@@ -359,7 +359,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
output_content = netchToClash(nodes, base_content, rca, extra_group, target == "clashr", ext); output_content = netchToClash(nodes, base_content, rca, extra_group, target == "clashr", ext);
if(upload == "true") if(upload == "true")
uploadGist("clash", upload_path, output_content, false); uploadGist(target, upload_path, output_content, false);
return output_content; return output_content;
} }
else if(target == "surge") else if(target == "surge")
+1 -2
View File
@@ -825,8 +825,7 @@ bool is_str_utf8(std::string data)
void removeUTF8BOM(std::string &data) void removeUTF8BOM(std::string &data)
{ {
int BOM[3] = {0xef, 0xbb, 0xbf}; if(data.compare(0, 3, "\xEF\xBB\xBF") == 0)
if(data.compare(0, 3, (char*)BOM) == 0)
data = data.substr(3); data = data.substr(3);
} }
+1
View File
@@ -1545,6 +1545,7 @@ std::string netchToMellow(std::vector<nodeInfo> &nodes, std::string &base_conf,
} }
rulesetToSurge(ini, ruleset_content_array, 2); rulesetToSurge(ini, ruleset_content_array, 2);
ini.RenameSection("Rule", "RoutingRule");
return ini.ToString(); return ini.ToString();
} }