1 # This file is part of NIT (http://www.nitlanguage.org).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
20 # Returns UTF-8 entities as-is
21 private class UTF8Coder
24 redef fun code_char
(c
) do return c
.to_s
.to_bytes
26 redef fun add_char_to
(c
, stream
) do c
.to_s
.append_to_bytes
(stream
)
28 redef fun code_string
(s
) do return s
.to_bytes
30 redef fun add_string_to
(s
, b
) do s
.append_to_bytes
(b
)
33 # Decodes entities in an external format to UTF-8
34 private class UTF8Decoder
37 redef fun decode_char
(b
) do
42 redef fun decode_string
(b
) do
47 # Returns the instance of a UTF-8 Coder
48 fun utf8_coder
: Coder do return once
new UTF8Coder
49 # Returns the instance of a UTF-8 Decoder
50 fun utf8_decoder
: Decoder do return once
new UTF8Decoder