Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Decode %hex encoded characters
name
code content
+ String { decodeHex { var new = String.new, stream = CollStream(this), ch, int; while { ch = stream.next; ch.notNil } { if(ch == $%) { ch = stream.next; if(ch.notNil) { int = ch.digit << 4; } { // If the string ends with %, then 'ch' after that is nil // so we can just append the % ^new.add($%); }; ch = stream.next; if(ch.notNil) { ch = (int + ch.digit).asAscii; } { // If we got this far, we know there was one (only one) char after % // so add them both ^new.add($%).add(this.last); }; }; new = new.add(ch); }; ^new } }
code description
A quick utility function for decoding UTF-8 characters in %hex codes (such as for web URLs). Save the code into a .sc file in your Extensions/ directory, recompile, and then: "%E5%A4%A7%E5%AE%B6%E5%A5%BD".decodeHex; -> 大家好 This probably works only for UTF-8. SC can save the individual bytes of Unicode characters into String objects, and the IDE will print UTF-8 code points correctly, but there is no way to switch the IDE to other Unicode variants.
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change