I ranted and I raved and I tried and failed :-)

Unfortunately, my proposal to wreak havoc in the String class proved futile - it popped up bugs that I never seen before (among others CGI escaping and ERB broke, the latter in a rather intricate way). Outside of these two problems the solution worked on my applications though (but I would not recommend using it in production by now as all the implications become clear). Also the speed overhead proved very substantial. However, after some more tweaks I have come to the simple idea of having proxy access to the characters instead of subclassing. Maybe this can be useful for ActiveSupport (it is going to be able to address the more expensive routines only where characters are involved, and when Matz finally comes up with a good M17N engine - doh - it will be a matter of aliasing a method to self.

Works (in general) like this:

@some_unicode_string.u.length
@some_unicode_string.u.reverse

etc. with modifications to the string in-place where necessary.

Here is the test suite
http://julik.textdriven.com/svn/tools/rails_plugins/unicode_hacks/ test/t_string_overrides.rb

I think this can be refactored nicely into the string extensions in ActiveSupport, after that things like validates_length_of and truncate will be able to address the characters explicitly without resorting to regexen. And the users get a goot head start on Unicode in their apps from the get go.

It has an implicit dependency on the Unicode gem for normalization and capitalization, but that can be easily stubbed out to dummy methods and made optional (having, for example, an alert in the development log). Considering that Rails has some implicit dependencies all by itself I don't see that as too much burden, but this is my opinion of course.

I will gladly provide a patch shall the core find this something noteworthy.

--
Julian 'Julik' Tarkhanov
please send all personal mail to
me at julik.nl


_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to