blob: 6c865a4dd2f9b45987fc52444dcb2fc029aa7897 (
plain)
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
|
(in-package :html-jen)
(defun dosya-metni-oku (dosya)
(let* ((uzunluk 0)
(metin
(with-output-to-string (out)
(with-open-file (in dosya :external-format :utf-8)
(loop :with arabellek := (make-array 8192 :element-type 'character)
:for n := (read-sequence arabellek in)
:while (< 0 n)
:do (incf uzunluk n)
(write-sequence arabellek out :start 0 :end n))))))
(values metin uzunluk)))
(defclass okur ()
((metin :initarg :metin :accessor metin
:documentation "Markdown string")
(i :initform 0 :accessor i
:documentation "Metin indeksi")
(uzunluk :initarg :uzunluk :accessor uzunluk
:documentation "Metin uzunluğu")
(dosya-ismi :initarg :dosya-ismi
:documentation "Okunan markdown dosyasının ismi")))
(defun okur! (dosya-ismi)
(multiple-value-bind (metin uzunluk)
(dosya-metni-oku dosya-ismi)
(make-instance 'okur :metin metin :uzunluk uzunluk :dosya-ismi dosya-ismi)))
(defmethod son? ((okur okur))
(>= (i okur)
(uzunluk okur)))
(defmethod index-reset ((okur okur))
(setf (i oo) 0))
(defparameter *blok-sonu* (format nil "~%~%"))
(defmethod blok-oku ((okur okur))
(unless (son? okur)
(with-slots (i uzunluk metin) okur
(let ((son (or (search *blok-sonu* metin :start2 i)
uzunluk)))
(prog1 (make-array (- son i)
:element-type 'character
:displaced-to metin
:displaced-index-offset i)
(setf i (+ son 2)))))))
(defmethod okur-blok-listesi ((okur okur))
(let ((blok (blok-oku okur)))
(if (null blok)
nil
(cons blok (okur-blok-listesi okur)))))
|