nancy.liao
2025-05-08 bf8143c649292042de87c0cef63e6cb3c523388f
libscpi/src/externinterface.cpp
@@ -82,52 +82,45 @@
    }
    static bool match_all_segments(const std::vector<std::string>& stringList,
                                   const std::vector<Segment>& vecSegment)
                                   const std::vector<Segment>& vecSegment) {
        size_t currentIndex = 0;
        for (const auto& segment : vecSegment)
    {
        int currentIndex = 0;
        for (size_t i = 0; i < vecSegment.size(); i++)
        {
            auto currentSegment = vecSegment[i];
            if (currentSegment.is_required) {
                for (const auto& option : currentSegment.options)
                {
                    //当索引index超过输入参数的词组大小 则表示命令不匹配
                    if(currentIndex >= stringList.size())
                    {
                        return false;
                    }
                    if (stringList[currentIndex] != option)
            if (segment.is_required)
                    {
                        return false;
                    } else {
                        currentIndex += 1;
                    }
                bool matched = false;
                for (const auto& option : segment.options)
                {
                    if (stringList[currentIndex] == option)
                    {
                        matched = true;
                    break;
                }
            }
            else if (currentSegment.is_variable)
            {
                if (stringList.size() == vecSegment.size())
                {
                    auto vecTempSegments = currentSegment.options;
                    for (const auto& option : vecTempSegments)
                    {
                        if (stringList[currentIndex] != option)
                if (!matched)
                        {
                            return false;
                        } else {
                            currentIndex += 1;
                        }
                        break;
                currentIndex++;
            }
            else if (segment.is_variable)
            {
                // 可变参数:直接跳过
                currentIndex++;
            } else
            {
                if (segment.options.empty() || stringList[currentIndex] != segment.options[0]) {
                    return false;
                }
                currentIndex++;
                    }
                }
            }
            else {
                currentIndex += 1;
            }
        }
        return true;
        return currentIndex == stringList.size();
    }
    static std::vector<Segment> extract_all_segments(const std::string& pattern)
@@ -339,9 +332,4 @@
    }
    return PatternParser::match_all_segments(inputList, segments) ? 1 : 0;
}
CPatternResult *GetInstance()
{
    return g_pattern_results;
}