r9687: new routines
authorKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 24 Jun 2004 15:12:02 +0000 (15:12 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Thu, 24 Jun 2004 15:12:02 +0000 (15:12 +0000)
debian/changelog
macros.lisp
package.lisp
strings.lisp

index 96d7fad36f969e46041387cbdc49bef786d25448..3429a8d759ff4593eaa030cc24583d4cbc60b970 100644 (file)
@@ -1,3 +1,9 @@
+cl-kmrcl (1.75-1) unstable; urgency=low
+
+  * New upstream
+
+ -- Kevin M. Rosenberg <kmr@debian.org>  Thu, 24 Jun 2004 01:19:04 -0600
+
 cl-kmrcl (1.74-1) unstable; urgency=low
 
   * New upstream
index 1239eb46b6d7d7cce32b073edc15d0d53a23efe8..c83b3b64a19f9f9be26f9dd96daa9ed9213f6f6d 100644 (file)
      ,@body))
 
 
+(defmacro time-seconds (&body body)
+  (let ((t1 (gensym)))
+    `(let ((,t1 (get-internal-real-time)))
+       (values
+       (progn ,@body)
+       (coerce (/ (- (get-internal-real-time) ,t1)
+                  internal-time-units-per-second)
+               'double-float)))))
+  
 (defmacro time-iterations (n &body body)
   (let ((i (gensym))
        (count (gensym)))
index 042fc119c0a49ccc7e834300f8f0daab8d052fc6..8bb206b53063f45dd61042d8a97028a9160fe75f 100644 (file)
@@ -71,7 +71,8 @@
    #:shrink-vector
    #:collapse-whitespace
    #:string->list
-
+   #:trim-non-alphanumeric
+   
    ;; io.lisp
    #:indent-spaces
    #:indent-html-spaces
    
    ;; macros.lisp
    #:time-iterations
+   #:time-seconds
    #:in
    #:mean
    #:with-gensyms
index 4ef18f0134e586755ab1cb9177e82ff53ca11b10..533bf013a5c663fba805486f07927344f7f39afd 100644 (file)
@@ -604,7 +604,12 @@ for characters in a string"
 
 (defun split-alphanumeric-string (string)
   "Separates a string at any non-alphanumeric chararacter"
-  (flet ((is-sep (char) (non-alphanumericp char)))
+  (declare (simple-string string)
+          (optimize (speed 3) (safety 0)))
+  (flet ((is-sep (char) 
+          (declare (character char))
+          (and (non-alphanumericp char)
+               (not (char= #\_ char)))))
     (let ((tokens nil))
       (do* ((token-start
              (position-if-not #'is-sep string) 
@@ -619,6 +624,30 @@ for characters in a string"
         (push (subseq string token-start token-end) tokens)))))
 
 
+(defun trim-non-alphanumeric (word)
+  "Strip non-alphanumeric characters from beginning and end of a word."
+  (declare (simple-string word)
+          (optimize (speed 3) (safety 0) (size 0)))
+  (let* ((start 0)
+        (len (length word))
+        (end len))
+    (declare (fixnum start end len))
+    (do ((done nil))
+       ((or done (= start end)))
+      (if (alphanumericp (schar word start))
+         (setq done t)
+       (incf start)))
+    (when (> end start)
+      (do ((done nil))
+         ((or done (= start end)))
+       (if (alphanumericp (schar word (1- end)))
+           (setq done t)
+         (decf end))))
+    (if (or (plusp start) (/= len end))
+       (subseq word start end)
+      word)))
+
+         
 
 (defun collapse-whitespace (s)
   "Convert multiple whitespace characters to a single space character."