Added String-Utilities sources instead of through ASDF
Tue Aug 8 08:56:06 PDT 2006 Daniel Dickison (danieldickison@gmail.com)
* Added String-Utilities sources instead of through ASDF
diff -rN -u old-c2ffi/Package.lisp new-c2ffi/Package.lisp
--- old-c2ffi/Package.lisp 2014-04-20 18:12:32.000000000 -0700
+++ new-c2ffi/Package.lisp 2014-04-20 18:12:32.000000000 -0700
@@ -1,3 +1,3 @@
(defpackage :c2ffi
(:shadowing-import-from :iterate :collect :collecting)
- (:use :cl :xmls :anaphora :cl-utilities :iterate :string-utilities))
+ (:use :cl :xmls :anaphora :cl-utilities :iterate))
diff -rN -u old-c2ffi/String-Utilities.lisp new-c2ffi/String-Utilities.lisp
--- old-c2ffi/String-Utilities.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-c2ffi/String-Utilities.lisp 2014-04-20 18:12:32.000000000 -0700
@@ -0,0 +1,41 @@
+(in-package :c2ffi)
+
+(defun string-replace (source from to &key all)
+ "Returns a new string where substrings of SOURCE that match FROM are replaced with TO. All arguments should be strings, case-sensitive."
+ (let* ((match (string-find source from)))
+ (if match
+ (let ((pre (subseq source 0 match))
+ (post (subseq source (+ match (length from)))))
+ (str+ pre to (if all
+ (string-replace post from to :all t)
+ post)))
+ source)))
+
+(defun string-find (source target
+ &key all (case-sensitive t)
+ (test (if case-sensitive #'string= #'string-equal)))
+ "Returns the index of SOURCE where the substring TARGET first appears. Arguments should be strings, case-sensitive. If ALL is true, then a list of all such indices is returned. This is currently a non-optimized implementation (TODO: replace with Boyer-moore algorithm)."
+ (loop
+ with target-length = (length target)
+ for i upto (- (length source) target-length)
+ if (funcall test (subseq source i (+ i target-length))
+ target)
+ if all
+ collect i
+ else
+ return i))
+
+(defun str+ (&rest strings)
+ "Returns a concatenation of every argument coerced into strings as by princ-to-string."
+ (reduce #'(lambda (combined str)
+ (concatenate 'string combined (princ-to-string str)))
+ strings
+ :initial-value ""))
+
+(defun list-to-delimited-string (strings &optional (delim ", "))
+ "Returns a string where each element of strings has been coerced into a string by princ-to-string and concatenated with delim between each item."
+ (reduce #'str+
+ (cdr (mapcan #'(lambda (str) (list delim str))
+ strings))
+ :initial-value ""))
+
diff -rN -u old-c2ffi/c2ffi.asd new-c2ffi/c2ffi.asd
--- old-c2ffi/c2ffi.asd 2014-04-20 18:12:32.000000000 -0700
+++ new-c2ffi/c2ffi.asd 2014-04-20 18:12:32.000000000 -0700
@@ -5,5 +5,6 @@
#-:ecl "uffi")
:components ((:file "Package")
(:file "Pathnames" :depends-on ("Package"))
- (:file "XML-Utilities" :depends-on ("Package"))
- (:file "C-to-FFI" :depends-on ("Pathnames" "Package" "XML-Utilities"))))
+ (:file "String-Utilities" :depends-on ("Package"))
+ (:file "XML-Utilities" :depends-on ("Package" "String-Utilities"))
+ (:file "C-to-FFI" :depends-on ("Pathnames" "Package" "XML-Utilities" "String-Utilities"))))