| 1 |
;;;-*- Mode:Lisp; Syntax:Common-Lisp; Package:CHAOS -*- |
| 2 |
;;; |
| 3 |
;;; Copyright (c) 2000-2018, Toshimi Sawada. All rights reserved. |
| 4 |
;;; |
| 5 |
;;; Redistribution and use in source and binary forms, with or without |
| 6 |
;;; modification, are permitted provided that the following conditions |
| 7 |
;;; are met: |
| 8 |
;;; |
| 9 |
;;; * Redistributions of source code must retain the above copyright |
| 10 |
;;; notice, this list of conditions and the following disclaimer. |
| 11 |
;;; |
| 12 |
;;; * Redistributions in binary form must reproduce the above |
| 13 |
;;; copyright notice, this list of conditions and the following |
| 14 |
;;; disclaimer in the documentation and/or other materials |
| 15 |
;;; provided with the distribution. |
| 16 |
;;; |
| 17 |
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED |
| 18 |
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 19 |
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 21 |
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 |
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 23 |
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 |
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 |
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 |
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 |
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
;;; |
| 29 |
(in-package :CHAOS) |
| 30 |
#|============================================================================== |
| 31 |
System: Chaos |
| 32 |
Module: comlib |
| 33 |
File: string.lisp |
| 34 |
==============================================================================|# |
| 35 |
#-:chaos-debug |
| 36 |
(declaim (optimize (speed 3) (safety 0) #-GCL (debug 0))) |
| 37 |
#+:chaos-debug |
| 38 |
(declaim (optimize (speed 1) (safety 3) #-GCL (debug 3))) |
| 39 |
|
| 40 |
;;; A collection of string utilities. |
| 41 |
|
| 42 |
;;; ******* |
| 43 |
;;; Strings_____________________________________________________________________ |
| 44 |
;;; ******* |
| 45 |
|
| 46 |
;;; parse-with-delimiter : String -> List[String] |
| 47 |
;;; Breaks LINE into a list of strings, using DELIM as a breaking point. |
| 48 |
|
| 49 |
(defun parse-with-delimiter (line &optional (delim #\newline)) |
| 50 |
(declare (type simple-string line) |
| 51 |
(type character delim)) |
| 52 |
;; what about #\return instead of #\newline? |
| 53 |
(let ((pos (position delim line))) |
| 54 |
(cond (pos |
| 55 |
(cons (subseq line 0 pos) |
| 56 |
(parse-with-delimiter (subseq line (1+ pos)) delim))) |
| 57 |
(t |
| 58 |
(list line))))) |
| 59 |
|
| 60 |
(defun parse-with-delimiter2 (line &optional (delim #\newline)) |
| 61 |
(declare (type simple-string line) |
| 62 |
(type character delim)) |
| 63 |
;; what about #\return instead of #\newline? |
| 64 |
(let ((pos (position delim line))) |
| 65 |
(cond (pos |
| 66 |
(cons (subseq line 0 pos) |
| 67 |
(cons (string delim) |
| 68 |
(parse-with-delimiter2 (subseq line (1+ pos)) delim)))) |
| 69 |
(t |
| 70 |
(list line))))) |
| 71 |
|
| 72 |
;;; numeric-char-p |
| 73 |
;;; |
| 74 |
(defmacro numeric-char-p (char) |
| 75 |
`(let ((cc (char-code ,char))) |
| 76 |
(and (>= cc (char-code #\0)) |
| 77 |
(<= cc (char-code #\9))))) |
| 78 |
|
| 79 |
;;; EOF |