View the DQSD CVS repository here:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dqsd/

Update of /cvsroot/dqsd/dqsd
In directory usw-pr-cvs1:/tmp/cvs-serv13593

Modified Files:
        ChangeLog.txt defer_tools.js search.htm 
Log Message:
Added parseArgsEx and trimWhitespace functions for additional argument parsing 
capabilities (from Brent Beardsley)

Index: ChangeLog.txt
===================================================================
RCS file: /cvsroot/dqsd/dqsd/ChangeLog.txt,v
retrieving revision 1.160
retrieving revision 1.161
diff -C2 -d -r1.160 -r1.161
*** ChangeLog.txt       31 Oct 2002 17:36:02 -0000      1.160
--- ChangeLog.txt       1 Nov 2002 14:31:45 -0000       1.161
***************
*** 4,8 ****
  
  * Added "mozillacal" as an option for the defaultcal preference to bring up the 
Mozilla calendar (although it doesn't go to the selected date yet)
! * Moved the Computer and Reference searches into menu subcategories..  
  
  -- What's new for 3.1.4.4 beta (October 24, 2002)
--- 4,9 ----
  
  * Added "mozillacal" as an option for the defaultcal preference to bring up the 
Mozilla calendar (although it doesn't go to the selected date yet)
! * Moved the Computer and Reference searches into menu subcategories.
! * Added parseArgsEx and trimWhitespace functions for additional argument parsing 
capabilities (from Brent Beardsley)
  
  -- What's new for 3.1.4.4 beta (October 24, 2002)

Index: defer_tools.js
===================================================================
RCS file: /cvsroot/dqsd/dqsd/defer_tools.js,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** defer_tools.js      2 Oct 2002 13:09:50 -0000       1.20
--- defer_tools.js      1 Nov 2002 14:31:45 -0000       1.21
***************
*** 147,152 ****
  }
  
- // parseArgs (Neel Doshi - 03/31/2002)
- //
  // Used to parse standard switches (/foo or /foo:bar).  Takes the following 
parameters:
  //    q - string from the search function
--- 147,150 ----
***************
*** 210,213 ****
--- 208,295 ----
    q = args_array.join(' ');
    return { q:q, switches:switches, switch_val:switch_val };
+ }
+ 
+ /*
+  * parseArgsEx is similar to parseArgs except that
+  * it isn't split on spaces but instead the /
+  * This means that args.q will be the value before the
+  * first slash and the parameter value is everything after
+  * the arg name until the next slash.  Also the arg name
+  * and value are separated by a space not a : like parseArgs.
+  * This will also allow you to have spaces in the argument value
+  * as well.
+  * [Brent Beardsley - 10/31/2002]
+  */
+ function parseArgsEx(q, expectedSwitches, expandSwitches)
+ {
+   // In case the caller does not pass in a value
+   if (typeof expandSwitches == 'undefined')
+     expandSwitches = 1;
+ 
+   // In case the caller uses a delimited (;,<space>) string
+   if (typeof expectedSwitches[0] == 'undefined')
+     expectedSwitches = expectedSwitches.split( /[,;/\s]/ );
+ 
+   var switches = [];
+   var switch_val = [];
+   var args_array = q.split('/');
+   for (var i=0; i < args_array.length; i++)
+   {
+     var one_arg = trimWhitespace(args_array[i]);
+     if (one_arg == "") 
+     {
+       continue;
+     }
+     var argRegExp = /(\S+)(\s+(.*))?/g;
+     var reResult = argRegExp.exec(one_arg);
+     if (reResult == null || reResult[1] == "") 
+     {
+       continue;
+     }
+     var argName = reResult[1];
+     var argValue = trimWhitespace(reResult[2]);
+     var re_res_switch;
+ 
+     for (var j = 0; j < expectedSwitches.length && !re_res_switch; j++)
+     {
+       var expect_regex = new RegExp(
+           '^(' + argName.replace('.', '\\.') +
+            ')' + (expandSwitches ? '' : '$'), 'i');
+ 
+       re_res_switch = expectedSwitches[j].match(expect_regex);
+ 
+       //  If there is a match, adjust the args_array, and save the values.
+       if (re_res_switch) 
+       {
+         argName = expectedSwitches[j];
+         switch_val[argName] = argValue;
+         switches.push( {name:argName.toLowerCase(), value:argValue} );
+       }
+     }
+     re_res_switch = "";
+   }
+ 
+   if (q.match(/^\s*\//))
+   {
+     // if it starts with a slash there are no non-switch values
+     q = "";
+   } 
+   else 
+   {
+     // only the part before the first slash is returned in args.q
+     var firstSlash = q.indexOf('/');
+     if (firstSlash != -1) 
+     {
+       q = q.substring(0, firstSlash);
+     }
+     q = trimWhitespace(q);
+   }
+   return { q:q, switches:switches, switch_val:switch_val };
+ }
+ 
+ 
+ function trimWhitespace( s )
+ {
+   return s.replace(/^\s+/, "").replace(/\s+$/, "");
  }
  

Index: search.htm
===================================================================
RCS file: /cvsroot/dqsd/dqsd/search.htm,v
retrieving revision 1.162
retrieving revision 1.163
diff -C2 -d -r1.162 -r1.163
*** search.htm  22 Oct 2002 06:23:56 -0000      1.162
--- search.htm  1 Nov 2002 14:31:45 -0000       1.163
***************
*** 312,316 ****
        if (fname.match(/\(.*\)/)) {
          // function with parameters specified
!         eval(fname); 
        } else {
          // just function no parameters
--- 312,316 ----
        if (fname.match(/\(.*\)/)) {
          // function with parameters specified
!         eval(fname);
        } else {
          // just function no parameters
***************
*** 330,335 ****
  {
    var fn = (alias ? alias : text);
!   var search = (fn + ' ' + document.deff.q.value).replace( /^\s*(\S+)\s*$/, "$1" ); 
// trim leading/trailing whitespace
!   if (searches[fn]) 
      addhist( search );
    performsearch( text, document.deff.q.value );
--- 330,335 ----
  {
    var fn = (alias ? alias : text);
!   var search = (fn + ' ' + document.deff.q.value).trimWhitespace( /^\s*(\S+)\s*$/, 
"$1" ); // trim leading/trailing whitespace
!   if (searches[fn])
      addhist( search );
    performsearch( text, document.deff.q.value );




-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm 
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
DQSD-CVS mailing list
https://lists.sourceforge.net/lists/listinfo/dqsd-cvs
DQSD CVS repository:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dqsd/

Reply via email to