Closed GarthSnyder closed 6 years ago
Hi @GarthSnyder, what a great contribution. Love this PR, can't wait to merge. I've seen all other PRs too, awesome work! I'll merge them in the next couple of days and release a new version ASAP.
Thank you 🙏
You're a true politician, Nuno. :) Thanks, I appreciate the enthusiasm - hope the patches are useful.
Thanks for FeedKit! I'm using it in a podcasting app and it's been working like a champ. I have made a few of small tweaks that I'll upload as PRs. There's isn't really a general theme except perhaps that several of them have to do with Postel's law - they are adjustments to make out-of-compliance but sensible feeds less likely to fail parsing.
This first patch changes the implementation of XML vs. JSON determination, for a couple of reasons.
First, XML needn't be in UTF-8 encoding, and I have seen cases where String(data:encoding:) actually fails because of this. String(decoding:as:) is a more lenient conversion and in this context it doesn't matter if odd characters are not correctly converted.
Second, there's no reason to convert the entire data block. Profiling was showing that this could be quite expensive with large feeds. If the feed doesn't show up within 200 characters, there's something very strange going on.
Finally, instead of just trimming whitespace, this patch just defines clear sets of accept/reject/don't-care characters and acts on the first accept or reject character in the buffer.