我想用 html 表单和 Rebol cgi 存储一些数据。我的表格如下所示:
<form action="test.cgi" method="post" >
Input:
<input type="text" name="field"/>
<input type="submit" value="Submit" />
</form>
但是对于像中文这样的 unicode 字符,我会得到带有百分号的数据的编码形式,例如%E4%BA%BA
.
(这是针对汉字“人”......它作为 Rebol 二进制文字的 UTF-8 形式是#{E4BABA}
)
系统中有没有可以直接解码的函数,或者现有的库? dehex
目前似乎没有涵盖这种情况。我目前正在通过删除百分号并构建相应的二进制文件来手动解码,如下所示:
data: to-string read system/ports/input
print data
;-- this prints "field=%E4%BA%BA"
k-v: parse data "="
print k-v
;-- this prints ["field" "%E4%BA%BA"]
v: append insert replace/all k-v/2 "%" "" "#{" "}"
print v
;-- This prints "#{E4BABA}" ... a string!, not binary!
;-- LOAD will help construct the corresponding binary
;-- then TO-STRING will decode that binary from UTF-8 to character codepoints
write %test.txt to-string load v