Last change
on this file since 9540 was
9540,
checked in by mikel, 13 years ago
|
added more infrastructure for svn self-update, including some sequence utilities
|
File size:
1.5 KB
|
Line | |
---|
1 | ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: cl-user -*- |
---|
2 | ;;;; *********************************************************************** |
---|
3 | ;;;; FILE IDENTIFICATION |
---|
4 | ;;;; |
---|
5 | ;;;; Name: split-if.lisp |
---|
6 | ;;;; Version: 0.1 |
---|
7 | ;;;; Project: utilities |
---|
8 | ;;;; Purpose: utilities for splitting sequences |
---|
9 | ;;;; |
---|
10 | ;;;; *********************************************************************** |
---|
11 | |
---|
12 | (in-package "CCL") |
---|
13 | |
---|
14 | |
---|
15 | ;;; Split a sequence SEQ at each point where TEST is true |
---|
16 | ;;; DIR should be one of :BEFORE, :AFTER or :ELIDE |
---|
17 | |
---|
18 | (defun split-if (test seq &optional (dir :before)) |
---|
19 | (remove-if |
---|
20 | #'(lambda (x) (equal x (subseq seq 0 0))) |
---|
21 | (loop for start fixnum = 0 |
---|
22 | then (if (eq dir :before) stop (the fixnum (1+ (the fixnum stop)))) |
---|
23 | while (< start (length seq)) |
---|
24 | for stop = (position-if |
---|
25 | test seq |
---|
26 | :start (if (eq dir :elide) start (the fixnum (1+ start)))) |
---|
27 | collect (subseq |
---|
28 | seq start |
---|
29 | (if (and stop (eq dir :after)) |
---|
30 | (the fixnum (1+ (the fixnum stop))) |
---|
31 | stop)) |
---|
32 | while stop))) |
---|
33 | |
---|
34 | (defun split-if-char (char seq &optional dir) |
---|
35 | (split-if #'(lambda (ch) (eq ch char)) seq dir)) |
---|
36 | |
---|
37 | (defmethod split-lines ((text string)) |
---|
38 | (delete-if (lambda (x) (string= x "")) |
---|
39 | (mapcar (lambda (s) |
---|
40 | (string-trim '(#\return #\newline) s)) |
---|
41 | (split-if (lambda (c) (member c '(#\return #\newline) :test #'char=)) |
---|
42 | text)))) |
---|
Note: See
TracBrowser
for help on using the repository browser.