scinfu / SwiftSoup

SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
https://scinfu.github.io/SwiftSoup/
MIT License
4.52k stars 345 forks source link

Requesting parse function that takes in Data instead of String #272

Open bjo0 opened 3 months ago

bjo0 commented 3 months ago

It would be convenient to have a version of the parse func that took in Data instead of String, as the conversion of Data to String involves transiting an Optional<String> function (String(data: encoding:)). This maybe looks superficially like not an inconvenience, but in practice it means I have to make my own error type in order to propagate failures at this step. If SwiftSoup did it and implemented the error type, it would improve ergonomics.

The function signature might be something like this:

func parse(data: Data) throws -> Document
aehlke commented 2 months ago

I will merge a PR for this if you want to implement it