Timeline for answer to How do I decode HTML entities in Swift? by Martin R
Current License: CC BY-SA 4.0
Post Revisions
31 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 13, 2025 at 10:07 | history | edited | Martin R | CC BY-SA 4.0 |
Re-added code that got lost in the previous revision.
|
| Feb 13, 2025 at 7:10 | comment | added | Martin R | @Mac: You are right, I had missed that case. The updated code should work correctly, thanks for the feedback! | |
| Feb 13, 2025 at 7:09 | history | edited | Martin R | CC BY-SA 4.0 |
Fixed case where there is another & between the & and the ; as noted by user "Mac" in a comment. Removed old code for Swift 2 and 3.
|
| Feb 13, 2025 at 6:30 | comment | added | Mac |
There is a serious bug in this answer. It does not take into account the case where there is another & between the & and the ;, as in &aaa", and does not work correctly.
|
|
| Aug 3, 2021 at 10:24 | comment | added | Martin R |
@Erika: Numerical character entities like ‘ are all decoded correctly. The dictionary is only needed for named character entities like ".
|
|
| Aug 3, 2021 at 10:19 | comment | added | Erika Electra | ‘ and ’, from the original poster's example, aren't in this dictionary... | |
| Jun 2, 2021 at 13:35 | comment | added | Sanjeev Chavan | After months getting stuck on a issue, this finally helped, thanks much | |
| Nov 3, 2020 at 20:13 | comment | added | Andrei Z. | gist.github.com/x0rb0t/a6c190dbefdfedad71143ff7f8153588 Complete List from dev.w3.org/html5/html-author/charref | |
| May 14, 2018 at 3:17 | comment | added | mugx | Thanks, with this answer I solved my issues: I had serious performance problems using NSAttributedString. | |
| Feb 18, 2018 at 18:09 | comment | added | Martin R | @user1118321: Code updated, thanks for letting me know. | |
| Feb 18, 2018 at 18:06 | history | edited | Martin R | CC BY-SA 3.0 |
deleted 192 characters in body
|
| Feb 18, 2018 at 17:58 | history | edited | Martin R | CC BY-SA 3.0 |
Swift 4 update.
|
| Feb 18, 2018 at 0:19 | comment | added | user1118321 | This is a great answer. I did get some errors compiling it with Swift 4.1 in Xcode 9.2. They were easily fixed by the compiler's suggestions, but it might be worth updating one more time. | |
| S Feb 2, 2018 at 13:05 | history | suggested | Community Bot | CC BY-SA 3.0 |
The implementation for Swift 3 works in Swift 4 as well
|
| Feb 2, 2018 at 13:00 | review | Suggested edits | |||
| S Feb 2, 2018 at 13:05 | |||||
| Sep 6, 2016 at 8:37 | comment | added | Martin R |
@yishus: Thanks for fixing the error in the Swift 3 code! (Previously, I had used strtoul() which silently ignores trailing non-digits.)
|
|
| S Sep 6, 2016 at 8:33 | history | suggested | yishus | CC BY-SA 3.0 |
remove last semicolon before decoding
|
| Sep 6, 2016 at 8:17 | review | Suggested edits | |||
| S Sep 6, 2016 at 8:33 | |||||
| Aug 27, 2016 at 17:04 | history | edited | Martin R | CC BY-SA 3.0 |
Swift 3 update.
|
| Apr 28, 2016 at 20:33 | comment | added | Adela Chang | @MartinR I was actually referring to Santiago's version up above in pastebin. The first time I saw this answer was long ago, so I must have missed the fact that you updated it, but the errors I was referring to was in the pastebin version and not yours. :) | |
| Apr 15, 2016 at 18:02 | comment | added | Martin R | @AdelaChang: Actually I had converted my answer to Swift 2 already in September 2015. It still compiles without warnings with Swift 2.2/Xcode 7.3. Or are you referring to Michael's version? | |
| Apr 15, 2016 at 16:33 | comment | added | Adela Chang |
I converted this answer to be compatible with Swift 2 and dumped it in a CocoaPod called StringExtensionHTML for ease of use. Note that Santiago's Swift 2 version fixes the compile time errors, but taking out the strtooul(string, nil, base) entirely will cause the code not to work with numeric character entities and crash when it comes to an entity it doesn't recognize (instead of failing gracefully).
|
|
| Sep 21, 2015 at 14:12 | comment | added | Matti | This answer should be preferred and accepted over the accepted one. The accepted answer is impossible to be used for longer texts. | |
| Sep 18, 2015 at 5:07 | history | edited | Martin R | CC BY-SA 3.0 |
Swift 2 update.
|
| Sep 17, 2015 at 22:31 | review | Suggested edits | |||
| Sep 17, 2015 at 23:10 | |||||
| Sep 17, 2015 at 22:29 | comment | added | Santiago | @MichaelWaterfall and Martin this is magnific! works like a charm! I update the extension for Swift 2 pastebin.com/juHRJ6au Thanks! | |
| Aug 27, 2015 at 17:11 | comment | added | Michael Waterfall | This is brilliant, thanks Martin! Here's the extension with the full list of HTML entities: gist.github.com/mwaterfall/25b4a6a06dc3309d9555 I've also slightly adapted it to provide the distance offsets made by the replacements. This allows the correct adjustment of any string attributes or entities that might be affected by these replacements (Twitter entity indices for example). | |
| May 9, 2015 at 18:49 | history | edited | Martin R | CC BY-SA 3.0 |
deleted 1 character in body
|
| May 9, 2015 at 17:05 | history | edited | Martin R | CC BY-SA 3.0 |
added 97 characters in body
|
| May 9, 2015 at 15:27 | history | edited | Martin R | CC BY-SA 3.0 |
added 47 characters in body
|
| May 9, 2015 at 15:21 | history | answered | Martin R | CC BY-SA 3.0 |