#46 ✓resolved
Kit Goncharov

Add Fuse.String#split

Reported by Kit Goncharov | July 17th, 2009 @ 09:23 PM

The native String#split method has several major bugs across all browsers (these are paraphrased from Steven Levithan's article; see http://blog.stevenlevithan.com/archives/cross-browser-split ):

  • IE & Safari 2-3 (and Konqueror) ignore RegExp capturing groups (example: 'a_b'.split(/(_)/) should return ["a", "_", "b"], instead, it returns ["a", "b"] in these buggy browsers).

  • Firefox ignores non-participating RegExp groups (see http://blog.stevenlevithan.com/archives/npcg-javascript ), and doesn't splice them into the resulting array as undefined

  • IE excludes empty values from the resulting array, but only for RegExes (strings work fine)

Steve goes on to implement a cross-browser solution to fix String#split, which I definitely think we could add to Fuse. However, his implementation uses RegExp decompilation (it breaks the separator RegExp down, then rebuilds it with an explicit g flag), which is extremely costly in all browsers.

Fuse.String#replace uses a RegExp's lastIndex property (instead of RegExp decompilation) to fix function replacement, and the code for fixing String#replace in Fuse and Steve's code for fixing String#split are not all that different. I was thinking of applying Steve's code for a Fuse.String#split implementation, but using a much faster lastIndex solution instead of decomp.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

JavaScript frameworks share similar features and functionality such as DOM manipulation, event registration, and CSS selector engines. FuseJS attempts to incorporate the strengths of these frameworks into one stable, efficient, and optimized core JavaScript framework.

People watching this ticket

Tags

Pages