Created
July 7, 2016 23:38
-
-
Save greggirwin/cf03798e0a09f89907f943379e0bb704 to your computer and use it in GitHub Desktop.
Red invalid-utf8? function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
invalid-utf?: function [ | |
; https://robots.thoughtbot.com/fight-back-utf-8-invalid-byte-sequences | |
"Checks UTF encoding; if correct, returns none else position of error." | |
binary [binary!] | |
][ | |
bad: [ | |
#{C0} | #{C1} | #{F5} | #{F6} | #{F7} | #{F8} | #{F9} | #{FA} | |
| #{FB} | #{FC} | #{FD} | #{FE} | #{FF} | |
] | |
if parse binary [any [[mark: bad (return mark)] | skip]] [none] | |
] | |
invalid-utf? #{00000000} | |
invalid-utf? #{C100FF00} | |
invalid-utf? #{000000FF} | |
invalid-utf? #{00FF00F8} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment