www.gusucode.com > external 工具箱matlab源码程序 > external/interfaces/webservices/http/+matlab/+net/+http/+internal/fieldParser.m
function res = fieldParser(value, field, parseElement, ... allowsArray, useStringMatrix, varargin) % fieldParser implements the behavior of matlab.net.http.HeaderField.parseField to % parse a comma-separated list of strings comprising in a header field value and % return a MATLAB type. It is factored out here so it can be used to parse an % input value for a HeaderField value, for the purpose of verifying that it is % semantically correct. This throws exceptions if the value could not be parsed. % % value the value to be parsed % field the HeaderField object for which it is being parsed % parseElement handle to field.parseElement() % allowsArray value returned by field.allowsArray() % useStringMatrix value returned by field.useStringMatrix() % varargin can be empty or % arrayDelims, structDelims, structFields[, custom] % arrayDelims, parser[, custom] % parameters, as per parseField % % FOR INTERNAL USE ONLY -- This function is intentionally undocumented % and is intended for use only within the scope of functions and classes % in toolbox/matlab/external/interfaces/webservices/http. Its behavior % may change, or the function itself may be removed in a future release. % Copyright 2015-2016 The MathWorks, Ince. args = varargin; if ~isempty(args) && islogical(args{end}) % strip off the custom arg for the purposes of looking at the other varargs args(end) = []; end nargs = length(args); if nargs == 0 arrayDelims = ','; else arrayDelims = args{1}; if nargs == 2 && isa(args{2},'function_handle') parser = args{2}; end end % set the parser to the field's parseElement function if ~exist('parser','var') % don't pass in arrayDelims, but pass in the custom parameter, if any parser = @(elem)parseElement(field, elem, varargin{2:end}); end if isempty(value) res = parser([]); elseif allowsArray && (~isempty(arrayDelims) || ischar(arrayDelims)) % Split the field into array elements elements = matlab.net.http.internal.delimSplit(... strtrim(value), arrayDelims); res = arrayfun(@(elem)parser(strtrim(elem)), elements, ... 'UniformOutput', false); if isscalar(res) % if result is a single element, extract from its cell res = res{1}; end else res = parser(strtrim(value)); end if ~isempty(res) && ~isscalar(res) if nargs < 2 sd = ''; sf = []; elseif nargs < 3 sd = args{2}; sf = []; else sd = args{2}; sf = args{3}; end stringParser = @(v)parseElement(field, v, sd, sf); if useStringMatrix res = matlab.net.http.internal.concatMatrices(res, stringParser); else res = matlab.net.http.internal.concatStructs(res, stringParser); end end end