[REBOL] String compose
From: d4marcus:dtek:chalmers:se at: 15-Mar-2001 22:54
As I was playing around with some webpage building scripts I'm currently
doing, I came up with something that I though could be useful to others as
well. Maybe something like this already exists - in any case feel free to
come up with improvements. As I'm going to use this myself I would be
grateful for any improvement.
REBOL [
Title: "String compose"
Date: 15-Mar-2001
Author: "Marcus Petersson"
File: %stringcompose.r
Version: 0.1
]
stringcompose!: make object! [
buffer: make block! 0
exec_start: "("
exec_end: ")"
rule: [any [rule_exec | rule_text]
copy string to end (append buffer string)]
rule_text: [copy string to exec_start
(append buffer string)]
rule_exec: [exec_start copy string to exec_end exec_end
(append buffer exec string)]
exec: func [series [series!]] [
if error? try [return do series] [
join exec_start [series exec_end]]]
set 'stringcompose func [
{Evaluates a string of expressions, only evaluating
executable parens, and returns a block.}
Text [String!]] [
clear buffer
parse/all Text rule
buffer]
]
; borrowed from Andrew Martin's HTML.r
ReString: func [Block [block!]] [
join "" reduce Block]
MailTo: func [eMail [email!] Link [string!] /Subject String [string!]] [
ReString [
join <a> [{ href=^"mailto:} eMail either Subject [
join "?subject=" String] [""] {^"}] Link </a>]]
; example
Marcus: [adress [d4marcus--dtek--chalmers--se]]
mail: func ['person string [any-type!]] [
mailto select get person 'adress either value? 'string [
string] [to-string person]]
recipients: "Rebol users"
text: {
Dear (recipients),
Now, this is nothing special at all, just a simple
example (but a good one). If you don't get the idea
maybe you should (mail Marcus "mail me")
and I'll explain it to you.}
print Restring stringcompose text
Marcus
------------------------------------
If you find that life spits on you
calm down and pretend it's raining