std::string_view 的使用

This commit is contained in:
2026-06-29 09:40:55 +08:00
parent cd446b7ca8
commit 8daf67aa5d
52 changed files with 1420 additions and 1367 deletions
+6 -5
View File
@@ -4,13 +4,14 @@
#include <filesystem>
#include <iostream>
#include <string>
#include <string_view>
using namespace Psc;
int max_distance = 700;
namespace fs = std::filesystem;
class MY_File_Data_Source : public File_Data_Source {
public:
BaseLogger *logger{};
void pre_handle(const std::string &data) override {}
void pre_handle(std::string_view data) override {}
void handle_mode_s(std::string &packet) override {}
size_t line_num = 0;
size_t line_num_ex = 0;
@@ -42,7 +43,7 @@ public:
std::cout << "first:" << mem2hex(packet) << std::endl;
return;
}
std::string error_len =
std::string_view error_len =
key + " " + LOG_POS_SIMPLE + " mode_s_error_length";
auto type = packet[1];
if (type == Msg::AC) {
@@ -137,7 +138,7 @@ void handle(const fs::path &file_path, const fs::path &rel_path) {
Mode_S::parse_call_back = [&](Mode_S::Parse_Call_Back_Type type,
Aircraft_Info *aircraft_info,
const std::string &field_name_or_error_info,
std::string_view field_name_or_error_info,
std::vector<std::string> bds_list,
void *cur_parser, Mode_S::P_S mode_s_msg) {
if (type == Mode_S::Parse_Call_Back_Type::Normal_Block)
@@ -200,7 +201,7 @@ void list_directory(const fs::path &dir_path, const fs::path &base_path) {
}
}
}
std::wstring _transformString2Wstring(const std::string &s) {
std::wstring _transformString2Wstring(std::string_view s) {
setlocale(LC_CTYPE, "en_US.UTF-8");
const char *_Source = s.c_str();
size_t len = strlen(_Source) + 1;
@@ -211,7 +212,7 @@ std::wstring _transformString2Wstring(const std::string &s) {
delete[] wStr;
return result;
}
std::wstring gbk_to_wstring(const std::string &gbk) {
std::wstring gbk_to_wstring(std::string_view gbk) {
int len = MultiByteToWideChar(CP_ACP, 0, gbk.c_str(), -1, nullptr, 0);
std::wstring wstr(len, L'\0');
MultiByteToWideChar(CP_ACP, 0, gbk.c_str(), -1, &wstr[0], len);