-
Notifications
You must be signed in to change notification settings - Fork 855
Description
First...thank you for this library. I was experiencing an issue in which a large incoming event wasn't being passed to the appropriate on: handler. No error was thrown. After some investigation, I narrowed it down to regex operations that weren't outputting valid json, thus leading the NSJSONSerialization to fail. Here is an example of the regex, although it happens a few times within the library:
var mutMessage = RegexMutable(stringMessage)
let messageGroups = mutMessage["(\\d*)\\/?(\\w*)?,?(\\d*)?(\\[.*\\])?"].groups()
The end of the regex uses a . to match any character, but by default it does not match line separators. If the intent is to include them, SwiftRegex lets us set the option NSRegularExpressionOptions.DotMatchesLineSeparators. I attempted a pull request to do the following but it wasn't working for me:
var mutMessage = RegexMutable(stringMessage)
let messageGroups = mutMessage["(\\d*)\\/?(\\w*)?,?(\\d*)?(\\[.*\\])?",NSRegularExpressionOptions.DotMatchesLineSeparators].groups()
I must be missing something, I thought that subscript would work but it crashes for me. The following did work:
var mutMessage = RegexMutable(stringMessage)
var swiftRegex = SwiftRegex(target: mutMessage, pattern: "(\\d*)\\/?(\\w*)?,?(\\d*)?(.*)?", options: NSRegularExpressionOptions.DotMatchesLineSeparators);
let messageGroups = swiftRegex.groups()
Also, it could be helpful to include a warning when the event parsing fails. Thanks!