From 743149ac54fd2c6ae2ad981bb4179d3cde2c81d1 Mon Sep 17 00:00:00 2001 From: ueno Date: Tue, 7 Dec 2004 03:35:06 +0000 Subject: [PATCH] * 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. --- lisp/ChangeLog | 12 ++++++++ lisp/riece-log.el | 37 +++++++++++++++++++++++++ lisp/test/test-riece-log.el | 64 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2695dd7..a1d217d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,15 @@ +2004-12-07 Daiki Ueno + + * 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 * test/test-riece-log.el: New test cases. diff --git a/lisp/riece-log.el b/lisp/riece-log.el index 559efe2..f9c9fe3 100644 --- a/lisp/riece-log.el +++ b/lisp/riece-log.el @@ -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))) diff --git a/lisp/test/test-riece-log.el b/lisp/test/test-riece-log.el index aeeb256..0118ed1 100644 --- a/lisp/test/test-riece-log.el +++ b/lisp/test/test-riece-log.el @@ -1,3 +1,5 @@ +;;; -*- coding: iso-2022-7 -*- + (require 'riece-log) (luna-define-class test-riece-log (lunit-test-case)) @@ -54,3 +56,65 @@ (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"))))) -- 1.7.10.4