tests: update sav for nitls because tests/project1 changef.
[nit.git] / lib / standard / codecs / utf8.nit
1 # This file is part of NIT (http://www.nitlanguage.org).
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 # Codec for UTF-8 I/O
16 module utf8
17
18 import codec_base
19
20 # Returns UTF-8 entities as-is
21 private class UTF8Coder
22 super Coder
23
24 redef fun code_char(c) do return c.to_s.to_bytes
25
26 redef fun add_char_to(c, stream) do c.to_s.append_to_bytes(stream)
27
28 redef fun code_string(s) do return s.to_bytes
29
30 redef fun add_string_to(s, b) do s.append_to_bytes(b)
31 end
32
33 # Decodes entities in an external format to UTF-8
34 private class UTF8Decoder
35 super Decoder
36
37 redef fun decode_char(b) do
38 var s = b.to_s
39 return s[0]
40 end
41
42 redef fun decode_string(b) do
43 return b.to_s
44 end
45 end
46
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