swiftlang / swift-experimental-string-processing

An early experimental general-purpose pattern matching engine for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistance throwing behavior on String and Regex's xxMatch

Kyle-Ye opened this issue · comments

commented

https://forums.swift.org/t/inconsistance-throwing-behavior-on-string-and-regexs-xxmatch/58535

We have public func wholeMatch(in s: String) throws -> Regex<Output>.Match? method on Regex and public func wholeMatch<R>(of r: R) -> Regex<R.RegexOutput>.Match? where R : RegexComponent on String.

Their usage is something like the following and IMO they can exchange in some extend.

let regex = /Hello/
let input = "Hello world"

try regex.wholeMatch(in: input)
input.wholeMatch(of: regex) // The result is the same as the above

So my question is why one is marked as "throw" and the other is not. Should the throwing behavior be aligned?

Apologies if I missed something already discussed before.