代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/drbd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 2beea682e7bd6b711e2e67ed05cda33e2fe6e4b1 Mon Sep 17 00:00:00 2001
From: Robert Altnoeder <robert.altnoeder@linbit.com>
Date: Thu, 8 Feb 2024 23:20:02 +0100
Subject: [PATCH 047/100] DRBDmon: Add string_matching module
---
user/drbdmon/Makefile.in | 1 +
user/drbdmon/string_matching.cpp | 91 ++++++++++++++++++++++++++++++++
user/drbdmon/string_matching.h | 37 +++++++++++++
3 files changed, 129 insertions(+)
create mode 100644 user/drbdmon/string_matching.cpp
create mode 100644 user/drbdmon/string_matching.h
diff --git a/user/drbdmon/Makefile.in b/user/drbdmon/Makefile.in
index 7bd8987e..3b2957c2 100644
--- a/user/drbdmon/Makefile.in
+++ b/user/drbdmon/Makefile.in
@@ -55,6 +55,7 @@ l-obj += configuration/CfgEntryStore.o configuration/CfgEntryBoolean.o configura
l-obj += configuration/CfgEntry.o configuration/Configuration.o configuration/IoException.o
l-obj += persistent_configuration.o
l-obj += StringTokenizer.o comparators.o utils.o exceptions.o integerfmt.o string_transformations.o
+l-obj += string_matching.o
ls-obj := drbdmon_main.o $(l-obj) $(dsaext-obj) $(integerparse-obj)
diff --git a/user/drbdmon/string_matching.cpp b/user/drbdmon/string_matching.cpp
new file mode 100644
index 00000000..4bd830aa
--- /dev/null
+++ b/user/drbdmon/string_matching.cpp
@@ -0,0 +1,91 @@
+#include <string_matching.h>
+
+namespace string_matching
+{
+ const uint16_t PATTERN_LIMIT = 20;
+
+ PatternItem::PatternItem(const std::string& init_text):
+ text(init_text)
+ {
+ }
+
+ PatternItem::~PatternItem() noexcept
+ {
+ }
+
+ PatternLimitException::PatternLimitException()
+ {
+ }
+
+ PatternLimitException::~PatternLimitException() noexcept
+ {
+ }
+
+ bool is_pattern(const std::string& pattern)
+ {
+ return pattern.find('*') != std::string::npos;
+ }
+
+ // @throws std::bad_alloc, PatternLimitException
+ void process_pattern(const std::string& pattern, std::unique_ptr<PatternItem>& pattern_list)
+ {
+ std::unique_ptr<PatternItem>* next_item = &pattern_list;
+
+ // Split pattern
+ size_t offset = 0;
+ size_t split_idx = 0;
+ uint16_t pattern_count = 0;
+ do
+ {
+ split_idx = pattern.find('*', offset);
+ size_t length = split_idx != std::string::npos ? split_idx - offset : pattern.length() - offset;
+ std::string fragment(pattern.substr(offset, length));
+ if (fragment.length() != 0 || offset == 0 || offset == pattern.length())
+ {
+ ++pattern_count;
+ if (pattern_count > PATTERN_LIMIT)
+ {
+ throw PatternLimitException();
+ }
+ (*next_item) = std::unique_ptr<PatternItem>(new PatternItem(fragment));
+ PatternItem* const current_item = (*next_item).get();
+ next_item = &(current_item->next);
+ }
+ if (split_idx != std::string::npos)
+ {
+ offset = split_idx + 1;
+ }
+ }
+ while (split_idx != std::string::npos);
+ }
+
+ bool match_text(const std::string& text, const PatternItem* const pattern_list)
+ {
+ bool matched = true;
+ const PatternItem* item = pattern_list;
+ if (item != nullptr)
+ {
+ size_t offset = 0;
+ bool anchor_start = true;
+ do
+ {
+ const PatternItem* const next_item = item->next.get();
+ const bool anchor_end = next_item == nullptr;
+ const size_t idx = anchor_end ? text.rfind(item->text) : text.find(item->text, offset);
+
+ matched = idx != std::string::npos &&
+ (!anchor_start || idx == 0) &&
+ (!anchor_end || idx == text.length() - item->text.length());
+
+ if (matched)
+ {
+ offset = idx + item->text.length();
+ anchor_start = false;
+ item = next_item;
+ }
+ }
+ while (matched && item != nullptr);
+ }
+ return matched;
+ }
+}
diff --git a/user/drbdmon/string_matching.h b/user/drbdmon/string_matching.h
new file mode 100644
index 00000000..9b3918fe
--- /dev/null
+++ b/user/drbdmon/string_matching.h
@@ -0,0 +1,37 @@
+#ifndef STRING_MATCHING_H
+#define STRING_MATCHING_H
+
+#include <string>
+#include <memory>
+#include <stdexcept>
+
+namespace string_matching
+{
+ extern const uint16_t PATTERN_LIMIT;
+
+ class PatternItem
+ {
+ public:
+ PatternItem(const std::string& init_text);
+ virtual ~PatternItem() noexcept;
+
+ std::string text;
+ std::unique_ptr<PatternItem> next;
+ };
+
+ class PatternLimitException : public std::exception
+ {
+ public:
+ PatternLimitException();
+ virtual ~PatternLimitException() noexcept;
+ };
+
+ bool is_pattern(const std::string& pattern);
+
+ // @throws std::bad_alloc, PatternLimitException
+ void process_pattern(const std::string& pattern, std::unique_ptr<PatternItem>& pattern_list);
+
+ bool match_text(const std::string& text, const PatternItem* const pattern_list);
+}
+
+#endif // STRING_MATCHING_H
--
2.33.1.windows.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。