From 78e1c2908d3f387cfcfd28c08105b5ba588bd7d0 Mon Sep 17 00:00:00 2001
From: nancy.liao <huihui.liao@greentest.com.cn>
Date: 周二, 06 5月 2025 09:29:46 +0800
Subject: [PATCH] 修改了全局变量的单例化

---
 libscpi/inc/scpi/externinterface.h |    3 +++
 libscpi/src/externinterface.cpp    |   19 ++++++++-----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libscpi/inc/scpi/externinterface.h b/libscpi/inc/scpi/externinterface.h
index 03d1107..1d3b41f 100644
--- a/libscpi/inc/scpi/externinterface.h
+++ b/libscpi/inc/scpi/externinterface.h
@@ -22,11 +22,14 @@
     int segments_count;
 } CPatternResult;
 
+static CPatternResult *GetInstance();
 
 int match_segments_global(const char* input, int pattern_index);
 void parse_pattern_global(const char* pattern);
 int get_pattern_count();
 void clear_global_patterns();
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/libscpi/src/externinterface.cpp b/libscpi/src/externinterface.cpp
index 17e3621..222a863 100644
--- a/libscpi/src/externinterface.cpp
+++ b/libscpi/src/externinterface.cpp
@@ -3,9 +3,11 @@
 #include <string>
 #include <algorithm>
 #include <cstring>
+#include <iostream>
+#include <string>
+#include <sstream>
 
-// 鍏ㄥ眬鍙橀噺瀹氫箟
-CPatternResult* g_pattern_results = nullptr;
+CPatternResult* g_pattern_results = new (std::nothrow) CPatternResult();
 int g_pattern_count = 0;
 
 class Segment {
@@ -37,14 +39,12 @@
         while (end != std::string::npos)
         {
             std::string token = input.substr(start, end - start);
-            trim_whitespace(token);
             if (!token.empty()) result.push_back(token);
             start = end + 1;
             end = input.find('|', start);
         }
 
         std::string last_token = input.substr(start);
-        trim_whitespace(last_token);
         last_token = remove_colon(last_token);
         if (!last_token.empty()) result.push_back(last_token);
         return result;
@@ -147,8 +147,6 @@
                 if (end_pos == std::string::npos) break;
 
                 std::string content = pattern.substr(pos + 1, end_pos - pos - 1);
-                trim_whitespace(content);
-
                 Segment segment;
                 segment.is_variable = false;
                 segment.options = split_options(content);
@@ -170,7 +168,6 @@
                 if (end_pos == std::string::npos) break;
 
                 std::string content = pattern.substr(pos + 1, end_pos - pos - 1);
-                trim_whitespace(content);
 
                 Segment segment;
                 segment.variableSize += 1;
@@ -195,7 +192,6 @@
                 {
                     content = pattern.substr(pos);
                 }
-                trim_whitespace(content);
 
                 if (!content.empty())
                 {
@@ -204,8 +200,6 @@
                     while (end != std::string::npos)
                     {
                         std::string token = content.substr(start, end - start);
-                        trim_whitespace(token);
-
                         if (!token.empty())
                         {
                             Segment segment;
@@ -218,7 +212,6 @@
                         end = content.find(':', start);
                     }
                     std::string last_token = content.substr(start);
-                    trim_whitespace(last_token);
                     if (!last_token.empty())
                     {
                         Segment segment;
@@ -348,3 +341,7 @@
     return PatternParser::match_all_segments(inputList, segments) ? 1 : 0;
 }
 
+CPatternResult *GetInstance()
+{
+    return g_pattern_results;
+}

--
Gitblit v1.9.1