markdown2 :: HtmlRenderer :: encode_uri
uri
string
# Encode the `uri` string
fun encode_uri(uri: String): String do
var buf = new Buffer
var i = 0
while i < uri.length do
var c = uri.chars[i]
if (c >= '0' and c <= '9') or
(c >= 'a' and c <= 'z') or
(c >= 'A' and c <= 'Z') or
c == ';' or c == ',' or c == '/' or c == '?' or
c == ':' or c == '@' or c == '=' or c == '+' or
c == '$' or c == '-' or c == '_' or c == '.' or
c == '!' or c == '~' or c == '*' or c == '(' or
c == ')' or c == '#' or c == '\''
then
buf.add c
else if c == '&' then
buf.append "&"
else if c == '%' and uri.search_from(re_uri_code, i) != null then
buf.append uri.substring(i, 3)
i += 2
else
var bytes = c.to_s.bytes
for b in bytes do buf.append "%{b.to_i.to_hex}".to_upper
end
i += 1
end
return buf.to_s
end
lib/markdown2/markdown_html_rendering.nit:108,2--138,4