time | Calls | line |
---|
< 0.001 | 30 | 1 | classdef TextVarOptsInputs < matlab.io.internal.FunctionInterface
|
| | 2 | %
|
| | 3 |
|
| | 4 | % Copyright 2018 The MathWorks, Inc.
|
| | 5 |
|
| | 6 | properties (Parameter)
|
| | 7 | %WHITESPACERULE
|
| | 8 | % Rules for dealing with leading and trailing whitespace when importing
|
| | 9 | % text data.
|
| | 10 | % 'trim' - (default) Any leading or trailing whitespace is removed from
|
| | 11 | % the text. Interior whitespace is unaffected.
|
| | 12 | %
|
| | 13 | % 'trimleading' - Only the leading whitespace will be removed.
|
| | 14 | %
|
| | 15 | % 'trimtrailing' - Only the trailing whitespace will be removed.
|
| | 16 | %
|
| | 17 | % 'preserve' - No whitespace will be removed.
|
| | 18 | %
|
| | 19 | % See also matlab.io.TextVariableImportOptions
|
| | 20 | WhitespaceRule = 'trim';
|
| | 21 | end
|
| | 22 |
|
| | 23 | methods
|
| | 24 | function obj = set.WhitespaceRule(obj,rhs)
|
| | 25 | obj.WhitespaceRule = validatestring(rhs,...
|
| | 26 | {'trim','trimleading','trimtrailing','preserve'});
|
| | 27 | end
|
| | 28 | end
|
| | 29 |
|
| | 30 | methods (Access = protected)
|
| | 31 | function val = setFillValue(~,val)
|
| | 32 | % Only accept cellstr with 1 char element.
|
| | 33 | val = convertCharsToStrings(val);
|
| | 34 |
|
| | 35 | if ~(isstring(val) && isscalar(val))
|
| | 36 | if isa(val,'missing') && isscalar(val)
|
| | 37 | val = string(missing);
|
| | 38 | return
|
| | 39 | end
|
| | 40 | error(message('MATLAB:textio:io:FillValueText'));
|
| | 41 | end
|
| | 42 | end
|
| | 43 |
|
| | 44 | function val = setType(obj,val)
|
| | 45 | try
|
| | 46 | val = validatestring(val,{'char','string'});
|
| | 47 | catch ME
|
| | 48 | import matlab.io.internal.supportedTypeNames
|
| | 49 | if strcmp(ME.identifier,'MATLAB:unrecognizedStringChoice') && any(strcmp(supportedTypeNames,val))
|
| | 50 | % additional information to help with debugging
|
| | 51 | newMsg = ['\n\n',getString(message('MATLAB:textio:io:Setdatatype')), '\n', ...
|
| | 52 | getString(message('MATLAB:textio:io:SetvartypeSyntax',obj.Name,val))];
|
| | 53 | throw(MException('MATLAB:unrecognizedStringChoice',[ME.message, newMsg]));
|
| | 54 | end
|
| | 55 | throw(ME);
|
| | 56 | end
|
| | 57 | end
|
| | 58 |
|
| | 59 | function val = getType(~,val)
|
| | 60 | if isempty(val), val = 'char';end
|
| | 61 | end
|
| | 62 |
|
| | 63 | function val = getFillValue(obj,val)
|
| | 64 | if isnumeric(val) % default []
|
| | 65 | switch obj.Type
|
| | 66 | case 'char'
|
| | 67 | val = '';
|
| | 68 | case 'string'
|
| | 69 | val = string(missing);
|
| | 70 | end
|
| | 71 | else
|
| | 72 | switch obj.Type
|
| | 73 | case 'char'
|
| | 74 | val = convertStringsToChars(val);
|
| | 75 | case 'string'
|
| | 76 | val = convertCharsToStrings(val);
|
| | 77 | end
|
| | 78 | end
|
| | 79 | end
|
| | 80 | end
|
| | 81 | end
|
| | 82 |
|
| | 83 |
|