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
20 var header
: Array[String] writable = new Array[String]
21 var lines
: Array[Array[String]] = new Array[Array[String]]
23 fun set_header
(values
: Object...) do
25 for value
in values
do
26 header
.add
(value
.to_s
)
30 fun add_line
(values
: Object...) do
31 if values
.length
!= header
.length
then
32 print
"CSV error: header declares {header.length} columns, line contains {values.length} values"
35 var line
= new Array[String]
36 for value
in values
do
43 var str
= header
.join
(";") + "\n"
44 for line
in lines
do str
+= line
.join
(";") + "\n"
48 fun save
(file
: String) do
49 var out
= new OFStream.open
(file
)