aboutsummaryrefslogtreecommitdiff
path: root/src/tests/csv.cpp
blob: 850fda80337f2a799fa5e89b30f729956c19330e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/optparser.h"
#include "bu/file.h"
#include "bu/newline.h"
#include "bu/csvreader.h"
#include "bu/buffer.h"
#include "bu/sio.h"

using namespace Bu;

class Options : public OptParser
{
public:
	Options( int argc, char *argv[] )
	{
		addOption( slot( this, &Options::onRead ), 'r', "read",
				"Read and display a csv file." );

		addHelpOption();

		parse( argc, argv );
	}

	int onRead( StrArray aArgs )
	{
		File fIn( aArgs[1], File::Read );
		NewLine nlIn( fIn );
		Buffer bIn( nlIn );
		CsvReader rCsv( bIn );
		while( !fIn.isEos() )
		{
			sio << rCsv.readLine() << sio.nl;
		}
		sio << sio.nl;
		return 1;
	}
};

int main( int argc, char *argv[] )
{
	Options opts( argc, argv );
	return 0;
}