diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-04 10:04:41 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-04 10:04:41 -0700 |
| commit | 4da73c630183e482e4ab2accef97ad54c6741bf4 (patch) | |
| tree | 7532c0821b19d31278d1e1b2fb80483cc22a96c3 /Hotline | |
| parent | a03636046a86863a5149924bf5aaa249d8606395 (diff) | |
Fix message board divider regular expression. New shared RegularExpressions.
Diffstat (limited to 'Hotline')
| -rw-r--r-- | Hotline/Hotline/HotlineClient.swift | 4 | ||||
| -rw-r--r-- | Hotline/Utility/RegularExpressions.swift | 23 |
2 files changed, 25 insertions, 2 deletions
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) + } + } + } +} |