Skip to content
Snippets Groups Projects
Commit acec9c48 authored by leprob001's avatar leprob001
Browse files

Updated tomlini.m

  / If a line is empty, it is now being skipped.
  / parseAsMatrix now throws a warning if the line that is currently parsed
    differs from the first line column. The line will be skipped.
parent 5cc814e0
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,6 @@ tomlini = false;
%% Initialize variables required for processing
tomlini = {};
currentSectionName = '';
% File specific characters required for processing
reservedCharacters = struct( ...
......@@ -86,7 +85,7 @@ for i = 1:length(allSections)
switch determineParseType(content)
case 'matrix'
tomlini.(title) = parseAsMatrix(content);
tomlini.(title) = parseAsMatrix(content, title);
case 'struct'
tomlini.(title) = parseAsStruct(content);
case 'cell'
......@@ -147,7 +146,7 @@ end
lines = splitlines(pContent);
returnContent = struct();
for i = 1:length(lines)
if (isComment(lines{i}))
if (isComment(lines{i}) || isempty(lines{i}))
continue
end
[line, comment] = extractValueAndComment(lines{i});
......@@ -172,10 +171,12 @@ end
end
end
function [ matrix ] = parseAsMatrix(pContent)
function [ matrix ] = parseAsMatrix(pContent, pTitle)
lines = splitlines(pContent);
%matrix = [];
columnCount = 0;
for i = 1:length(lines)
if (isComment(lines{i}))
if (isComment(lines{i}) || isempty(lines{i}))
continue
end
% cut rest of line if a comment character is available
......@@ -187,12 +188,18 @@ end
% remove empty cells
lineAsCell = lineAsCell(~cellfun('isempty', lineAsCell));
lineAsDouble = str2double(lineAsCell);
if any(isnan(lineAsDouble))
break;
end
if i == 1
matrix = lineAsDouble;
columnCount = length(lineAsDouble);
else
if (length(lineAsDouble) ~= columnCount)
warning( ...
"Expecting " + num2str(columnCount) + " columns in line " + ...
num2str(i) + " of section " + pTitle + ", but found " + ...
num2str(length(lineAsDouble)) + " columns. Line is being skipped!" ...
);
continue;
end
matrix = [matrix; lineAsDouble];
end
end
......@@ -202,7 +209,7 @@ end
lines = splitlines(pContent);
cell = {};
for i = 1:length(lines)
if (isComment(lines{i}))
if (isComment(lines{i}) || isempty(lines{i}))
continue
end
[line, comment] = extractValueAndComment(lines{i});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment