def self.dsub (text, dict, offset=nil)
text = text.to_s
j = text.index('}', offset || 0)
return text unless j
t = text[0, j]
i = t.rindex('${')
ii = t.rindex("\\${")
iii = t.rindex('{')
iii = nil if offset
return text unless i
return dsub(text, dict, j+1) if (iii) and (iii-1 > i)
return unescape(text) if (i) and (i != 0) and (ii == i-1)
key = text[i+2..j-1]
value = dict[key]
value = if value
value.to_s
else
dict.has_key?(key) ? 'false' : ''
end
pre = (i > 0) ? text[0..i-1] : ''
dsub("#{pre}#{value}#{text[j+1..-1]}", dict)
end