]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/jslib.js
use home-made string hashset/map instead of js default
[irc/quakenet/qwebirc.git] / js / jslib.js
index 994bf419901aaf80947e1b49f54103b4b4b5f6c0..67a26ff1f7d5e534af81bd5950429d586bfa5a9f 100644 (file)
@@ -41,7 +41,7 @@ String.prototype.splitMax = function(by, max) {
 
 /* returns the arguments */
 qwebirc.util.parseURI = function(uri) {
-  var result = {}
+  var result = new QHash();
 
   var start = uri.indexOf('?');
   if(start == -1)
@@ -56,11 +56,11 @@ qwebirc.util.parseURI = function(uri) {
     if(r.length < 2)
       continue;
       
-    result[unescape(r[0])] = unescape(r[1]);
+    result.put(unescape(r[0]), unescape(r[1]));
   }
   
   return result;
-}
+};
 
 qwebirc.util.DaysOfWeek = {
   0: "Sun",
@@ -119,6 +119,32 @@ qwebirc.util.pad = function(x) {
 
 RegExp.escape = function(text) {
   return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+};
+
+RegExp.fromIRCPattern = function(t) {
+  /* escape everything but ? . and * */
+  var t = t.replace(/[-[\]{}()+,\\^$|#\s]/g, "\\$&");
+  t = t.split("");
+  var out = [];
+
+  /* now process the rest */
+  for(var i=0;i<t.length;i++) {
+    var c = t[i];
+    switch(c) {
+      case '.':
+        out.push("\\.");
+        break;
+      case '?':
+        out.push(".");
+        break;
+      case '*':
+        out.push(".*");
+        break;
+      default:
+        out.push(c);
+    }
+  }
+  return out.join("");
 }
 
 qwebirc.ui.insertAt = function(position, parent, element) {
@@ -244,18 +270,22 @@ qwebirc.util.createInput = function(type, parent, name, selected, id) {
     } else {
       id = "";
     }
-    r = $(document.createElement("<input type=\"" + type + "\"" + name + id + " " + (selected?" checked":"") + "/>"));
-  } else {    
-    r = new Element("input");
-    r.type = type;
-    if(name)
-      r.name = name;
-    if(id)
-      r.id = id;
-      
-    if(selected)
-      r.checked = true;
+    try {
+      return $(document.createElement("<input type=\"" + type + "\"" + name + id + " " + (selected?" checked":"") + "/>"));
+    } catch(e) {
+      /* fallthough, trying it the proper way... */
+    }
   }
+  
+  r = new Element("input");
+  r.type = type;
+  if(name)
+    r.name = name;
+  if(id)
+    r.id = id;
+      
+  if(selected)
+    r.checked = true;
     
   parent.appendChild(r);
   return r;