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
-
Kit Goncharov July 17th, 2009 @ 09:49 PM
- State changed from new to open
-
Joe Gornick October 7th, 2009 @ 01:44 AM
- Milestone cleared.
- State changed from open to new
- Assigned user cleared.
-
John-David Dalton April 15th, 2010 @ 02:31 AM
- State changed from new to resolved
- Assigned user set to John-David Dalton
this is now in core http://github.com/jdalton/fusejs/commit/577c92459a33102627141a3e5a90a2e45dff3d70, I updated the CHANGELOG later to include kit in the credits.
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.
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.