r8914: rework test suites
[clsql.git] / base / utils.lisp
index f123b4feccc885f0ab0ebc2e41b2a2ba01c480b4..3f9ad8a6348862c3dce8723b4cd5dee1d80db835 100644 (file)
       procstr)))
 
 
+(defun delimited-string-to-list (string &optional (separator #\space) 
+                                                 skip-terminal)
+  "Split a string with delimiter, from KMRCL."
+  (declare (optimize (speed 3) (safety 0) (space 0) (compilation-speed 0))
+          (type string string)
+          (type character separator))
+  (do* ((len (length string))
+       (output '())
+       (pos 0)
+       (end (position-char separator string pos len)
+            (position-char separator string pos len)))
+       ((null end)
+       (if (< pos len)
+           (push (subseq string pos) output)
+           (when (or (not skip-terminal) (zerop len))
+             (push "" output)))
+       (nreverse output))
+    (declare (type fixnum pos len)
+            (type (or null fixnum) end))
+    (push (subseq string pos end) output)
+    (setq pos (1+ end))))
+
+(defun string-to-list-connection-spec (str)
+  (let ((at-pos (position #\@ str)))
+    (cond
+      ((and at-pos (> (length str) at-pos))
+       ;; Connection spec is SQL*NET format
+       (append (delimited-string-to-list (subseq str 0 at-pos) #\/)
+              (list (subseq str (1+ at-pos)))))
+      (t
+       (delimited-string-to-list str #\/)))))