From 0b871120efe0fbbd53dbc586751a05b729237889 Mon Sep 17 00:00:00 2001 From: MistEO Date: Sun, 25 Dec 2022 03:53:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=86=8D=E6=AC=A1=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E7=9A=84=E6=95=B0=E5=AD=97=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp | 7 ++++--- .../Vision/Miscellaneous/StageDropsImageAnalyzer.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp b/src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp index 03ddb88072..cf856ed3bd 100644 --- a/src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp +++ b/src/MaaCore/Vision/Miscellaneous/DepotImageAnalyzer.cpp @@ -320,12 +320,13 @@ int asst::DepotImageAnalyzer::match_quantity(const Rect& roi) digit_str.erase(m_pos, digit_str.size()); } + constexpr char Dot = '.'; if (digit_str.empty() || - !ranges::all_of(digit_str, [](const char& c) -> bool { return std::isdigit(c) || c == '.'; })) { + !ranges::all_of(digit_str, [](const char& c) -> bool { return std::isdigit(c) || c == Dot; })) { return 0; } - if (auto dot_pos = digit_str.find('.'); dot_pos != std::string::npos) { - if (dot_pos == 0 || dot_pos == digit_str.size() - 1) { + if (auto dot_pos = digit_str.find(Dot); dot_pos != std::string::npos) { + if (dot_pos == 0 || dot_pos == digit_str.size() - 1 || digit_str.find(Dot, dot_pos + 1) != std::string::npos) { return 0; } } diff --git a/src/MaaCore/Vision/Miscellaneous/StageDropsImageAnalyzer.cpp b/src/MaaCore/Vision/Miscellaneous/StageDropsImageAnalyzer.cpp index 69bad6eca2..a95ca36045 100644 --- a/src/MaaCore/Vision/Miscellaneous/StageDropsImageAnalyzer.cpp +++ b/src/MaaCore/Vision/Miscellaneous/StageDropsImageAnalyzer.cpp @@ -553,12 +553,13 @@ int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi, bool use_word digit_str.erase(k_pos, digit_str.size()); } + constexpr char Dot = '.'; if (digit_str.empty() || - !ranges::all_of(digit_str, [](const char& c) -> bool { return std::isdigit(c) || c == '.'; })) { + !ranges::all_of(digit_str, [](const char& c) -> bool { return std::isdigit(c) || c == Dot; })) { return 0; } - if (auto dot_pos = digit_str.find('.'); dot_pos != std::string::npos) { - if (dot_pos == 0 || dot_pos == digit_str.size() - 1) { + if (auto dot_pos = digit_str.find(Dot); dot_pos != std::string::npos) { + if (dot_pos == 0 || dot_pos == digit_str.size() - 1 || digit_str.find(Dot, dot_pos + 1) != std::string::npos) { return 0; } }