@@ -46,31 +46,6 @@ private static string DateMaskStandardToCstr(string mask)
46
46
return mask ;
47
47
}
48
48
49
- /// <summary>
50
- /// Get list of widths fixed width
51
- /// </summary>
52
- /// <param name="csvdef"> csvdefinition </param>
53
- /// <param name="abspos"> absolute column positions or column widths</param>
54
- private static string GetColumnWidths ( CsvDefinition csvdef , bool abspos )
55
- {
56
- var res = ( abspos ? "0, " : "" ) ;
57
- var colwidth = 0 ;
58
-
59
- for ( int c = 0 ; c < csvdef . Fields . Count ; c ++ )
60
- {
61
- // next field
62
- if ( abspos ) {
63
- colwidth += csvdef . Fields [ c ] . MaxWidth ;
64
- } else {
65
- colwidth = csvdef . Fields [ c ] . MaxWidth ;
66
- }
67
- var comma = ( c < csvdef . Fields . Count - 1 ? ", " : "" ) ;
68
- res += string . Format ( "{0}{1}" , colwidth , comma ) ;
69
- }
70
-
71
- return res ;
72
- }
73
-
74
49
/// <summary>
75
50
/// Standard disclaimer for generated scripts
76
51
/// </summary>
@@ -106,7 +81,7 @@ public static void GenerateSchemaJSON(CsvDefinition csvdef)
106
81
// file format
107
82
jsonmeta . Append ( "\t \" dialect\" : {" ) ;
108
83
if ( csvdef . Separator == '\0 ' )
109
- jsonmeta . Append ( string . Format ( "\r \n \t \t \" columnpositions\" : [{0}]" , GetColumnWidths ( csvdef , true ) ) ) ;
84
+ jsonmeta . Append ( string . Format ( "\r \n \t \t \" columnpositions\" : [{0}]" , csvdef . GetColumnWidths ( true ) ) ) ;
110
85
else
111
86
jsonmeta . Append ( string . Format ( "\r \n \t \t \" delimiter\" : \" {0}\" " , separator ) ) ;
112
87
jsonmeta . Append ( string . Format ( ",\r \n \t \t \" header\" : \" {0}\" " , ( csvdef . ColNameHeader ? "true" : "false" ) ) ) ;
@@ -437,8 +412,8 @@ public static void GeneratePythonPanda(CsvDefinition csvdef)
437
412
if ( csvdef . Separator == '\0 ' )
438
413
{
439
414
// fixed width
440
- python . Append ( string . Format ( "# fixed width, positions {0}\r \n " , GetColumnWidths ( csvdef , true ) ) ) ;
441
- python . Append ( string . Format ( "col_widths = [{0}]\r \n " , GetColumnWidths ( csvdef , false ) ) ) ;
415
+ python . Append ( string . Format ( "# fixed width, positions {0}\r \n " , csvdef . GetColumnWidths ( true ) ) ) ;
416
+ python . Append ( string . Format ( "col_widths = [{0}]\r \n " , csvdef . GetColumnWidths ( false ) ) ) ;
442
417
python . Append ( string . Format ( "df = pd.read_fwf(filename, decimal='{0}'{1}{2}, dtype=col_types, widths=col_widths)\r \n \r \n " , r_dec , nameparam , col_dates ) ) ;
443
418
}
444
419
else
@@ -525,7 +500,7 @@ public static void GenerateSchemaIni(CsvDefinition csvdef)
525
500
526
501
// fixed width, also output absolute column positions
527
502
var colwidth = "" ;
528
- if ( csvdef . Separator == '\0 ' ) colwidth = string . Format ( "\r \n ; Fixed Length positions {0}\r \n " , GetColumnWidths ( csvdef , true ) ) ;
503
+ if ( csvdef . Separator == '\0 ' ) colwidth = string . Format ( "\r \n ; Fixed Length positions {0}\r \n " , csvdef . GetColumnWidths ( true ) ) ;
529
504
530
505
// also add filename
531
506
string FILE_NAME = Path . GetFileName ( notepad . GetCurrentFilePath ( ) ) ;
@@ -683,8 +658,8 @@ public static void GenerateRScript(CsvDefinition csvdef)
683
658
if ( csvdef . Separator == '\0 ' )
684
659
{
685
660
// fixed width
686
- rscript . Append ( string . Format ( "# fixed width, positions {0}\r \n " , GetColumnWidths ( csvdef , true ) ) ) ;
687
- rscript . Append ( string . Format ( "colWidths <- c({0})\r \n " , GetColumnWidths ( csvdef , false ) ) ) ;
661
+ rscript . Append ( string . Format ( "# fixed width, positions {0}\r \n " , csvdef . GetColumnWidths ( true ) ) ) ;
662
+ rscript . Append ( string . Format ( "colWidths <- c({0})\r \n " , csvdef . GetColumnWidths ( false ) ) ) ;
688
663
rscript . Append ( string . Format ( "df <- read.fwf(filename, {0}colClasses=colTypes, width=colWidths, stringsAsFactors=FALSE, comment.char='', header={1})\r \n \r \n " , nameparam , header ) ) ;
689
664
} else {
690
665
// character separated
@@ -999,4 +974,4 @@ public static void GeneratePowerShell(CsvDefinition csvdef)
999
974
}
1000
975
}
1001
976
}
1002
- }
977
+ }
0 commit comments