-
Notifications
You must be signed in to change notification settings - Fork 1
/
rail-common.el
92 lines (75 loc) · 3.14 KB
/
rail-common.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; rail-common.el --- Replace Agent-string Internal Library -*- coding: iso-2022-7bit-ss2; -*-
;; Copyright (C) 1999 by Free Software Foundation, Inc.
;; Author: SHIMADA Mitsunobu <simm-emacs@fan.gr.jp>
;; Youhei SASAKI <uwabami@gfd-dennou.org>
;; Keywords: i18n, internal, rail
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;
;;; Code:
(require 'rail-vars)
(defun rail-replace-character (string src dst)
"Replace character src -> dst"
(let ((len (length string))
(i 0))
(while (< i len)
(if (eq src (aref string i))
(aset string i dst))
(setq i (1+ i)))
string))
(defun rail-replace-into-iso8859-4 (string)
"Replace ISO-8859-1 string into ISO-8859-4."
(if rail-user-agent-replace-into-iso8859-4
(progn
(rail-replace-character string ?~ ?.DN~)
(rail-replace-character string ?.AN^ ?.DN^)
(rail-replace-character string ?.ANo ?.DNo)
(rail-replace-character string ?.ANO ?.DNO)
(rail-replace-character string ?.ANr ?.DNr)
(rail-replace-character string ?.ANR ?.DNR))))
(defmacro rail-assoc (string alist direction)
"Do assoc or rassoc, according to direction.
If direction is non-nil, returns (cdr (assoc string alist)).
If direction is nil, returns (car (rassoc string alist))."
(if (symbol-value direction)
(list 'cdr (list 'assoc string alist))
(list 'car (list 'rassoc string alist))))
(defun rail-replace-codename-primitive (form &rest alist)
"Replace codename according to pattern."
(save-excursion
(if (looking-at form)
(let* ((beg (match-beginning 2))
(end (match-end 2))
(code (buffer-substring beg end))
(ccode (rail-assoc code (apply 'append alist) rail-convert-direction)))
(goto-char beg)
(delete-region beg end)
(insert (or ccode code))))))
(defun rail-replace-codename (string flag &rest alist)
"Replace mule-version string."
(let (buf result)
(save-excursion
(setq buf (get-buffer-create rail-temporary-buffer-name))
(if (set-buffer buf)
(progn
(erase-buffer)
(insert string)
(goto-char (point-min))
(if (not flag)
(apply 'rail-replace-codename-primitive rail-mule-version-header-format alist))
(setq result (buffer-substring (point-min) (point-max))))
(kill-buffer buf)))
(or result string)))
(provide 'rail-common)
;;; rail-common.el ends here