5 (put 'ew-crlf-line-generic 'lisp-indent-function 1)
6 (put 'ew-crlf-line-convert 'lisp-indent-function 1)
7 (put 'ew-lf-line-generic 'lisp-indent-function 1)
8 (put 'ew-lf-line-convert 'lisp-indent-function 1)
10 (defun ew-lf-to-crlf (str)
11 (let ((i 0) (j 0) (l (length str)) result)
13 (when (equal (aref str j) ?\n)
14 (setq result (ew-rcons*
21 (setq result (ew-rcons*
24 (apply 'concat (nreverse result))))
26 (defun ew-crlf-to-lf (str)
27 (let* ((i 0) (j 0) (l (length str)) (l- (1- l)) result)
29 (when (and (equal (aref str j) ?\r)
30 (equal (aref str (1+ j)) ?\n))
31 (setq result (ew-rcons*
38 (setq result (ew-rcons*
41 (apply 'concat (nreverse result))))
43 (defun ew-lf-crlf-to-crlf (str)
44 (let* ((i 0) (j 0) (l (length str)) (l- (1- l)) result)
48 (equal (aref str j) ?\r)
49 (equal (aref str (1+ j)) ?\n))
51 ((equal (aref str j) ?\n)
52 (setq result (ew-rcons*
59 (setq result (ew-rcons*
62 (apply 'concat (nreverse result))))
64 (defun ew-crlf-unfold (str)
65 (let* ((i 0) (j 0) (l (length str)) (l- (- l 2)) result)
67 (when (and (equal (aref str j) ?\r)
68 (equal (aref str (1+ j)) ?\n)
69 (member (aref str (+ j 2)) '(?\t ?\ )))
70 (setq result (ew-rcons*
77 (setq result (ew-rcons*
80 (apply 'concat (nreverse result))))
82 (defun ew-lf-unfold (str)
83 (let* ((i 0) (j 0) (l (length str)) (l- (- l 1)) result)
85 (when (and (equal (aref str j) ?\n)
86 (member (aref str (+ j 1)) '(?\t ?\ )))
87 (setq result (ew-rcons*
94 (setq result (ew-rcons*
97 (apply 'concat (nreverse result))))
99 (defun ew-cut-generic (str chars)
100 (let ((i 0) (j 0) (l (length str)) result)
102 (when (member (aref str j) chars)
103 (setq result (ew-rcons*
109 (setq result (ew-rcons*
112 (apply 'concat (nreverse result))))
114 (defun ew-cut-cr-lf (str) (ew-cut-generic str '(?\r ?\n)))
115 (defun ew-cut-cr (str) (ew-cut-generic str '(?\r)))
116 (defun ew-cut-lf (str) (ew-cut-generic str '(?\n)))
118 (defmacro ew-crlf-line-generic-define ()
119 (let ((str (make-symbol "str"))
120 (others-fun (make-symbol "others-fun"))
121 (fold-fun (make-symbol "fold-fun"))
122 (crlf-fun (make-symbol "crlf-fun"))
123 (bare-cr-fun (make-symbol "bare-cr-fun"))
124 (bare-lf-fun (make-symbol "bare-lf-fun"))
125 (p (make-symbol "p"))
126 (q (make-symbol "q"))
127 (r (make-symbol "r")))
128 `(defun ew-crlf-line-generic
129 (,str ,others-fun ,fold-fun ,crlf-fun ,bare-cr-fun ,bare-lf-fun)
130 (let ((,p 0) (,q (length ,str)) ,r)
133 (lex-scan-unibyte ,str ,p ,q
134 ((+ [^ "\r\n"]) (when ,others-fun (funcall ,others-fun ,r ,p)))
135 ((?\r ?\n [" \t"]) (when ,fold-fun (funcall ,fold-fun ,r ,p)))
136 ((?\r ?\n) (when ,crlf-fun (funcall ,crlf-fun ,r ,p)))
137 ((?\r) (when ,bare-cr-fun (funcall ,bare-cr-fun ,r ,p)))
138 ((?\n) (when ,bare-lf-fun (funcall ,bare-lf-fun ,r ,p)))
139 (() (error "something wrong"))))
142 (ew-crlf-line-generic-define)
144 (defmacro ew-crlf-line-convert-define ()
145 (let ((str (make-symbol "str"))
146 (others-fun (make-symbol "others-fun"))
147 (fold-fun (make-symbol "fold-fun"))
148 (crlf-fun (make-symbol "crlf-fun"))
149 (bare-cr-fun (make-symbol "bare-cr-fun"))
150 (bare-lf-fun (make-symbol "bare-lf-fun"))
151 (index (make-symbol "index"))
152 (result (make-symbol "result"))
153 (start (make-symbol "starx"))
154 (end (make-symbol "end")))
155 `(defun ew-crlf-line-convert
156 (,str ,others-fun ,fold-fun ,crlf-fun ,bare-cr-fun ,bare-lf-fun)
157 (let ((,index 0) ,result)
158 (when (> (ew-crlf-line-generic
163 (lambda (,start ,end)
164 (when (< ,index ,start)
167 (substring ,str ,index ,start))))
171 (substring ,str ,start ,end)))
173 (list others-fun fold-fun crlf-fun bare-cr-fun bare-lf-fun)))
177 (substring ,str ,index))))
178 (apply 'concat (nreverse ,result))))))
180 (ew-crlf-line-convert-define)
182 (defmacro ew-lf-line-generic-define ()
183 (let ((str (make-symbol "str"))
184 (others-fun (make-symbol "others-fun"))
185 (fold-fun (make-symbol "fold-fun"))
186 (lf-fun (make-symbol "lf-fun"))
187 (p (make-symbol "p"))
188 (q (make-symbol "q"))
189 (r (make-symbol "r")))
190 `(defun ew-lf-line-generic
191 (,str ,others-fun ,fold-fun ,lf-fun)
192 (let ((,p 0) (,q (length ,str)) ,r)
195 (lex-scan-unibyte ,str ,p ,q
196 ((+ [^ "\n"]) (when ,others-fun (funcall ,others-fun ,r ,p)))
197 ((?\n [" \t"]) (when ,fold-fun (funcall ,fold-fun ,r ,p)))
198 ((?\n) (when ,lf-fun (funcall ,lf-fun ,r ,p)))
199 (() (error "something wrong"))))
202 (ew-lf-line-generic-define)
204 (defmacro ew-lf-line-convert-define ()
205 (let ((str (make-symbol "str"))
206 (others-fun (make-symbol "others-fun"))
207 (fold-fun (make-symbol "fold-fun"))
208 (lf-fun (make-symbol "lf-fun"))
209 (index (make-symbol "index"))
210 (result (make-symbol "result"))
211 (start (make-symbol "starx"))
212 (end (make-symbol "end")))
213 `(defun ew-lf-line-convert
214 (,str ,others-fun ,fold-fun ,lf-fun)
215 (let ((,index 0) ,result)
216 (when (> (ew-lf-line-generic
221 (lambda (,start ,end)
222 (when (< ,index ,start)
225 (substring ,str ,index ,start))))
229 (substring ,str ,start ,end)))
231 (list others-fun fold-fun lf-fun)))
235 (substring ,str ,index))))
236 (apply 'concat (nreverse ,result))))))
238 (ew-lf-line-convert-define)