From f03bf0a615a652fbb960a99342c3423100e5ea24 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Mon, 13 May 2013 17:47:11 +0200 Subject: [PATCH] reporting: preserve case when assigning method options while allowing user to enter any case --- matlab/reports/@graph/graph.m | 8 +++++--- matlab/reports/@page/page.m | 8 +++++--- matlab/reports/@report/report.m | 8 +++++--- matlab/reports/@section/section.m | 8 +++++--- matlab/reports/@series/series.m | 8 +++++--- matlab/reports/@table/table.m | 8 +++++--- matlab/reports/@vspace/vspace.m | 8 +++++--- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m index 16a6c74c82..4a0eaca538 100644 --- a/matlab/reports/@graph/graph.m +++ b/matlab/reports/@graph/graph.m @@ -73,13 +73,15 @@ elseif nargin > 1 'pairs.']); end - optNames = lower(fieldnames(o)); + optNames = fieldnames(o); % overwrite default values for pair = reshape(varargin, 2, []) field = lower(pair{1}); - if any(strmatch(field, optNames, 'exact')) - o.(field) = pair{2}; + ind = strmatch(field, lower(optNames), 'exact'); + assert(isempty(ind) || length(ind) == 1); + if ~isempty(ind) + o.(optNames{ind}) = pair{2}; else error('@graph.graph: %s is not a recognized option.', field); end diff --git a/matlab/reports/@page/page.m b/matlab/reports/@page/page.m index a0469e0ccc..5702dd4de2 100644 --- a/matlab/reports/@page/page.m +++ b/matlab/reports/@page/page.m @@ -48,13 +48,15 @@ elseif nargin > 1 'pairs.']); end - optNames = lower(fieldnames(o)); + optNames = fieldnames(o); % overwrite default values for pair = reshape(varargin, 2, []) field = lower(pair{1}); - if any(strmatch(field, optNames, 'exact')) - o.(field) = pair{2}; + ind = strmatch(field, lower(optNames), 'exact'); + assert(isempty(ind) || length(ind) == 1); + if ~isempty(ind) + o.(optNames{ind}) = pair{2}; else error('@page.page: %s is not a recognized option.', field); end diff --git a/matlab/reports/@report/report.m b/matlab/reports/@report/report.m index 9497ce9988..f4c4b70936 100644 --- a/matlab/reports/@report/report.m +++ b/matlab/reports/@report/report.m @@ -54,13 +54,15 @@ elseif nargin > 1 'pairs']); end - optNames = lower(fieldnames(o)); + optNames = fieldnames(o); % overwrite default values for pair = reshape(varargin, 2, []) field = lower(pair{1}); - if any(strmatch(field, optNames, 'exact')) - o.(field) = pair{2}; + ind = strmatch(field, lower(optNames), 'exact'); + assert(isempty(ind) || length(ind) == 1); + if ~isempty(ind) + o.(optNames{ind}) = pair{2}; else error('@report.report: %s is not a recognized option.', ... field); diff --git a/matlab/reports/@section/section.m b/matlab/reports/@section/section.m index ba2bc26624..aca48b8c18 100644 --- a/matlab/reports/@section/section.m +++ b/matlab/reports/@section/section.m @@ -36,13 +36,15 @@ elseif nargin > 1 'pairs.']); end - optNames = lower(fieldnames(o)); + optNames = fieldnames(o); % overwrite default values for pair = reshape(varargin, 2, []) field = lower(pair{1}); - if any(strmatch(field, optNames, 'exact')) - o.(field) = pair{2}; + ind = strmatch(field, lower(optNames), 'exact'); + assert(isempty(ind) || length(ind) == 1); + if ~isempty(ind) + o.(optNames{ind}) = pair{2}; else error('@section.section: %s is not a recognized option.', ... field); diff --git a/matlab/reports/@series/series.m b/matlab/reports/@series/series.m index 95f48562b2..fe5759a1b9 100644 --- a/matlab/reports/@series/series.m +++ b/matlab/reports/@series/series.m @@ -61,13 +61,15 @@ elseif nargin > 1 'pairs.']); end - optNames = lower(fieldnames(o)); + optNames = fieldnames(o); % overwrite default values for pair = reshape(varargin, 2, []) field = lower(pair{1}); - if any(strmatch(field, optNames, 'exact')) - o.(field) = pair{2}; + ind = strmatch(field, lower(optNames), 'exact'); + assert(isempty(ind) || length(ind) == 1); + if ~isempty(ind) + o.(optNames{ind}) = pair{2}; else error('@series.series: %s is not a recognized option.', field); end diff --git a/matlab/reports/@table/table.m b/matlab/reports/@table/table.m index 0692885989..0e8484238b 100644 --- a/matlab/reports/@table/table.m +++ b/matlab/reports/@table/table.m @@ -58,13 +58,15 @@ elseif nargin > 1 'pairs.']); end - optNames = lower(fieldnames(o)); + optNames = fieldnames(o); % overwrite default values for pair = reshape(varargin, 2, []) field = lower(pair{1}); - if any(strmatch(field, optNames, 'exact')) - o.(field) = pair{2}; + ind = strmatch(field, lower(optNames), 'exact'); + assert(isempty(ind) || length(ind) == 1); + if ~isempty(ind) + o.(optNames{ind}) = pair{2}; else error('%s is not a recognized option to the Table constructor.', ... field); diff --git a/matlab/reports/@vspace/vspace.m b/matlab/reports/@vspace/vspace.m index 4958c48be1..0af84127e1 100644 --- a/matlab/reports/@vspace/vspace.m +++ b/matlab/reports/@vspace/vspace.m @@ -44,13 +44,15 @@ elseif nargin > 1 'pairs.']); end - optNames = lower(fieldnames(o)); + optNames = fieldnames(o); % overwrite default values for pair = reshape(varargin, 2, []) field = lower(pair{1}); - if any(strmatch(field, optNames, 'exact')) - o.(field) = pair{2}; + ind = strmatch(field, lower(optNames), 'exact'); + assert(isempty(ind) || length(ind) == 1); + if ~isempty(ind) + o.(optNames{ind}) = pair{2}; else error('@vspace.vspace: %s is not a recognized option.', field); end -- GitLab