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.