我希望能够使用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
load v
构建二进制文件不是很自然。http://curecode.org/中的两个链接非常棒。我会仔细阅读它们的。你的代码有一个小错误,还是我的版本不支持?在我的控制台中,代码`{%} -1 skip无法工作(脚本错误:值超出范围:-1)。我将其改为
to {%}`,然后它就可以工作了。最后,非常感谢您的格式化和重新组织。 - Wayne Cuifield=x123\abc%E4BA%BA
这样格式不正确的输入也会被接受。我会研究如何正确地向后跳过,但AND
将确保只有在百分号是紧接着的下一个位置而没有提前时才触发规则... - HostileFork says dont trust SE