On Mar 31, 4:44 pm, Nanyang Zhan <rails-mailing-l...@andreas-s.net>
wrote:
> Frederick Cheung wrote:
> > Those aren't playing with encodings which is apparently the issue
> > here. Why does it matter anyway?
>
> ok.
>
> Here is the source code of ERB::Util.url_encode(s) method.
> # File erb.rb, line 801
>     def url_encode(s)
>       s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X",
> $&.unpack("C")[0]) }
>     end
>
> now it works like this:
>
> > ERB::Util.url_encode("中文")
>
> > => "%E4%B8%AD%E6%96%87"
>
> Can you help me changing the url_encode code a bit, so it can return
> utf16 result? ( which '%D6%D0%CE%C4' is the one I want.)

well s.unpack("U*") will turn a string into a array of integers (utf
code points) that it should then be easy to split into bytes. I'd
start from scratch rather than using url_encode though.


Fred
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to