From 6f097e664285809a333c78eeea4ac9e5227eb0a5 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 15 Feb 2022 12:09:53 +0100 Subject: [PATCH] =?UTF-8?q?RegexMatcher.go=20:=20-=20Ajoute=20m=C3=A9thode?= =?UTF-8?q?=20CreateRegexMatcher,=20qui=20cr=C3=A9e=20une=20instance=20de?= =?UTF-8?q?=20RegexMatcher.go=20et=20compile=20le=20pattern.=20-=20Ajout?= =?UTF-8?q?=20d'un=20attribut=20matcher=20auquel=20est=20attribu=C3=A9=20l?= =?UTF-8?q?e=20retour=20de=20la=20compilation=20du=20pattern=20-=20Impl?= =?UTF-8?q?=C3=A9mentation=20m=C3=A9thode=20match,=20v=C3=A9rifie=20que=20?= =?UTF-8?q?la=20donn=C3=A9e=20re=C3=A7ue=20en=20param=C3=A8tre=20respecte?= =?UTF-8?q?=20le=20pattern=20compil=C3=A9=20et=20stock=C3=A9=20dans=20la?= =?UTF-8?q?=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/protocol/RegexMatcher.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 pkg/protocol/RegexMatcher.go diff --git a/pkg/protocol/RegexMatcher.go b/pkg/protocol/RegexMatcher.go new file mode 100644 index 0000000..e6a5d63 --- /dev/null +++ b/pkg/protocol/RegexMatcher.go @@ -0,0 +1,23 @@ +package protocol + +import "regexp" + +// CreateRegexMatcher Création d'une instance de RegexMatcher +func CreateRegexMatcher(pattern string) *RegexMatcher { + compile, err := regexp.Compile(pattern) + if err != nil { + return nil + } + + return &RegexMatcher{matcher: compile} +} + +// RegexMatcher Propose des méthodes relatives au matching de chaine de caractère +type RegexMatcher struct { + matcher *regexp.Regexp +} + +// match Permet de vérifier la validité d'une donnée affiliée à un protocole +func (m RegexMatcher) match(data string) bool { + return m.matcher.MatchString(data) +}