File tree Expand file tree Collapse file tree 1 file changed +49
-5
lines changed
Expand file tree Collapse file tree 1 file changed +49
-5
lines changed Original file line number Diff line number Diff line change @@ -25,14 +25,58 @@ public Deserializer(byte[] buffer)
2525
2626 public Document Deserialize ( )
2727 {
28-
29- return new Document ( Headers , Rows ) ;
28+ Document doc = new Document ( ) ;
29+ int index = 0 ;
30+ while ( ! File . EndOfStream )
31+ {
32+ Row row = new Row ( ) ;
33+ char [ ] line = File . ReadLine ( ) . ToCharArray ( ) ;
34+ char [ ] buffer = new char [ line . Length ] ; //temporary buffer for composing values
35+ for ( int i = 0 ; i < line . Length ; i ++ )
36+ {
37+ int bufferIndex = 0 ;
38+ if ( line [ i ] == '\" ' )
39+ {
40+ int closingQuoteIndex = IndexOf ( line , '\" ' , i + 1 ) ;
41+ for ( int a = i + 1 ; a < closingQuoteIndex ; a ++ )
42+ {
43+ buffer [ bufferIndex ] = line [ a ] ;
44+ ++ bufferIndex ;
45+ }
46+ i = closingQuoteIndex ;
47+ }
48+ else if ( line [ i ] == ',' )
49+ {
50+ String tmp = "" ;
51+ foreach ( char c in buffer )
52+ tmp += c ;
53+ Value value = new Value ( tmp ) ;
54+ row . AddValue ( value ) ;
55+ }
56+ else
57+ {
58+ buffer [ bufferIndex ] = line [ i ] ;
59+ ++ bufferIndex ;
60+ }
61+ }
62+ if ( index == 0 )
63+ doc . SetHeader ( row ) ;
64+ else
65+ doc . AddRow ( row ) ;
66+ ++ index ;
67+ }
68+
3069 }
3170
32- public List < Row > GetValues ( )
71+ //returns the index of the first occurrence of the spacified element
72+ private int IndexOf ( char [ ] array , char element , int startingIndex = 0 )
3373 {
34-
35- return new List < Row > ( ) ; //temporary
74+ for ( int i = startingIndex ; i < array . Length ; i ++ )
75+ {
76+ if ( array [ i ] == element )
77+ return i ;
78+ }
79+ return - 1 ;
3680 }
3781 }
3882}
You can’t perform that action at this time.
0 commit comments