Code covered by the BSD License  

Highlights from
Error-tolerant parsing of newline-delimited data

Error-tolerant parsing of newline-delimited data

by

 

Adaptive parsing of newline-separated data. Handles bad lines WITHOUT reading line-by-line.

adaptive_parse_appender_demo(parsed,thisChunkParsed,parsedPtrs,appendOptions)
function [parsed,parsedPtrs] = adaptive_parse_appender_demo(parsed,thisChunkParsed,parsedPtrs,appendOptions)
% adaptive_parse_appender_demo.m--Appending function for demonstrating use
% of adaptive_parse().
%
% The "appendOptions" input argument is not used in this demo function, but
% it MUST appear in the function declaration.
%
% Syntax: [parsed,parsedPtrs] = adaptive_parse_appender_demo(parsed,thisChunkParsed,parsedPtrs,appendOptions)

% Developed in Matlab 7.11.0.584 (R2010b) on GLNX86.
% Kevin Bartlett (kpb@uvic.ca), 2011-03-22 10:46
%-------------------------------------------------------------------------

% Append the new data.
fieldNames = fieldnames(thisChunkParsed);

for iField = 1:length(fieldNames)
    thisFieldName = fieldNames{iField};
    thisFieldLength = length(thisChunkParsed.(thisFieldName));
    thisFieldStartPtr = parsedPtrs.(thisFieldName)+1;
    thisFieldEndPtr = thisFieldStartPtr +(thisFieldLength-1);
    parsed.(thisFieldName)(thisFieldStartPtr:thisFieldEndPtr) = thisChunkParsed.(thisFieldName);
    parsedPtrs.(thisFieldName) = thisFieldEndPtr;
end % for

Contact us