9b4da2feeda0aa5f7d9aebf16201da08fb0a1963
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.
15 # CSV output facilities
18 # A CSV document representation
22 var header
: Array[String] writable = new Array[String]
23 var lines
: Array[Array[String]] = new Array[Array[String]]
25 fun set_header
(values
: Object...) do
27 for value
in values
do
28 header
.add
(value
.to_s
)
32 fun add_line
(values
: Object...) do
33 if values
.length
!= header
.length
then
34 print
"CSV error: header declares {header.length} columns, line contains {values.length} values"
37 var line
= new Array[String]
38 for value
in values
do
44 private fun write_line_to
(line
: Collection[String], stream
: OStream)
59 redef fun write_to
(stream
)
61 write_line_to
(header
, stream
)
62 for line
in lines
do write_line_to
(line
, stream
)
65 # deprecated alias for `write_to_file`
66 fun save
(file
: String) do write_to_file
(file
)