Modify ↓
Ticket #2279 (closed enhancement: fixed)
faster trim
| Reported by: | phpmyforum | Owned by: | flesler |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.4.3 |
| Component: | core | Version: | 1.4.2 |
| Keywords: | Cc: | phpmyforum | |
| Blocking: | Blocked by: |
Description
Maybe everyone had read this already... I think jQuery would really benefit from this:
http://blog.stevenlevithan.com/archives/faster-trim-javascript
Attachments
Change History
comment:3 Changed 5 years ago by flesler
I actually proposed one, and I think this trim12 is pretty much mine :)
comment:4 Changed 5 years ago by flesler
- need changed from Review to Patch
- Owner set to flesler
- Status changed from new to assigned
- Milestone changed from 1.2.3 to 1.3
comment:5 Changed 5 years ago by flesler
- Cc phpmyforum added
- need changed from Patch to Commit
I think I'll add this trim function. We need to do some tests to verify it's a good choice for most situations.
comment:6 Changed 4 years ago by john
After fixing #4037, .trim() is no longer used in jQuery core - FYI.
comment:21 Changed 3 years ago by john
- Status changed from assigned to closed
- Version changed from 1.2.2 to 1.4.2
- Resolution set to fixed
- Milestone changed from 1.3 to 1.4.3
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.


Seconded. Specifically, I'd suggest the following version, which is Steve's trim12 function with the null-value fix from bug 1395:
trim: function( text ) { var text = (text || "").replace(/^\s\s*/, ''), ws = /\s/, i = text.length; while ( ws.test(text.charAt(--i)) ){} return text.slice(0, i + 1); },