[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

finishing output translating stream



Hi,

Is there any way for <translate-proc> of make-translated-output-stream
to know if the translated output stream is flushed or closed?

It is necessary for implementing character encoding conversion, since
character encodings may have states, which should be cleared
depending on the next output character or if there's no more output
characters.

An example: Suppose I'm writing a translating output stream that
receives utf8 string and produces iso-2022 encoded string.
Iso-2022 is a stateful encoding, switching "current code sets"
with escape sequences.  And it is required that the encoding
string should end with code set #0 (default one).  If the last
character of the original output is in other code set than #0,
the translate-proc should write out extra bytes to reset the
code set.

Another example: Even Unicode can be stateful in regard to other
encoding systems.   When I'm converting utf-8 to jisx0213,
strictly following the specification, there are a few Unicode
characters I need to peek at the next character or EOF state to
determine the corresponding jisx0213 character.
For example, unicode character <U+30AB> becomes jisx0213 <0xA5AB>,
except the sequence <U+30AB> <U+309A>, which becomes <0xA5F7>.
If the last character of the original output is <U+30AB>, the
translate-proc needs to know it's the last one.

--shiro