 :: iso2022kr-stream-set-status ( stream so/si -- )
     so/si stream *iso2022kr-status* get-global set-at ;
 
-: iso2022kr-stream-shift-out? ( stream -- ? )
-    iso2022kr-stream-get-status* shift-out = ;
 
 
 M: iso2022kr encode-char ( char stream encoding -- )

    ] ;




PRIVATE>

        char unicode>cp949 byte?
        [
            ! if <SO> written, then enclose with <SI>.
            stream iso2022kr-stream-get-status shift-out =
            [
                shift-in 1byte-array stream stream-write
                stream shift-in iso2022kr-stream-set-status
            ] [ ] if
            ! plain ascii
            char 1byte-array stream stream-write
        ]
        [
            ! if <SO> is closed, then start it.
            stream iso2022kr-stream-get-status [ shift-in = ] [ f = ] bi or
            [
                shift-out 1byte-array stream stream-write
                stream shift-out iso2022kr-stream-set-status
            ] [ ] if
            !
            char unicode>cp949 h>b/b swap 2byte-array
            ! GR -> GL
