Hi SKILL experts,
I am trying to parse a CSV file and populate this data into a hash table. The CSV file could possibly have empty cells. If any of the first 7 columns for a given row in the CSV file is empty, the parser should stop and not write the data to the hash table.Although when the line is read from the CSV file and written to a list, an empty cell is recognized as highlighted below:
before parsing :"PCB Rules, SilkScreen Checks,SilkText to Exposed Pad Spacing,,Text to exposed ViaPad Spacing on Top Layer,axlformbmp1.bmp,silktxt_exposed-spacing.txt,MIN_TXT_TO_VIAPAD_TOP_DIST,FLOAT,1,,,"
After parsing the line using parseString(_line “,”) , the output is as follows. The empty cell is not being detected:
after parsing :("PCB Rules" " SilkScreen Checks" "SilkText to Exposed Pad Spacing" "Text to exposed ViaPad Spacing on Top Layer" "axlformbmp1.bmp""silktxt_exposed-spacing.txt" "MIN_TXT_TO_VIAPAD_TOP_DIST""FLOAT" "1")
My code snippet is as follows. Please let me know of any other string parsing function in SKILL which can detect spaces (empty cells read from CSV file). Or if I can use a combination of comma and spaces (more than 2) as ‘breakCharacters’.
_returnLine = nil
_lineCount = 1
when(_inFile
while(gets(_newData _inFile)
when(_newData !="\n" && _lineCount > 1
_returnLine = ()
;; read each line from the csv file into a string
_textLine = car(parseString(_newData "\n"))
printf("\nbefore parsing :%L" _textLine)
;; parse the string with comma as the separator
_returnLine = parseString(_textLine ",")
printf("\nafter parsing :%L" _returnLine)
;; read the parsed fields
_ruleType = nth(0 _returnLine)
_category = nth(1 _returnLine)
_workbook = nth(2 _returnLine)
_ruleFile = nth(3 _returnLine)
_ruleName = nth(4 _returnLine)
_bitmap = nth(5 _returnLine)
_document = nth(6 _returnLine)
;; populate the hash table only if the first 7 columns for each row are not empty
if( (_ruleType != " ") then
if( (nth(1 _returnLine) != " ") then
if( (nth(2 _returnLine) != " ") then
if( (nth(3 _returnLine) != " ") then
if( (nth(4 _returnLine) != " ") then
if( (nth(5 _returnLine) != " ") then
if( (nth(6 _returnLine) != " ") then
_rule->ruletype = nth(0 _returnLine)
_rule->category = nth(1 _returnLine)
_rule->workbook = nth(2 _returnLine)
_rule->ruleFile = nth(3 _returnLine)
_rule->ruleName = nth(4 _returnLine)
_rule->bitmap = nth(5 _returnLine)
_rule->document = nth(6 _returnLine)
)
)
)
)
)
)
)
;; insert this structure into hash table with rule name as key
ruleTable[nth(4 _returnLine)] = _rule
);when
;; move to next line
_lineCount = _lineCount + 1
);while
close(_inFile)
);when
Thanks,
Bindu