/[ht-ajax]/join-strings.lisp
ViewVC logotype

Contents of /join-strings.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Fri Nov 14 21:17:43 2008 UTC (5 years, 5 months ago) by xlopez
File size: 983 byte(s)
Initial commit, version 0.0.7.
1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Base: 10 -*-
2
3 (in-package #:ht-ajax)
4
5 ;; Written by Riastradh ( http://mumble.net/~campbell/blog.txt )
6 ;; posted at http://paste.lisp.org/display/35412
7 ;; and placed in the public domain
8
9 (defun join-strings (string-list separator)
10 (if (null string-list)
11 ""
12 (let* ((separator-length (length separator))
13 (total-length
14 (reduce (lambda (left-length right-length)
15 (+ left-length separator-length right-length))
16 string-list
17 :key #'length))
18 (result (make-string total-length)))
19 (replace result (car string-list))
20 (let ((offset (length (car string-list))))
21 (dolist (string (cdr string-list))
22 (replace result separator :start1 offset)
23 (replace result string :start1 (+ offset separator-length))
24 (incf offset (+ separator-length (length string)))))
25 result)))

  ViewVC Help
Powered by ViewVC 1.1.5