StackOverflowMATLABchat / mlapp2classdef

Convert MATLAB App's XML file to *.m class definition
4 stars 5 forks source link

Regex removes characters following all end statements #1

Closed sco1 closed 8 years ago

sco1 commented 8 years ago

The second statement in the regexprep statement strips out characters following any end statement in the input file.

A = regexprep(A, '(^.*)(?=classdef)|(?<=end)(.*$)', '');

Though likely not generally an issue, this is a very greedy implementation and could potentially negatively affect the user's code.

sco1 commented 8 years ago

This is a holdover from the previous implementation (prior to initial commit), where the entire body of the XML file was loaded into a single character array and parsed. Because we're only looking to strip the header and footer, it was a robust enough approach to anchor the regexprep expressions to the beginning/end of the string.

The XML parsing was swapped to a fgetl approach into a cell array of strings to make writing the classdef to a *.m file simpler, as the previous approach did not pull in the appropriate line endings.