| | |
| | | #include <sstream> |
| | | |
| | | CPatternResult* g_pattern_results = new (std::nothrow) CPatternResult(); |
| | | |
| | | int g_pattern_count = 0; |
| | | |
| | | //static std::vector<std::string_view> currentCommandGroup; |
| | | |
| | | static int currentIndex; |
| | | |
| | | class Segment { |
| | | public: |
| | |
| | | } |
| | | }; |
| | | |
| | | char* currentPattern() |
| | | { |
| | | return g_pattern_results[currentIndex].commandData; |
| | | } |
| | | // 全局管理函数实现 |
| | | void add_pattern_to_global(const std::vector<Segment>& segments) |
| | | void add_pattern_to_global(const char* pattern, const std::vector<Segment>& segments) |
| | | { |
| | | // 重新分配内存 |
| | | CPatternResult* new_results = new CPatternResult[g_pattern_count + 1]; |
| | |
| | | CPatternResult& new_item = new_results[g_pattern_count]; |
| | | new_item.segments_count = static_cast<int>(segments.size()); |
| | | new_item.segments = new CSegment[segments.size()]; |
| | | |
| | | for (size_t i = 0; i < segments.size(); ++i) |
| | | { |
| | | const auto& seg = segments[i]; |
| | |
| | | |
| | | int get_pattern_count() { return g_pattern_count; } |
| | | |
| | | |
| | | void clearCurrentGroup() |
| | | { |
| | | currentIndex = -1; |
| | | //currentCommandGroup.clear(); |
| | | } |
| | | void parse_pattern_global(const char* pattern) |
| | | { |
| | | auto segments = PatternParser::extract_all_segments(pattern); |
| | | add_pattern_to_global(segments); |
| | | add_pattern_to_global(pattern,segments); |
| | | } |
| | | |
| | | void setCurrentIndex(int index) |
| | | { |
| | | currentIndex = index; |
| | | } |
| | | |
| | | //pattern_index 匹配组的下标 |
| | | int match_segments_global(const char* input, int pattern_index) |
| | | { |
| | | if (pattern_index < 0 || pattern_index >= g_pattern_count) |