Permalink
Browse files

String.after returns empty string.

  • Loading branch information...
richcollins committed Jan 12, 2011
1 parent 72bf8ca commit eed215bdb2637ce84a6b6eb6ca021475fbb6eb05
Showing with 124 additions and 24 deletions.
  1. +10 −0 lib/Crux/Array.js
  2. +39 −0 lib/Crux/Random.js
  3. +35 −1 lib/Crux/String.js
  4. +2 −1 lib/Crux/index.txt
  5. +2 −2 lib/Vertex/Collector.js
  6. +2 −2 lib/Vertex/PCursor.js
  7. +4 −0 lib/Vertex/PDB.js
  8. +29 −17 lib/Vertex/Vertex.js
  9. +1 −1 tests/correctness/PDBTest.js
View
@@ -341,6 +341,16 @@ Array.prototype.setSlotsIfAbsent(
{
return this.filter.apply(this, arguments);
},
+
+ removeNulls: function()
+ {
+ return this.filter(function(e){ return e !== null });
+ },
+
+ removeUndefined: function()
+ {
+ return this.filter(function(e){ return e !== undefined });
+ },
detect: function(callback)
{
View
@@ -0,0 +1,39 @@
+Random = Proto.clone().newSlots({
+ protoType: "Random"
+}).setSlots({
+ base64Url: function(length)
+ {
+ if(!length)
+ {
+ length = 6;
+ }
+
+ var randChars = [];
+ var chars = this.BASE_64_CHARS;
+ for(var i = 0; i < length; i ++)
+ {
+ randChars.push(chars[Math.floor(Math.random()*chars.length)]);
+ }
+ return randChars.join("");
+ }
+});
+
+(function(){
+ var chars = [];
+ for(var i = "0".charCodeAt(); i <= ("9".charCodeAt()); i ++)
+ {
+ chars.push(String.fromCharCode(i));
+ }
+ for(var i = "a".charCodeAt(); i <= ("z".charCodeAt()); i ++)
+ {
+ chars.push(String.fromCharCode(i));
+ }
+ for(var i = "A".charCodeAt(); i <= ("Z".charCodeAt()); i ++)
+ {
+ chars.push(String.fromCharCode(i));
+ }
+ chars.push("-");
+ chars.push("_");
+
+ Random.BASE_64_CHARS = chars;
+}).call();
View
@@ -101,9 +101,29 @@ String.prototype.setSlotsIfAbsent(
after: function(aString)
{
var index = this.indexOf(aString);
- if(index == -1) return null;
+ if(index == -1) return "";
return this.slice(index + aString.length);
},
+
+ between: function(before, after)
+ {
+ var next = this.after(before);
+ if(next)
+ {
+ if(next.indexOf(after) == -1)
+ {
+ return "";
+ }
+ else
+ {
+ return next.before(after);
+ }
+ }
+ else
+ {
+ return "";
+ }
+ },
asUncapitalized: function()
{
@@ -192,5 +212,19 @@ String.prototype.setSlotsIfAbsent(
}
return characters;
+ },
+
+ htmlEscaped: function()
+ {
+ return this.replace(/&(?!\w+;)|["<>\\]/g, function(s) {
+ switch(s) {
+ case "&": return "&amp;";
+ case "\\": return "\\\\";
+ case '"': return '\"';
+ case "<": return "&lt;";
+ case ">": return "&gt;";
+ default: return s;
+ }
+ });
}
});
View
@@ -8,4 +8,5 @@ String
Number
Date
Delegator
-Profiler
+Profiler
+Random
View
@@ -193,7 +193,7 @@ Collector = Proto.clone().newSlots({
// still need to make this loop incremental
c.first()
- while (c.key() != null)
+ while (c.key())
{
//require('util').debug(" " + node.pid() + " " + c.key() + ": " + c.value());
this.addPidToBeMarked(c.value())
@@ -237,7 +237,7 @@ Collector = Proto.clone().newSlots({
this._pdb.commit()
//writeln("sweep count ", sweepCount);
- if (c.key() == null)
+ if (!c.key())
{
this.sweepEnd()
}
View
@@ -70,8 +70,8 @@ PCursor = Proto.clone().newSlots({
{
return null
}
-
- return k.after(this._prefix)
+
+ return k.after(this._prefix) || null; //handle ""
},
value: function()
View
@@ -99,6 +99,9 @@ PDB = Proto.clone().newSlots({
{
this.setIsOpen(true);
}
+/*
+this.show();
+*/
this.createRootPNodeIfNeeded();
this.collector().resetHighWaterMark();
@@ -259,6 +262,7 @@ PDB = Proto.clone().newSlots({
atPut: function(k, v)
{
+writeln("atPut(", k, ",", v, ")");
if (this._collector.isRunning())
{
// innefficient - we should avoid these extra string ops
View
@@ -189,27 +189,39 @@ if(elapsed > 1000)
function (s)
{
var s = s.after("at ");
- //writeln("s = ", s)
- if(s && s.contains("("))
+ if(s)
{
- var place = s.before(" (");
- var obj = place.before(".");
- var method = place.after(".");
- var rest = s.after(" (");
- var path = rest.before(":").pathComponents().last();
- var line = rest.after(":").before(":");
- //return { place: place.replace("\.", " "), path:path, line: line};
- if ({"events.js":true, "http.js":true, "net.js":true}[path] || method == "<anonymous>") return "";
- //return "<tr><td>" + path.before(".") + "</td><td>" + method + "&nbsp;&nbsp;</td><td align=right>" + path + "</td><td>" + line + "</td></tr>";
- var filePath = rest.before(":");
- filePath = "txmt://open/?url=file://" + filePath + "&line=" + line //"&column=" + column
-
- return "<tr onmouseover=\"style.backgroundColor='#ddd';\" onmouseout=\"style.backgroundColor='#fff';\" onclick=\"window.location = '" + filePath + "'\"><td align=right><font color=#999>" + line + "&nbsp;&nbsp;</td><td>" + path.before(".") + "&nbsp;&nbsp;</td><td>" + method + "&nbsp;&nbsp;</td></tr>";
+ if(s.contains("("))
+ {
+ var place = s.before(" (");
+ var rest = s.after(" (");
+ var filePath = rest.before(")").before(":");
+ }
+ else
+ {
+ var place = "";
+ var filePath = s.before(":");
+ }
+ if(filePath == "native")
+ {
+ return "<tr><td></td><td></td><td>" + place + "&nbsp;&nbsp;</td></tr>";
+ }
+ else
+ {
+ var fileName = filePath.pathComponents().last().before(".");
+ var line = s.between(":", ":");
+
+ var url = "txmt://open/?url=file://" + filePath + "&line=" + line //"&column=" + column
+ return "<tr onmouseover=\"style.backgroundColor='#ddd';style.cursor='pointer';\" onmouseout=\"style.backgroundColor='#fff';style.cursor='default';\" onclick=\"window.location = '" + url.htmlEscaped() + "'\"><td align=right><font color=#999>" + line + "&nbsp;&nbsp;</td><td>" + fileName.htmlEscaped() + "&nbsp;&nbsp;</td><td>" + place.after(".").htmlEscaped() + "&nbsp;&nbsp;</td></tr>";
+ }
+ }
+ else
+ {
+ return null;
}
- return "";
}
- );
+ ).removeNulls();
body = body + "<table cellspacing=0 border=0 cellpadding=2>" + calls.join("\n") + "</table>";
body = body + "</div>";
@@ -163,7 +163,7 @@ Tester = UnitTest.newSlots({
var c = root.mk("b");
c.first();
- assert(c.key() == null);
+ assert(!c.key());
}
}).clone().run()

0 comments on commit eed215b

Please sign in to comment.