annotate lisp/tl/tl-str.el @ 23:0edd3412f124

Added tag r19-15b94 for changeset 8fc7fe29b841
author cvs
date Mon, 13 Aug 2007 08:50:31 +0200
parents 0293115a14e9
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
1 ;;; tl-str.el --- Emacs Lisp Library module about string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
2
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
3 ;; Copyright (C) 1995,1996,1997 Free Software Foundation, Inc.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
6 ;; Version: $Id: tl-str.el,v 1.3 1997/02/02 05:06:17 steve Exp $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
7 ;; Keywords: string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
8
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
9 ;; This file is part of tl (Tiny Library).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
10
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
11 ;; This program is free software; you can redistribute it and/or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
12 ;; modify it under the terms of the GNU General Public License as
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
13 ;; published by the Free Software Foundation; either version 2, or (at
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
14 ;; your option) any later version.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
15
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
16 ;; This program is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
20
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
25
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
26 ;;; Code:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
27
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
28 (require 'emu)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
29 (require 'tl-list)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
30
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
31
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
32 ;;; @ converter
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
33 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
34
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
35 (defun expand-char-ranges (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
36 (let ((i 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
37 (len (length str))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
38 chr pchr nchr
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
39 (dest ""))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
40 (while (< i len)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
41 (setq chr (elt str i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
42 (cond ((and pchr (eq chr ?-))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
43 (setq pchr (1+ pchr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
44 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
45 (setq nchr (elt str i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
46 (while (<= pchr nchr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
47 (setq dest (concat dest (char-to-string pchr)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
48 (setq pchr (1+ pchr))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
49 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
50 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
51 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
52 (setq dest (concat dest (char-to-string chr)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
53 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
54 (setq pchr chr)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
55 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
56 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
57 dest))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
58
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
59
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
60 ;;; @ space
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
61 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
62
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
63 (defun eliminate-top-spaces (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
64 "Eliminate top sequence of space or tab and return it. [tl-str.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
65 (if (string-match "^[ \t]+" str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
66 (substring str (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
67 str))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
68
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
69 (defun eliminate-last-spaces (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
70 "Eliminate last sequence of space or tab and return it. [tl-str.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
71 (if (string-match "[ \t]+$" str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
72 (substring str 0 (match-beginning 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
73 str))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
74
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
75 (defun replace-space-with-underline (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
76 (mapconcat (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
77 (lambda (arg)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
78 (char-to-string
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
79 (if (eq arg ?\ )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
80 ?_
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
81 arg)))) str "")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
82 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
83
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
84
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
85 ;;; @ version
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
86 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
87
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
88 (defun version-to-list (str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
89 (if (string-match "[0-9]+" str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
90 (let ((dest
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
91 (list
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
92 (string-to-number
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
93 (substring str (match-beginning 0)(match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
94 ))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
95 (setq str (substring str (match-end 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
96 (while (string-match "^\\.[0-9]+" str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
97 (setq dest
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
98 (cons
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
99 (string-to-number
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
100 (substring str (1+ (match-beginning 0))(match-end 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
101 dest))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
102 (setq str (substring str (match-end 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
103 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
104 (nreverse dest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
105 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
106
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
107 (defun version< (v1 v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
108 (or (listp v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
109 (setq v1 (version-to-list v1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
110 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
111 (or (listp v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
112 (setq v2 (version-to-list v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
113 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
114 (catch 'tag
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
115 (while (and v1 v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
116 (cond ((< (car v1)(car v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
117 (throw 'tag v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
118 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
119 ((> (car v1)(car v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
120 (throw 'tag nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
121 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
122 (setq v1 (cdr v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
123 v2 (cdr v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
124 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
125 v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
126
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
127 (defun version<= (v1 v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
128 (or (listp v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
129 (setq v1 (version-to-list v1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
130 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
131 (or (listp v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
132 (setq v2 (version-to-list v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
133 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
134 (catch 'tag
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
135 (while (and v1 v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
136 (cond ((< (car v1)(car v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
137 (throw 'tag v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
138 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
139 ((> (car v1)(car v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
140 (throw 'tag nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
141 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
142 (setq v1 (cdr v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
143 v2 (cdr v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
144 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
145 (or v2 (and (null v1)(null v2)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
146 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
147
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
148 (defun version> (v1 v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
149 (or (listp v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
150 (setq v1 (version-to-list v1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
151 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
152 (or (listp v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
153 (setq v2 (version-to-list v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
154 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
155 (catch 'tag
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
156 (while (and v1 v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
157 (cond ((> (car v1)(car v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
158 (throw 'tag v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
159 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
160 ((< (car v1)(car v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
161 (throw 'tag nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
162 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
163 (setq v1 (cdr v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
164 v2 (cdr v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
165 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
166 v1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
167
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
168 (defun version>= (v1 v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
169 (or (listp v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
170 (setq v1 (version-to-list v1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
171 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
172 (or (listp v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
173 (setq v2 (version-to-list v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
174 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
175 (catch 'tag
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
176 (while (and v1 v2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
177 (cond ((> (car v1)(car v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
178 (throw 'tag v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
179 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
180 ((< (car v1)(car v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
181 (throw 'tag nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
182 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
183 (setq v1 (cdr v1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
184 v2 (cdr v2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
185 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
186 (or v1 (and (null v1)(null v2)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
187 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
188
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
189
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
190 ;;; @ RCS version
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
191 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
192
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
193 (defun get-version-string (id)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
194 "Return a version-string from RCS ID. [tl-str.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
195 (and (string-match ",v \\([0-9][0-9.][0-9.]+\\)" id)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
196 (substring id (match-beginning 1)(match-end 1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
197 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
198
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
199
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
200 ;;; @ file name
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
201 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
202
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
203 (defun file-name-non-extension (filename)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
204 (if (string-match "\\.[^.]+$" filename)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
205 (substring filename 0 (match-beginning 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
206 filename))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
207
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
208 (autoload 'replace-as-filename "filename"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
209 "Return safety filename from STRING.")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
210
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
211
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
212 ;;; @ symbol
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
213 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
214
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
215 (defun symbol-concat (&rest args)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
216 "Return a symbol whose name is concatenation of arguments ARGS
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
217 which are string or symbol. [tl-str.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
218 (intern (apply (function concat)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
219 (mapcar (function
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
220 (lambda (s)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
221 (cond ((symbolp s) (symbol-name s))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
222 ((stringp s) s)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
223 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
224 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
225 args)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
226 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
227
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
228
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
229 ;;; @ matching
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
230 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
231
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
232 (defun top-string-match (pat str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
233 "Return a list (MATCHED REST) if string PAT is top substring of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
234 string STR. [tl-str.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
235 (if (string-match
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
236 (concat "^" (regexp-quote pat))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
237 str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
238 (list pat (substring str (match-end 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
239 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
240
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
241 (defun middle-string-match (pat str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
242 "Return a list (PREVIOUS MATCHED REST) if string PAT is found in
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
243 string STR. [tl-str.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
244 (if (equal pat str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
245 (list nil pat nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
246 (if (string-match (regexp-quote pat) str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
247 (let ((b (match-beginning 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
248 (e (match-end 0)) )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
249 (list (if (not (= b 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
250 (substring str 0 b)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
251 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
252 pat
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
253 (if (> (length str) e)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
254 (substring str e)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
255 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
256 )))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
257
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
258 (defun re-top-string-match (pat str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
259 "Return a list (MATCHED REST) if regexp PAT is matched as top
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
260 substring of string STR. [tl-str.el]"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
261 (if (string-match (concat "^" pat) str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
262 (let ((e (match-end 0)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
263 (list (substring str 0 e)(substring str e))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
264 )))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
265
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
266
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
267 ;;; @ compare
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
268 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
269
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
270 (defun string-compare-from-top (str1 str2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
271 (let* ((len1 (length str1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
272 (len2 (length str2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
273 (len (min len1 len2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
274 (p 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
275 c1 c2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
276 (while (and (< p len)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
277 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
278 (setq c1 (sref str1 p)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
279 c2 (sref str2 p))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
280 (eq c1 c2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
281 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
282 (setq p (+ p (char-length c1)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
283 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
284 (and (> p 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
285 (let ((matched (substring str1 0 p))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
286 (r1 (and (< p len1)(substring str1 p)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
287 (r2 (and (< p len2)(substring str2 p)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
288 )
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
289 (if (eq r1 r2)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
290 matched
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
291 (list 'seq matched (list 'or r1 r2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
292 )))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
293
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
294
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
295 ;;; @ regexp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
296 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
297
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
298 (defun regexp-* (regexp)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
299 (concat regexp "*"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
300
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
301 (defun regexp-or (&rest args)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
302 (concat "\\(" (mapconcat (function identity) args "\\|") "\\)"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
303
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
304
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
305 ;;; @ end
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
306 ;;;
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
307
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
308 (provide 'tl-str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
309
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents:
diff changeset
310 ;;; tl-str.el ends here