[Laszlo-checkins] r11047 - in openlaszlo/trunk: WEB-INF/lps/lfc/kernel/swf lps/includes/source test
bargull@openlaszlo.org
bargull at openlaszlo.org
Wed Sep 17 10:14:52 PDT 2008
Author: bargull
Date: 2008-09-17 10:14:46 -0700 (Wed, 17 Sep 2008)
New Revision: 11047
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzRegExp.lzs
openlaszlo/trunk/lps/includes/source/regexp.js
openlaszlo/trunk/test/regexp.lzx
Log:
Change 20080916-bargull-ykY by bargull at dell--p4--2-53 on 2008-09-16 10:10:14
in /home/Admin/src/svn/openlaszlo/trunk
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: add RegExp support to split
New Features:
Bugs Fixed:
Technical Reviewer: max
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
Add implementation for RegExp to String.prototype.split
Tests:
Updated test/regexp.lzx
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzRegExp.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzRegExp.lzs 2008-09-17 17:12:57 UTC (rev 11046)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/kernel/swf/LzRegExp.lzs 2008-09-17 17:14:46 UTC (rev 11047)
@@ -229,4 +229,15 @@
String.prototype.search = function (re:*) :int {
if (!(re instanceof RegExp)) re = new RegExp(re + "");//coerce to string
return re.__call("lz.embed.regex.search", RegExp.__mask(this));
-}
\ No newline at end of file
+}
+
+String.prototype.__split = String.prototype.split;
+
+String.prototype.split = function (sep:*, limit:Number) :Array {
+ if (sep instanceof RegExp) {
+ return RegExp.__unmaskArr(sep.__call("lz.embed.regex.split", RegExp.__mask(this), limit));
+ } else {
+ // call shadowed
+ return String.prototype.__split.apply(this, arguments);
+ }
+}
Modified: openlaszlo/trunk/lps/includes/source/regexp.js
===================================================================
--- openlaszlo/trunk/lps/includes/source/regexp.js 2008-09-17 17:12:57 UTC (rev 11046)
+++ openlaszlo/trunk/lps/includes/source/regexp.js 2008-09-17 17:14:46 UTC (rev 11047)
@@ -56,6 +56,11 @@
var o = lz.embed.regex;
return o.unmask(s).search(o.cache[id]);
},
+ split:
+ function (id, s, limit) {
+ var o = lz.embed.regex;
+ return o.maskArr(o.unmask(s).split(o.cache[id], limit));
+ },
remove:
function (id) {
delete lz.embed.regex.cache[id];
Modified: openlaszlo/trunk/test/regexp.lzx
===================================================================
--- openlaszlo/trunk/test/regexp.lzx 2008-09-17 17:12:57 UTC (rev 11046)
+++ openlaszlo/trunk/test/regexp.lzx 2008-09-17 17:14:46 UTC (rev 11047)
@@ -8,6 +8,7 @@
this.addTest("testReplace");
this.addTest("testSearch");
this.addTest("testMatch");
+ this.addTest("testSplit");
this.addTest("testExec");
this.addTest("testTest");
this.addTest("testFlags");
@@ -51,6 +52,17 @@
assertTrue(equalArrays(["il sole"], src.match("il \\w+")));
]]></method>
+ <method name="testSplit" ><![CDATA[
+ //test shadowed String.prototype.split
+ assertTrue(equalArrays(["a", "b", "c"], "a;b;c".split(";")));
+ assertTrue(equalArrays(["", "a", "b", "c"], ";a;b;c".split(";")));
+
+ assertTrue(equalArrays(["a", "b", "c"], "a;b;c".split(new RegExp("[;]"))));
+ assertTrue(equalArrays(["a", "b", "c"], "a;b,c".split(new RegExp("[,;]"))));
+ assertTrue(equalArrays(["a", "b"], "a;b,c".split(new RegExp("[,;]"), 2)));
+ assertTrue(equalArrays(["10,0", "a", "b"], "10,0,a,b".split(new RegExp(",(?!\\d)"))));
+ ]]></method>
+
<method name="testExec" ><![CDATA[
var src = "The quick brown fox jumps over the lazy dog.";
var re = new RegExp("\\w+", "g");
@@ -69,7 +81,8 @@
}
assertEquals(0, re.lastIndex);
-
+ var splits =
+
assertTrue(equalArrays(["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"], words));
assertTrue(equalArrays([0, 4, 10, 16, 20, 26, 31, 35, 40], indices));
assertTrue(equalArrays([3, 9, 15, 19, 25, 30, 34, 39, 43], lastindices));
@@ -121,9 +134,16 @@
assertTrue(equalArrays(["b", ""], new RegExp("(a*)b\\1+").exec("baaaac")));
assertTrue(equalArrays(["", "aaa"], new RegExp("(?=(a+))").exec("baaabac")));
assertTrue(equalArrays(["aba", "a"], new RegExp("(?=(a+))a*b\\1").exec("baaabac")));
+ assertTrue(equalArrays(["a", "b"], "ab".split(new RegExp("a*?"))));
- // Internet Explorer doesn't even get the tests which are listed in the spec...
+ // Fails in Internet Explorer and Firefox, only Opera follows the spec (don't know about Safari?)
+ Debug.info("expected failure in IE and Firefox");
+ assertTrue(equalArrays(["A", void(0), "B", "bold", "/", "B", "and", void(0), "CODE", "coded", "/", "CODE", ""], "A<B>bold</B>and<CODE>coded</CODE>".split(new RegExp("<(/)?([^<>]+)>"))));
+
+ // Internet Explorer doesn't even get all tests which are listed in the spec...
Debug.info("expected failure in IE");
+ assertTrue(equalArrays(["", "b"], "ab".split(new RegExp("a*"))));
+ Debug.info("expected failure in IE");
assertTrue(equalArrays(["abc", "a", "a", void(0), "bc", void(0), "bc"], new RegExp("((a)|(ab))((c)|(bc))").exec("abc")));
Debug.info("expected failure in IE");
assertTrue(equalArrays(["zaacbbbcac", "z", "ac", "a", void(0), "c"], new RegExp("(z)((a+)?(b+)?(c))*").exec("zaacbbbcac")));
More information about the Laszlo-checkins
mailing list