full-text v. regular expression userid searches (was: Re: [svn] GnuPG - r3867 - trunk/keyserver)

Jason Harris jharris at widomaker.com
Sat Aug 20 14:13:32 CEST 2005


On Fri, Aug 19, 2005 at 10:55:06AM -0400, David Shaw wrote:
> On Fri, Aug 19, 2005 at 09:49:19AM -0400, Jason Harris wrote:

> > > Not that I'm suggesting regex searches.  I think they're overkill for
> > > the problem at hand.  Even LDAP doesn't do full regex.
> > 
> > Well, allowing "anchoring" of the (full-word) searches with ^ and $
> > sounds like it would be a good start,
> 
> Hard to do in a backwards compatible way, but at least it's not likely
> that people use ^ and $ at the beginning and end of their real user
> IDs.  Anyway, I can't say I think it's really necessary, but if SKS
> starts to support it, I'll add support for it in gpgkeys_hkp.

This applies after yminsky at cs.cornell.edu--2004/sks--mainline--1.0--patch-44,
Enjoy: 

--- orig/utils.ml
+++ mod/utils.ml
@@ -327,16 +327,13 @@
 
 let substring_find ~sub string = 
   try
-    for i = 0 to String.length string - String.length sub  do
-      try
-	for j = 0 to String.length sub - 1 do
-	  if string.[i+j] <> sub.[j] then raise Exit
-	done;
-	raise (Found i)
-      with
-	Exit -> ()
-    done;
-    -1
+    let string = String.lowercase string in
+    let sub = String.lowercase sub in
+    let re = Str.regexp sub in
+    try
+      let pos = Str.search_forward re string 0 in
+      raise (Found pos)
+    with Not_found -> raise (Found (-1))
+  -1
   with
-    Found i -> i
-      
+    Found pos -> pos

-- 
Jason Harris           |  NIC:  JH329, PGP:  This _is_ PGP-signed, isn't it?
jharris at widomaker.com _|_ web:  http://keyserver.kjsl.com/~jharris/
          Got photons?   (TM), (C) 2004
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 313 bytes
Desc: not available
Url : /pipermail/attachments/20050820/024b8636/attachment.pgp


More information about the Gnupg-devel mailing list