core :: Text :: to_percent_encoding
self
to percent (or URL) encodingassert "aBc09-._~".to_percent_encoding == "aBc09-._~"
assert "%()< >".to_percent_encoding == "%25%28%29%3c%20%3e"
assert ".com/post?e=asdf&f=123".to_percent_encoding == ".com%2fpost%3fe%3dasdf%26f%3d123"
assert "éあいう".to_percent_encoding == "%c3%a9%e3%81%82%e3%81%84%e3%81%86"
# Encode `self` to percent (or URL) encoding
#
# ~~~
# assert "aBc09-._~".to_percent_encoding == "aBc09-._~"
# assert "%()< >".to_percent_encoding == "%25%28%29%3c%20%3e"
# assert ".com/post?e=asdf&f=123".to_percent_encoding == ".com%2fpost%3fe%3dasdf%26f%3d123"
# assert "éあいう".to_percent_encoding == "%c3%a9%e3%81%82%e3%81%84%e3%81%86"
# ~~~
fun to_percent_encoding: String
do
var buf = new Buffer
for i in [0..length[ do
var c = 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 == '~'
then
buf.add c
else
var bytes = c.to_s.bytes
for b in bytes do buf.append "%{b.to_i.to_hex}"
end
end
return buf.to_s
end
lib/core/text/abstract_text.nit:895,2--923,4