From 4da73c630183e482e4ab2accef97ad54c6741bf4 Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Sat, 4 May 2024 10:04:41 -0700 Subject: Fix message board divider regular expression. New shared RegularExpressions. --- Hotline/Hotline/HotlineClient.swift | 4 ++-- Hotline/Utility/RegularExpressions.swift | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 Hotline/Utility/RegularExpressions.swift (limited to 'Hotline') diff --git a/Hotline/Hotline/HotlineClient.swift b/Hotline/Hotline/HotlineClient.swift index f0e5eea..15ba73f 100644 --- a/Hotline/Hotline/HotlineClient.swift +++ b/Hotline/Hotline/HotlineClient.swift @@ -1,5 +1,6 @@ import Foundation import Network +import RegexBuilder enum HotlineClientStatus: Int { case disconnected @@ -491,8 +492,7 @@ class HotlineClient: NetSocketDelegate { } var messages: [String] = [] - let messageBoardRegex = /([\s\r\n]*[_\-]+[\s\r\n]+)/ - let matches = text.matches(of: messageBoardRegex) + let matches = text.matches(of: RegularExpressions.messageBoardDivider) var start = text.startIndex if matches.count > 0 { diff --git a/Hotline/Utility/RegularExpressions.swift b/Hotline/Utility/RegularExpressions.swift new file mode 100644 index 0000000..0314dd7 --- /dev/null +++ b/Hotline/Utility/RegularExpressions.swift @@ -0,0 +1,23 @@ +import RegexBuilder + +struct RegularExpressions { + static let messageBoardDivider = Regex { + Capture { + OneOrMore { + CharacterClass(.newlineSequence) + } + ZeroOrMore { + CharacterClass(.whitespace, .newlineSequence) + } + Repeat(2...) { + CharacterClass(.anyOf("_-")) + } + ZeroOrMore { + CharacterClass(.whitespace) + } + OneOrMore { + CharacterClass(.newlineSequence) + } + } + } +} -- cgit