Merge: Fix qualified imports
[nit.git] / lib / core / codecs / codec_base.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 # Base for codecs to use with streams
16 #
17 # A Codec (Coder/Decoder) is a tranformer from a byte-format to another
18 #
19 # As Nit Strings are UTF-8, a codec works as :
20 # - Coder: From a UTF-8 string to a specified format (writing)
21 # - Decoder: From a specified format to a UTF-8 string (reading)
22 module codec_base
23
24 import text
25 import bytes
26
27 # Codes UTF-8 entities to an external format
28 abstract class Coder
29
30 # Transforms `c` to its representation in the format of `self`
31 fun code_char(c: Char): Bytes is abstract
32
33 # Adds a char `c` to bytes `s`
34 fun add_char_to(c: Char, s: Bytes) is abstract
35
36 # Transforms `s` to the format of `self`
37 fun code_string(s: Text): Bytes is abstract
38
39 # Adds a string `s` to bytes `b`
40 fun add_string_to(s: Text, b: Bytes) is abstract
41 end
42
43 # Decodes entities in an external format to UTF-8
44 abstract class Decoder
45
46 # Decodes a char from `b` to a Unicode code-point
47 fun decode_char(b: Bytes): Char is abstract
48
49 # Decodes a string `b` to UTF-8
50 fun decode_string(b: Bytes): String is abstract
51 end