aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string
Commit message (Collapse)AuthorAgeFilesLines
* drastically reduce object allocationsAaron Patterson2014-06-021-6/+13
| | | | | | | | | | before this change, we were allocating AS::SafeBuffer objects that were being interpolated in to a string, so the safe buffer object was being thrown away. This change only allocates a string (vs a string *and* a safebuffer) and interpolates the string. On my test application, this reduced the AS::SafeBuffer objects from 1527k per request to about 500 per request.
* reduce AS::SafeBuffer allocationsAaron Patterson2014-06-021-1/+2
| | | | | | | | | | | | html_escape_interpolated_argument is only used in mutation methods: https://github.com/rails/rails/blob/c07d09559ec171e1904b55c7ad7e8c7d586ca51b/activesupport/lib/active_support/core_ext/string/output_safety.rb#L174 https://github.com/rails/rails/blob/c07d09559ec171e1904b55c7ad7e8c7d586ca51b/activesupport/lib/active_support/core_ext/string/output_safety.rb#L179 The return value doesn't need to be converted to an AS::SafeBuffer since we know that the current object is an AS::SafeBuffer and will be mutated, and the return value from html_escape_interpolated_argument will be thrown away
* concat is a hotspot (via AV#append=), so just directly define the methodsAaron Patterson2014-06-021-4/+6
|
* Fix inconsistent behavior from String#pluralizeKuldeep Aggarwal2014-04-191-1/+1
| | | | | | | | | | | Before: When calling String#pluralize with count=1 then it returned same string, but with count other than 1, returned new string. After: String#pluralize always return a new string. => Prevent mutation of a string inadvertently.
* Fix inconsistent behavior from String#first/#lastErnie Miller2014-04-181-4/+4
| | | | | | | While calling String#first or String#last with zero or a Fixnum < the string's length returns a new string, a Fixnum >= the string's length returns the string itself. This inconsistency can lead to inadvertent mutation of a string.
* Add more test case for #demodulize, Improve documentationAkshay Vishnoi2014-04-111-0/+2
|
* Move require to actual fileCarlos Antonio da Silva2014-04-021-0/+1
| | | | | Change to require all active_support/deprecation since that's the actual entry point for the deprecation methods.
* DRY AS::SafeBuffer a bit using existing helperPavel Pravosud2014-04-021-5/+1
|
* Make AS::SafeBuffer#prepend act like String#prependPavel Pravosud2014-03-311-6/+13
| | | | | | | Make `#prepend` method modify instance in-place and return self instead of just returning modified value. That is exactly what `#prepend!` method was doing previously, so it's deprecated from now on.
* Clarify behavior of json_escape, update examplesJon Jensen2014-01-091-12/+12
| | | | | | | | The behavior of json_escape was fixed in 2f1c5789, but the doc changes and example in that commit incorrectly indicated that the return value would be html-safe. Since quotation marks are preserved, the raw value is not safe to use in other contexts (specifically HTML attributes).
* Revert "Speedup String#to"Yves Senn2014-01-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 2ef1fb2c455ca53a0c1e1768f50824926ce28bd3. As described in PR #13627 this commit broke functionality when passing a negative Fixnum to the `String#to` method: ```ruby assert_equal "hell", s.to(-2) ``` Before the revert, this failed with: ``` 1) Failure: StringAccessTest#test_#to_with_negative_Fixnum,_position_is_counted_from_the_end [test/core_ext/string_ext_test.rb:275]: Expected: "hell" Actual: nil ``` This revert is to keep the functionality on `master` working. If there is another way to get the performance benefit and keep the documented functionality we can add that. /cc @amatsuda @carlosantoniodasilva
* Fixes interpolation on SafeBufferJulien Letessier2013-12-141-7/+12
| | | | | | | | | Interpolation was untested and did not work with hash arguments. Adds - support for interpolation with hash argument - tests for the above - tests for safe/unsafe interpolation
* Review json_escape docs [ci skip]Carlos Antonio da Silva2013-12-041-22/+22
|
* Also move html_esacpe regex to a constant (see 9d25af60)Godfrey Chan2013-12-041-1/+2
|
* Added \u2028 \u2029 to json_escapeGodfrey Chan2013-12-041-5/+7
|
* Use lower case letters in unicodes sequences to match the new encoder's outputGodfrey Chan2013-12-041-1/+1
|
* Fixed a long-standing bug in `json_escape` that strips quotation marksGodfrey Chan2013-12-041-12/+49
|
* Avoid generating more strings while iterating to create methodsCarlos Antonio da Silva2013-12-021-1/+1
| | | | | Use the already existing strings instead of creating a new one each time just to test if it responds to the methods.
* [ci skip] removed singulars section from classify docGreg Molnar2013-11-271-4/+0
|
* Change syntax format for example returned valuesPrem Sichanugrist2013-11-113-41/+41
| | | | | | | | | According to our guideline, we leave 1 space between `#` and `=>`, so we want `# =>` instead of `#=>`. Thanks to @fxn for the suggestion. [ci skip]
* Add +capitalize+ option to Inflector.humanizeclaudiob2013-11-061-5/+11
| | | | | | | So strings can be humanized without being capitalized: 'employee_salary'.humanize # => "Employee salary" 'employee_salary'.humanize(capitalize: false) # => "employee salary"
* Typo Fix[ci skip]Rashmi Yadav2013-08-141-3/+3
|
* Add String#remove(pattern) as a short-hand for the common pattern of ↵David Heinemeier Hansson2013-08-131-0/+10
| | | | String#gsub(pattern, '')
* Add missing requireAkira Matsuda2013-07-111-0/+1
|
* Better not mutate the given options HashAkira Matsuda2013-07-101-3/+3
|
* Speed up String#truncateAkira Matsuda2013-07-101-1/+1
| | | | | | | Benchmark: user system total real old 1.550000 0.040000 1.590000 ( 1.585866) new 1.250000 0.040000 1.290000 ( 1.287693)
* Speedup String#toAkira Matsuda2013-07-101-1/+1
| | | | | | | | Benchmark: 1000000.times { str.to(30) } user system total real old 0.490000 0.110000 0.600000 ( 0.607374) new 0.390000 0.000000 0.390000 ( 0.387306)
* Remove deprecated `String#encoding_aware?` Arun Agrawal2013-07-031-8/+0
| | | core extensions (`core_ext/string/encoding`).
* Revert "Merge pull request #10600 from aditya-kapoor/code_refactor"Rafael Mendonça França2013-05-151-9/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 8ce3c1e5dde9fb180813e4d89324db03da110b13, reversing changes made to f93da579ce7f77dbd58b9a2165861aee265b8c93. Reason: It slow down the running time. require "diffbench" load 'output_safety.rb' N = 10000 b = ActiveSupport::SafeBuffer.new("hello world") DiffBench.bm do report "capitalize in safe buffer" do N.times do b.capitalize end end end > git checkout 069ea45; diffbench bench.rb; diffbench bench.rb;diffbench bench.rb;diffbench bench.rb;diffbench bench.rb;diffbench bench.rb;diffbench bench.rb; Running benchmark with current working tree Checkout HEAD^ Running benchmark with HEAD^ Checkout to previous HEAD again user system total real ----------------------------------capitalize in safe buffer After patch: 0.010000 0.000000 0.010000 ( 0.009733) Before patch: 0.010000 0.000000 0.010000 ( 0.007702) Improvement: -26% Running benchmark with current working tree Checkout HEAD^ Running benchmark with HEAD^ Checkout to previous HEAD again user system total real ----------------------------------capitalize in safe buffer After patch: 0.010000 0.000000 0.010000 ( 0.009768) Before patch: 0.010000 0.000000 0.010000 ( 0.007896) Improvement: -24% Running benchmark with current working tree Checkout HEAD^ Running benchmark with HEAD^ Checkout to previous HEAD again user system total real ----------------------------------capitalize in safe buffer After patch: 0.010000 0.000000 0.010000 ( 0.009938) Before patch: 0.010000 0.000000 0.010000 ( 0.007768) Improvement: -28% Running benchmark with current working tree Checkout HEAD^ Running benchmark with HEAD^ Checkout to previous HEAD again user system total real ----------------------------------capitalize in safe buffer After patch: 0.010000 0.000000 0.010000 ( 0.010001) Before patch: 0.010000 0.000000 0.010000 ( 0.007873) Improvement: -27% Running benchmark with current working tree Checkout HEAD^ Running benchmark with HEAD^ Checkout to previous HEAD again user system total real ----------------------------------capitalize in safe buffer After patch: 0.010000 0.000000 0.010000 ( 0.009670) Before patch: 0.010000 0.000000 0.010000 ( 0.007800) Improvement: -24% Running benchmark with current working tree Checkout HEAD^ Running benchmark with HEAD^ Checkout to previous HEAD again user system total real ----------------------------------capitalize in safe buffer After patch: 0.010000 0.000000 0.010000 ( 0.009949) Before patch: 0.010000 0.000000 0.010000 ( 0.007752) Improvement: -28%
* Added a blank space and removed to_symaditya-kapoor2013-05-141-4/+5
|
* Removed Class Eval and used define_method instead for the SafeBufferaditya-kapoor2013-05-141-12/+9
|
* Changed spelling of Busines to Businessaditya-kapoor2013-05-081-1/+1
|
* document String#to_time exceptionVipul A M2013-05-021-0/+1
|
* Adjust for daylight savings in String#to_timeAndrew White2013-04-231-8/+6
| | | | | | | | | | | | | | | The changes in b79adc4323 had a bug where if the time in the String was in standard time but the current time was in daylight savings then the calculated adjustment was off by an hour. This commit fixes this and adds extra tests for the following: * time in string is standard time, current time is standard time * time in string is standard time, current time is daylight savings * time in string is daylight savings, current time is standard time * time in string is daylight savings, current time is daylight savings Fixes #10306.
* interpolate instead of string concatVipul A M2013-04-151-1/+1
|
* Corrected paramter to parameterCarson McDonald2013-04-131-1/+1
|
* Revert "Merge pull request #10158 from steveklabnik/issue_10125"Rafael Mendonça França2013-04-101-2/+2
| | | | | | | | This reverts commit fa3ef8e82ab2f96cf15ef9bc885b2468fad77621, reversing changes made to e0af93dd3a5eeee2e2a67b05f34afb66cc80c00b. Reason: Routes, Active Record and the rendering stack should not depend on the default locale
* Fix inflector to respect default locale.Nick Cox2013-04-101-2/+2
| | | | | | | | The inflector was made aware of locales in 7db0b073fec6bc3e6f213b58c76e7f43fcc2ab97, but it defaulted to :en. That should actually be our default locale instead. Fixes #10125
* `fast_xs` support has been removed. Use 'String#encode(xml: :attr)`.Aaron Patterson2013-04-051-18/+0
|
* fix some typos in ASVipul A M2013-03-301-1/+1
|
* Call String#gsub with Hash directlyAman Gupta2013-03-041-2/+2
|
* no need for \Z, \z is more conciseXavier Noria2013-01-281-1/+1
|
* Improve String#squish whitespaces matchingAntoine Lyset2013-01-221-2/+5
|
* Use `DateTime.parse` inside `String#to_datetime`Andrew White2013-01-211-8/+1
| | | | | | | | | | Use the standard library's `DateTime.parse` because it's marginally faster and supports partial date/time strings. Benchmark: user system total real old 3.980000 0.000000 3.980000 ( 3.987606) new 3.640000 0.010000 3.650000 ( 3.641342)
* Standardise the return value of `to_time`Andrew White2013-01-211-17/+27
| | | | | | | | | | | | | | | | | | | | | | This commit standardises the return value of `to_time` to an instance of `Time` in the local system timezone, matching the Ruby core and standard library behavior. The default form for `String#to_time` has been changed from :utc to :local but research seems to suggest the latter is the more common form. Also fix an edge condition with `String#to_time` where the string has a timezone offset in it and the mode is :local. e.g: # Before: >> "2000-01-01 00:00:00 -0500".to_time(:local) => 2000-01-01 05:00:00 -0500 # After: >> "2000-01-01 00:00:00 -0500".to_time(:local) => 2000-01-01 00:00:00 -0500 Closes #2453
* Better error message for String#to_dateKelly Stannard2013-01-041-5/+1
| | | | | | | | | | I did this because to_date gives a very unhelpful error message if you do not pass in a correct date. In the process I think this cleans up the code nicely and even better it tends to be slightly faster than the current implementation. Benchmark https://gist.github.com/4440875
* Merge pull request #8560 from u16suzu/masterRafael Mendonça França2012-12-201-2/+2
|\ | | | | | | | | | | | | Fix document for String#humanize Conflicts: activesupport/lib/active_support/core_ext/string/inflections.rb
| * Fix: documentation for String#humanizeYuichiro Suzuki2012-12-201-2/+2
| |
* | Deprecate obsolete Time to DateTime fallback methodsAndrew White2012-12-111-1/+1
| | | | | | | | | | | | | | The Time.time_with_datetime_fallback, Time.utc_time and Time.local_time methods were added to handle the limitations of Ruby's native Time implementation. Those limitations no longer apply so we are deprecating them in 4.0 and they will be removed in 4.1.
* | Add String#in_time_zone methodAndrew White2012-12-111-0/+13
| | | | | | | | | | | | This commit adds a convenience method for converting a string to an ActiveSupport::TimeWithZone instance using the configured Time.zone or another passed as an argument.