anchor.diff:                                           (2 (< state #x800))
                                            (3 (< state #x10000)))
                                          (progn (incf read) #2#)
  -                                       (commit state))
  +                                       (if not-first-byte
  +                                           (commit state)
  +                                           (progn
  +                                             (setf not-first-byte t)
  +                                             (if (or (= state #xfeff)
  +                                                     (= state #xfffe))
  +                                                 (setf (encoding-bom encoding) state)
  +                                                 (commit state)))))
                                      (setf state 0 count 0 read 0))))))
               (when (< end buffer-size)
                 (return))
           :finally (commit nil))))) ;; signal eof
   
   (defmethod encoding-write ((encoding utf-8) out)
  -  (declare(ignore encoding))
  -  (lambda (c)
  -    (when c
  -      (let ((p (char-code c)))
  -        (cond ((<=    #x00 p   #x7f) (write-byte p out))
  -              ((e-range p) (write-byte (e- p) out))
  -              ((<=    #x80 p  #x7ff) 
  -               (write-byte (+ #xc0 (ash p -6)) out)
  -               (write-byte (+ #x80 (logand p #x3f)) out))
  -              ((<=   #x800 p #xffff)
  -               (write-byte (+ #xe0 (ash p -12)) out)
  -               (write-byte (+ #x80 (logand (ash p -6) #x3f)) out)
  -               (write-byte (+ #x80 (logand p #x3f)) out))
  -              ((<= #x10000 p #x1fffff)
  -               (write-byte (+ #xf0 (ash p -18)) out)
  -               (write-byte (+ #x80 (logand (ash p -12) #x3f)) out)
  -               (write-byte (+ #x80 (logand (ash p -6) #x3f)) out)
  -               (write-byte (+ #x80 (logand p #x3f)) out)))))))
  +  (flet ((utf8-write-char (c)
  +           (when c
  +             (let ((p (char-code c)))
  +               (cond ((<=    #x00 p   #x7f) (write-byte p out))
  +                     ((e-range p) (write-byte (e- p) out))
  +                     ((<=    #x80 p  #x7ff)
  +                      (write-byte (+ #xc0 (ash p -6)) out)
  +                      (write-byte (+ #x80 (logand p #x3f)) out))
  +                     ((<=   #x800 p #xffff)
  +                      (write-byte (+ #xe0 (ash p -12)) out)
  +                      (write-byte (+ #x80 (logand (ash p -6) #x3f)) out)
  +                      (write-byte (+ #x80 (logand p #x3f)) out))
  +                     ((<= #x10000 p #x1fffff)
  +                      (write-byte (+ #xf0 (ash p -18)) out)
  +                      (write-byte (+ #x80 (logand (ash p -12) #x3f)) out)
  +                      (write-byte (+ #x80 (logand (ash p -6) #x3f)) out)
  +                      (write-byte (+ #x80 (logand p #x3f)) out)))))))
  +    (let ((bom (encoding-bom encoding)))
  +      (when bom
  +        (case bom
  +          (#xfffe (utf8-write-char bom))
  +          (t (utf8-write-char #xfeff)))))
  +    #'utf8-write-char))
  
positive.code: (in-package :lem-encodings/utf-8)
  ;;;don't edit above
  
  (defclass utf-8 (encoding) ())
  
  (register-encoding 'utf-8)
  
  
negative.code:                                      ((<= #xc0 c #xdf) (values 1 (logand #x1f c)))
                                       ((<= #xe0 c #xef) (values 2 (logand #x0f c)))
                                       ((<= #xf0 c #xf7) (values 3 (logand #x07 c)))
                                       ((<= #xf8 c #xff) (ecommit c) (values 0 0)))) ;; error exceed 21bit
                            (cond ((or (<= #x00 c #x7f)  ;;error input
                                       (<= #xc0 c #xff))
                                   #2=(loop :with result ;;revert partial read.
  