aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-10-07 20:59:03 +0200
committerMichael Koziarski <michael@koziarski.com>2008-10-07 21:01:43 +0200
commit5556db22c57294a9f4e2ee4e633834ec6a200242 (patch)
treef18e457538db1f72f06f39e8966335740448df67 /activesupport/lib
parenta4629e707d80a5769f7a71ca6ed9471015e14dc9 (diff)
downloadrails-5556db22c57294a9f4e2ee4e633834ec6a200242.tar.gz
rails-5556db22c57294a9f4e2ee4e633834ec6a200242.tar.bz2
rails-5556db22c57294a9f4e2ee4e633834ec6a200242.zip
Reduce memory usage slightly in String#parameterize
[#1034 state:committed]
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/inflector.rb14
1 files changed, 9 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index f1e7abf4aa..336b6db47f 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -259,11 +259,15 @@ module ActiveSupport
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
def parameterize(string, sep = '-')
re_sep = Regexp.escape(sep)
- transliterate(string).
- gsub(/[^a-z0-9\-_\+]+/i, sep). # Turn unwanted chars into the separator.
- squeeze(sep). # No more than one of the separator in a row.
- gsub(/^#{re_sep}|#{re_sep}$/i, ''). # Remove leading/trailing separator.
- downcase
+ # replace accented chars with ther ascii equivalents
+ parameterized_string = transliterate(string)
+ # Turn unwanted chars into the seperator
+ parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
+ # No more than one of the separator in a row.
+ parameterized_string.squeeze!(sep)
+ # Remove leading/trailing separator.
+ parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
+ parameterized_string.downcase
end