aboutsummaryrefslogtreecommitdiff
path: root/Hotline
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline')
-rw-r--r--Hotline/Hotline/HotlineClient.swift4
-rw-r--r--Hotline/Utility/RegularExpressions.swift23
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)
+ }
+ }
+ }
+}