* test/test-riece-log.el (test-riece-log-encode-file-name): New
authorueno <ueno>
Tue, 7 Dec 2004 03:35:06 +0000 (03:35 +0000)
committerueno <ueno>
Tue, 7 Dec 2004 03:35:06 +0000 (03:35 +0000)
test case.
(test-riece-log-encode-file-name-mule): New test case.
(test-riece-log-decode-file-name): New test case.
(test-riece-log-decode-file-name-mule): New test case.

* riece-log.el (riece-log-file-name-coding-system): New user option.
(riece-log-encode-file-name): New function.
(riece-log-decode-file-name): New function.

lisp/ChangeLog
lisp/riece-log.el
lisp/test/test-riece-log.el

index 2695dd7..a1d217d 100644 (file)
@@ -1,3 +1,15 @@
+2004-12-07  Daiki Ueno  <ueno@unixuser.org>
+
+       * test/test-riece-log.el (test-riece-log-encode-file-name): New
+       test case.
+       (test-riece-log-encode-file-name-mule): New test case.
+       (test-riece-log-decode-file-name): New test case.
+       (test-riece-log-decode-file-name-mule): New test case.
+
+       * riece-log.el (riece-log-file-name-coding-system): New user option.
+       (riece-log-encode-file-name): New function.
+       (riece-log-decode-file-name): New function.
+
 2004-12-06  Daiki Ueno  <ueno@unixuser.org>
 
        * test/test-riece-log.el: New test cases.
index 559efe2..f9c9fe3 100644 (file)
@@ -61,6 +61,13 @@ If integer, flash back only this line numbers. t means all lines."
   :type 'symbol
   :group 'riece-log)
 
+(defcustom riece-log-file-name-coding-system
+  (if (boundp 'file-name-coding-system)
+      file-name-coding-system)
+  "*Coding system used for filenames of log files."
+  :type 'symbol
+  :group 'riece-log)
+
 (defcustom riece-log-open-directory-function 'find-file
   "*Function for opening a directory."
   :type 'function
@@ -112,6 +119,36 @@ If integer, flash back only this line numbers. t means all lines."
        (expand-file-name name (expand-file-name server riece-log-directory))
       (expand-file-name name riece-log-directory))))
 
+(defun riece-log-encode-file-name (file-name)
+  (if riece-log-file-name-coding-system
+      (setq file-name
+           (encode-coding-string file-name
+                                 riece-log-file-name-coding-system)))
+  (let ((index 0))
+    (while (string-match "[^-0-9A-Za-z=_\x80-\xFF]" file-name index)
+      (setq file-name (replace-match
+                      (format "=%02X"
+                              (aref file-name (match-beginning 0)))
+                      nil t file-name)
+           index (+ 3 index)))
+    file-name))
+
+(defun riece-log-decode-file-name (file-name)
+  (let ((index 0))
+    (while (string-match "=\\([0-7][0-9A-F]\\)" file-name index)
+      (setq file-name (replace-match
+                      (char-to-string
+                       (car (read-from-string
+                             (concat "?\\x" (match-string 1 file-name)))))
+                      nil t file-name)
+           index (1+ index)))
+    file-name)
+  (if riece-log-file-name-coding-system
+      (setq file-name
+           (decode-coding-string file-name
+                                 riece-log-file-name-coding-system)))
+  file-name)
+
 (defun riece-log-flashback-1 (identity)
   (if (eq riece-log-flashback t)
       (let ((file (riece-log-get-file identity)))
index aeeb256..0118ed1 100644 (file)
@@ -1,3 +1,5 @@
+;;; -*- coding: iso-2022-7 -*-
+
 (require 'riece-log)
 
 (luna-define-class test-riece-log (lunit-test-case))
            (with-temp-buffer
              (riece-log-flashback (riece-make-identity "#riece" ""))
              (buffer-string))))))
+
+(luna-define-method test-riece-log-encode-file-name ((case test-riece-log))
+  (let (riece-log-file-name-coding-system)
+    (lunit-assert-2
+     case
+     (equal "=23riece"
+           (riece-log-encode-file-name "#riece")))
+    (lunit-assert-2
+     case
+     (equal "=23riece=3A=2A=2Ejp"
+           (riece-log-encode-file-name "#riece:*.jp")))))
+
+(luna-define-method test-riece-log-encode-file-name-mule
+  ((case test-riece-log))
+  (let ((riece-log-file-name-coding-system 'iso-8859-1))
+    (lunit-assert-2
+     case
+     (equal "=23\xABriece\xBB"
+           (riece-log-encode-file-name
+            (format "#%criece%c"
+                    (make-char 'latin-iso8859-1 43)
+                    (make-char 'latin-iso8859-1 59))))))
+  (let ((riece-log-file-name-coding-system 'iso-2022-jp))
+    (lunit-assert-2
+     case
+     (equal "=23=1B=24B=24j=21=3C=249=1B=28B"
+           (riece-log-encode-file-name
+            (format "#%c%c%c"
+                   (make-char 'japanese-jisx0208 36 106)
+                   (make-char 'japanese-jisx0208 33 60)
+                   (make-char 'japanese-jisx0208 36 57)))))))
+
+(luna-define-method test-riece-log-decode-file-name ((case test-riece-log))
+  (let (riece-log-file-name-coding-system)
+    (lunit-assert-2
+     case
+     (equal "#riece"
+           (riece-log-decode-file-name "=23riece")))
+    (lunit-assert-2
+     case
+     (equal "#riece:*.jp"
+           (riece-log-decode-file-name "=23riece=3A=2A=2Ejp")))))
+
+(luna-define-method test-riece-log-decode-file-name-mule
+  ((case test-riece-log))
+  (let ((riece-log-file-name-coding-system 'iso-8859-1))
+    (lunit-assert-2
+     case
+     (equal (format "#%criece%c"
+                    (make-char 'latin-iso8859-1 43)
+                    (make-char 'latin-iso8859-1 59))
+           (riece-log-decode-file-name
+            "=23\xABriece\xBB"))))
+  (let ((riece-log-file-name-coding-system 'iso-2022-jp))
+    (lunit-assert-2
+     case
+     (equal (format "#%c%c%c"
+                   (make-char 'japanese-jisx0208 36 106)
+                   (make-char 'japanese-jisx0208 33 60)
+                   (make-char 'japanese-jisx0208 36 57))
+           (riece-log-decode-file-name
+            "=23=1B=24B=24j=21=3C=249=1B=28B")))))