1 ;;; tl-str.el --- Emacs Lisp Library module about string
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Version: $Id: tl-str.el,v 1.1.1.1 1998-01-14 06:27:57 steve Exp $
9 ;; This file is part of tl (Tiny Library).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
35 (defun expand-char-ranges (str)
41 (setq chr (elt str i))
42 (cond ((and pchr (eq chr ?-))
45 (setq nchr (elt str i))
47 (setq dest (concat dest (char-to-string pchr)))
52 (setq dest (concat dest (char-to-string chr)))
63 (defun eliminate-top-spaces (str)
64 "Eliminate top sequence of space or tab and return it. [tl-str.el]"
65 (if (string-match "^[ \t]+" str)
66 (substring str (match-end 0))
69 (defun eliminate-last-spaces (str)
70 "Eliminate last sequence of space or tab and return it. [tl-str.el]"
71 (if (string-match "[ \t]+$" str)
72 (substring str 0 (match-beginning 0))
75 (defun replace-space-with-underline (str)
88 (defun version-to-list (str)
89 (if (string-match "[0-9]+" str)
93 (substring str (match-beginning 0)(match-end 0))
95 (setq str (substring str (match-end 0)))
96 (while (string-match "^\\.[0-9]+" str)
100 (substring str (1+ (match-beginning 0))(match-end 0)))
102 (setq str (substring str (match-end 0)))
107 (defun version< (v1 v2)
109 (setq v1 (version-to-list v1))
112 (setq v2 (version-to-list v2))
116 (cond ((< (car v1)(car v2))
119 ((> (car v1)(car v2))
127 (defun version<= (v1 v2)
129 (setq v1 (version-to-list v1))
132 (setq v2 (version-to-list v2))
136 (cond ((< (car v1)(car v2))
139 ((> (car v1)(car v2))
145 (or v2 (and (null v1)(null v2)))
148 (defun version> (v1 v2)
150 (setq v1 (version-to-list v1))
153 (setq v2 (version-to-list v2))
157 (cond ((> (car v1)(car v2))
160 ((< (car v1)(car v2))
168 (defun version>= (v1 v2)
170 (setq v1 (version-to-list v1))
173 (setq v2 (version-to-list v2))
177 (cond ((> (car v1)(car v2))
180 ((< (car v1)(car v2))
186 (or v1 (and (null v1)(null v2)))
193 (defun get-version-string (id)
194 "Return a version-string from RCS ID. [tl-str.el]"
195 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
196 (substring id (match-beginning 1)(match-end 1))
203 (defun file-name-non-extension (filename)
204 (if (string-match "\\.[^.]+$" filename)
205 (substring filename 0 (match-beginning 0))
208 (autoload 'replace-as-filename "filename"
209 "Return safety filename from STRING.")
215 (defun symbol-concat (&rest args)
216 "Return a symbol whose name is concatenation of arguments ARGS
217 which are string or symbol. [tl-str.el]"
218 (intern (apply (function concat)
221 (cond ((symbolp s) (symbol-name s))
232 (defun top-string-match (pat str)
233 "Return a list (MATCHED REST) if string PAT is top substring of
234 string STR. [tl-str.el]"
236 (concat "^" (regexp-quote pat))
238 (list pat (substring str (match-end 0)))
241 (defun middle-string-match (pat str)
242 "Return a list (PREVIOUS MATCHED REST) if string PAT is found in
243 string STR. [tl-str.el]"
246 (if (string-match (regexp-quote pat) str)
247 (let ((b (match-beginning 0))
249 (list (if (not (= b 0))
253 (if (> (length str) e)
258 (defun re-top-string-match (pat str)
259 "Return a list (MATCHED REST) if regexp PAT is matched as top
260 substring of string STR. [tl-str.el]"
261 (if (string-match (concat "^" pat) str)
262 (let ((e (match-end 0)))
263 (list (substring str 0 e)(substring str e))
270 (defun string-compare-from-top (str1 str2)
271 (let* ((len1 (length str1))
273 (len (min len1 len2))
276 (while (and (< p len)
278 (setq c1 (sref str1 p)
282 (setq p (+ p (char-length c1)))
285 (let ((matched (substring str1 0 p))
286 (r1 (and (< p len1)(substring str1 p)))
287 (r2 (and (< p len2)(substring str2 p)))
291 (list 'seq matched (list 'or r1 r2))
298 (defun regexp-* (regexp)
301 (defun regexp-or (&rest args)
302 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
310 ;;; tl-str.el ends here