Mercurial Hosting > luan
comparison src/luan/modules/parsers/Csv.java @ 1330:f41919741100
fix security
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 11 Feb 2019 01:38:55 -0700 |
parents | 9fa8b8389578 |
children | 25746915a241 |
comparison
equal
deleted
inserted
replaced
1329:5a39b006acd1 | 1330:f41919741100 |
---|---|
1 package luan.modules.parsers; | 1 package luan.modules.parsers; |
2 | 2 |
3 import luan.LuanState; | 3 import luan.LuanState; |
4 import luan.LuanTable; | 4 import luan.LuanTable; |
5 import luan.LuanException; | |
5 import luan.lib.parser.Parser; | 6 import luan.lib.parser.Parser; |
6 import luan.lib.parser.ParseException; | 7 import luan.lib.parser.ParseException; |
7 | 8 |
8 | 9 |
9 public final class Csv { | 10 public final class Csv { |
10 | 11 |
11 public static LuanTable toList(LuanState luan,String line) throws ParseException { | 12 public static LuanTable toList(LuanState luan,String line) throws ParseException { |
12 return new Csv(line).parse(luan); | 13 try { |
14 return new Csv(line).parse(luan); | |
15 } catch(LuanException e) { | |
16 throw new RuntimeException(e); | |
17 } | |
13 } | 18 } |
14 | 19 |
15 private final Parser parser; | 20 private final Parser parser; |
16 | 21 |
17 private Csv(String line) { | 22 private Csv(String line) { |
20 | 25 |
21 private ParseException exception(String msg) { | 26 private ParseException exception(String msg) { |
22 return new ParseException(parser,msg); | 27 return new ParseException(parser,msg); |
23 } | 28 } |
24 | 29 |
25 private LuanTable parse(LuanState luan) throws ParseException { | 30 private LuanTable parse(LuanState luan) throws ParseException, LuanException { |
26 LuanTable list = new LuanTable(luan); | 31 LuanTable list = new LuanTable(luan); |
27 while(true) { | 32 while(true) { |
28 Spaces(); | 33 Spaces(); |
29 String field = parseField(); | 34 String field = parseField(); |
30 list.rawPut(list.rawLength()+1,field); | 35 list.put(list.rawLength()+1,field); |
31 Spaces(); | 36 Spaces(); |
32 if( parser.endOfInput() ) | 37 if( parser.endOfInput() ) |
33 return list; | 38 return list; |
34 if( !parser.match(',') ) | 39 if( !parser.match(',') ) |
35 throw exception("unexpected char"); | 40 throw exception("unexpected char"); |