Rebol 编程/resolve
外观
< Rebol 编程
RESOLVE target source /only from /all
>> reword "$1 is $2." [1 "This" 2 "that"] == "This is that."
通过将源中的值设置到目标中来复制上下文。
RESOLVE 是一个函数值。
- target -- (类型: 对象端口)
- source -- (类型: 对象端口)
- /escape -- 选择您自己的转义字符(块模板没有转义)
- char -- 使用此转义字符(默认 $) (类型: 字符 任何字符串)
- /into -- 插入到缓冲区中(返回插入后的位置)
- output -- 缓冲区系列(修改后的) (类型: 任何字符串)
reword: make function! [[ {Substitutes values into a template string, returning a new string.} source [any-string!] "Template series (or string with escape sequences)" values [map! object! block!] {Pairs of values and replacements (will be call ed if functions)} /escape {Choose your own escape char (no escape for block templates)} char [char! any-string!] "Use this escape char (default $)" /into {Insert into a buffer instead (returns position after insert)} output [any-string!] "The buffer series (modified)" /local vals word a b c d ] [ output: any [output make source length? source] vals: make map! length? values foreach [w v] values [ unless string? :w [w: to string! :w] unless empty? w [poke vals w unless unset? :v [:v]] ] word: make block! 2 * length? vals foreach w vals [word: reduce/into [w '|] word] word: head remove back word escape: [c: word d: ( output: insert insert/part output a b vals/(copy/part c d) :b ) a:] char: to string! any [char "$"] either empty? char [ parse/all source [ a: any [b: [escape | skip]] to end (output: insert output a) ] ] [ parse/all source [ a: any [to char b: char [escape | none]] to end (output: insert output a) ] ] either into [output] [head output] ]]