time | Calls | line |
|---|
| | 16 | function str = jstring2string(jstr)
|
| | 17 | % Convert a Java string vector or scalar into a string vector. Input may be
|
| | 18 | % null, or may have null elements, which get converted to <missing>.
|
< 0.001 | 1 | 19 | if isempty(jstr)
|
| | 20 | str = string(NaN);
|
< 0.001 | 1 | 21 | else
|
| | 22 | % we don't have a builtin to directly convert a Java String scalar or
|
| | 23 | % vector to a string, but we can convert it to a cell array of chars.
|
< 0.001 | 1 | 24 | cel = cell(jstr);
|
< 0.001 | 1 | 25 | if ~iscellstr(cel)
|
| | 26 | % If it's not a cellstr, it's because it had [] cells where
|
| | 27 | % the input had nulls, so convert one cell at a time.
|
| | 28 | str(length(cel)) = string(NaN); % preallocate with <missing>
|
| | 29 | for i = 1 : length(cel)
|
| | 30 | ch = cel{i};
|
| | 31 | if ischar(ch)
|
| | 32 | % if not char, it must be [] which stays <missing>
|
| | 33 | str(i) = string(ch);
|
| | 34 | end
|
| | 35 | end
|
< 0.001 | 1 | 36 | else
|
| | 37 | % convert the cellstr to a string all at once
|
< 0.001 | 1 | 38 | str = string(cel);
|
< 0.001 | 1 | 39 | end
|
< 0.001 | 1 | 40 | end
|
< 0.001 | 1 | 41 | end
|
Other subfunctions in this file are not included in this listing.