, ... , R2. ! ! :
good-workaround: # {F0908080}
Rebol2, Rebol3. - .
, Unicode , -... , , ^ (7F), Rebol 2, 3. , , :
-: [# "^ (F0)" # "^ (90)" # "^ (80)" # "^ (80)" ]
... " UTF-8"...
, , 4 = length? terrible-workaround. Rebol2 , ! ! . , Rebol2 , , AS-BINARY AS-STRING. ( Rebol3, , !)
, 4, , , to integer!. , - , , . Rebol2:
>> to integer!
== 128
>> to binary!
==
R3 UTF-8, :
>> to integer!
== 128
>> to binary!
==
, , , , - , -. , , "" R2 , , "". R2:
>> to binary!
==
"03".: -/
, - Unicode R3, - :
mu-utf8:
utf8: rejoin [
. . , Rebol2.
: , , - , Rebol3:
utf8: rejoin [
, , , LINEAR B SYLLABLE B008 A. , , , - , , , , . , , .
:. , , :
safe-r2-char: charset [#"^(00)" - #"^(7F)"]
unsafe-r2-char: charset [#"^(80)" - #"^(FF)"]
hex-digit: charset [#"0" - #"9" #"A" - #"F" #"a" - #"f"]
r2-string-to-binary: func [
str [string!] /string /unescape /unsafe
/local result s e escape-rule unsafe-rule safe-rule rule
] [
result: copy either string [{}] [#{}]
escape-rule: [
"^^(" s: 2 hex-digit e: ")" (
append result debase/base copy/part s e 16
)
]
unsafe-rule: [
s: unsafe-r2-char (
append result to integer! first s
)
]
safe-rule: [
s: safe-r2-char (append result first s)
]
rule: compose/deep [
any [
(either unescape [[escape-rule |]] [])
safe-rule
(either unsafe [[| unsafe-rule]] [])
]
]
unless parse/all str rule [
print "Unsafe codepoints found in string! by r2-string-to-binary"
print "See http://stackoverflow.com/questions/15077974/"
print mold str
throw "Bad codepoint found by r2-string-to-binary"
]
result
]
to binary!, Rebol2, Rebol3. ( terrible-workaround.)