-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsafeInputParser.m
37 lines (27 loc) · 1.23 KB
/
safeInputParser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
classdef safeInputParser < inputParser
methods
function parse(self,varargin)
parse@inputParser(self);
defaults = self.Results;
isSuccessful = false;
while ~isSuccessful
try
parse@inputParser(self,varargin{:});
isSuccessful = true;
catch err
param = regexp(err.message,'The value of ''(.+)'' is invalid','tokens');
if isempty(param)
error(err);
end
param = param{1}{1};
valueIndex = find(strcmpi(param,varargin))+1;
if varargin{valueIndex} == defaults.(param)
error('The default value for %s doesn''t pass validation, you dumbass',param);
end
warning('Invalid value supplied for %s, using default value',param);
varargin{valueIndex} = defaults.(param);
end
end
end
end
end