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
Branches
Tags
No related merge requests found
...@@ -37,7 +37,6 @@ tomlini = false; ...@@ -37,7 +37,6 @@ tomlini = false;
%% Initialize variables required for processing %% Initialize variables required for processing
tomlini = {}; tomlini = {};
currentSectionName = '';
% File specific characters required for processing % File specific characters required for processing
reservedCharacters = struct( ... reservedCharacters = struct( ...
...@@ -86,7 +85,7 @@ for i = 1:length(allSections) ...@@ -86,7 +85,7 @@ for i = 1:length(allSections)
switch determineParseType(content) switch determineParseType(content)
case 'matrix' case 'matrix'
tomlini.(title) = parseAsMatrix(content); tomlini.(title) = parseAsMatrix(content, title);
case 'struct' case 'struct'
tomlini.(title) = parseAsStruct(content); tomlini.(title) = parseAsStruct(content);
case 'cell' case 'cell'
...@@ -147,7 +146,7 @@ end ...@@ -147,7 +146,7 @@ end
lines = splitlines(pContent); lines = splitlines(pContent);
returnContent = struct(); returnContent = struct();
for i = 1:length(lines) for i = 1:length(lines)
if (isComment(lines{i})) if (isComment(lines{i}) || isempty(lines{i}))
continue continue
end end
[line, comment] = extractValueAndComment(lines{i}); [line, comment] = extractValueAndComment(lines{i});
...@@ -172,10 +171,12 @@ end ...@@ -172,10 +171,12 @@ end
end end
end end
function [ matrix ] = parseAsMatrix(pContent) function [ matrix ] = parseAsMatrix(pContent, pTitle)
lines = splitlines(pContent); lines = splitlines(pContent);
%matrix = [];
columnCount = 0;
for i = 1:length(lines) for i = 1:length(lines)
if (isComment(lines{i})) if (isComment(lines{i}) || isempty(lines{i}))
continue continue
end end
% cut rest of line if a comment character is available % cut rest of line if a comment character is available
...@@ -187,12 +188,18 @@ end ...@@ -187,12 +188,18 @@ end
% remove empty cells % remove empty cells
lineAsCell = lineAsCell(~cellfun('isempty', lineAsCell)); lineAsCell = lineAsCell(~cellfun('isempty', lineAsCell));
lineAsDouble = str2double(lineAsCell); lineAsDouble = str2double(lineAsCell);
if any(isnan(lineAsDouble))
break;
end
if i == 1 if i == 1
matrix = lineAsDouble; matrix = lineAsDouble;
columnCount = length(lineAsDouble);
else 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]; matrix = [matrix; lineAsDouble];
end end
end end
...@@ -202,7 +209,7 @@ end ...@@ -202,7 +209,7 @@ end
lines = splitlines(pContent); lines = splitlines(pContent);
cell = {}; cell = {};
for i = 1:length(lines) for i = 1:length(lines)
if (isComment(lines{i})) if (isComment(lines{i}) || isempty(lines{i}))
continue continue
end end
[line, comment] = extractValueAndComment(lines{i}); [line, comment] = extractValueAndComment(lines{i});
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment