source: trunk/abcl/contrib/jss/util.lisp

Last change on this file was 15146, checked in by Mark Evenson, 5 years ago

JSS read sharp expression bugfixes
(Alan Ruttenberg)

Fix the following in JSS:

1) method call expression lookup java class for jstatic.
2) maybe-class, if it isn't a class, intern in current package vs. jss

Added missing <file:contrib/jss/util.lisp> from the head as of
github.com/alanruttenberg/abcl
with commit 2dab9f16384f279afe0127ef3c540811939c5bcb
<https://github.com/alanruttenberg/abcl/commit/0ce3f7d0e8003d2ca66cf59c4cd5d32a7c8f4f40>.

Untabify all source units for sanity.

Merges <https://github.com/armedbear/abcl/pull/65>.

Via
<https://github.com/armedbear/abcl/pull/65/commits/4461941d335feb298fd246f29967766c213b0e8c>,
<https://github.com/armedbear/abcl/pull/65/commits/3a681f852f0dc0581f8d47393e0d2d5d6e58596f>.

File size: 1.1 KB
Line 
1(in-package :jss)
2
3(defun tree-replace (replace-fn tree)
4  "create new tree replacing each element with the result of calling replace-fn on it"
5  (labels ((tr-internal (tree)
6             (cond ((atom tree) (funcall replace-fn tree))
7                   (t (let ((replacement (funcall replace-fn tree)))
8                        (if (eq replacement tree)
9                            (mapcar #'tr-internal tree)
10                            replacement))))))
11    (tr-internal tree)))
12
13(defun replace-all (string regex function &rest which)
14  (let ((matcher (#"matcher" (if (java-object-p regex) regex (#"compile" 'java.util.regex.pattern regex)) string))
15        (sb (new 'stringbuffer)))
16    (with-constant-signature ((append "appendReplacement")) 
17      (loop for found = (#"find" matcher)
18            while found 
19            do
20               (#"appendReplacement" matcher sb (apply function 
21                                                       (loop for g in which collect
22                                                                            (#"group" matcher g)))))
23      )
24    (#"appendTail" matcher sb)
25    (#"toString" sb)))
Note: See TracBrowser for help on using the repository browser.