Mercurial > octave
changeset 24474:0b65949870e3
isstring.m: Add new function for identifying string arrays.
* scripts/strings/isstring.m: New function. Always returns false since Octave
does not implement string arrays.
* scripts/strings/module.mk: Add isstring.m to build system.
* NEWS: Announce new function.
* strings.txi: Add DOCSTRING entry for isstring to manual.
Rewrite how to distinguish a string (1xN char vector) from a char array.
* data.cc (Fislogical, Fisinteger, Fiscomplex, Fisfloat, Fisnumeric):
Add isstring to @seealso links.
* strfns.cc (Fischar): Add isstring to @seealso links.
* ov-cell.cc (Fiscellstr): Add isstring to @seealso links.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 27 Dec 2017 11:22:26 -0800 |
parents | 42d099b841aa |
children | 8cb985e362f3 |
files | NEWS doc/interpreter/strings.txi libinterp/corefcn/data.cc libinterp/corefcn/strfns.cc libinterp/octave-value/ov-cell.cc scripts/strings/isstring.m scripts/strings/module.mk |
diffstat | 7 files changed, 71 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Wed Dec 27 08:59:41 2017 -0800 +++ b/NEWS Wed Dec 27 11:22:26 2017 -0800 @@ -100,6 +100,7 @@ integral2 integral3 isgraphics + isstring openvar quad2d repelem
--- a/doc/interpreter/strings.txi Wed Dec 27 08:59:41 2017 -0800 +++ b/doc/interpreter/strings.txi Wed Dec 27 11:22:26 2017 -0800 @@ -177,19 +177,21 @@ @DOCSTRING(ischar) -To test if an object is a string (i.e., a character vector and not a character -matrix) you can use the @code{ischar} function in combination with the -@code{isvector} function as in the following example: +@DOCSTRING(isstring) + +To test if an object is a string (i.e., a 1xN row vector of characters +and not a character matrix) you can use the @code{ischar} function in +combination with the @code{isrow} function as in the following example: @example @group ischar (collection) @result{} 1 -ischar (collection) && isvector (collection) +ischar (collection) && isrow (collection) @result{} 0 -ischar ("my string") && isvector ("my string") +ischar ("my string") && isrow ("my string") @result{} 1 @end group @end example
--- a/libinterp/corefcn/data.cc Wed Dec 27 08:59:41 2017 -0800 +++ b/libinterp/corefcn/data.cc Wed Dec 27 11:22:26 2017 -0800 @@ -3102,7 +3102,7 @@ @deftypefn {} {} islogical (@var{x}) @deftypefnx {} {} isbool (@var{x}) Return true if @var{x} is a logical object. -@seealso{isfloat, isinteger, ischar, isnumeric, isa} +@seealso{ischar, isfloat, isinteger, isstring, isnumeric, isa} @end deftypefn */) { if (args.length () != 1) @@ -3134,7 +3134,7 @@ Note that @w{@code{isinteger (14)}} is false because numeric constants in Octave are double precision floating point values. -@seealso{isfloat, ischar, islogical, isnumeric, isa} +@seealso{isfloat, ischar, islogical, isstring, isnumeric, isa} @end deftypefn */) { if (args.length () != 1) @@ -3189,7 +3189,7 @@ doc: /* -*- texinfo -*- @deftypefn {} {} iscomplex (@var{x}) Return true if @var{x} is a complex-valued numeric object. -@seealso{isreal, isnumeric, islogical, ischar, isfloat, isa} +@seealso{isreal, isnumeric, ischar, isfloat, islogical, isstring, isa} @end deftypefn */) { if (args.length () != 1) @@ -3204,7 +3204,7 @@ Return true if @var{x} is a floating-point numeric object. Objects of class double or single are floating-point objects. -@seealso{isinteger, ischar, islogical, isnumeric, isa} +@seealso{isinteger, ischar, islogical, isnumeric, isstring, isa} @end deftypefn */) { if (args.length () != 1) @@ -3565,7 +3565,7 @@ complex array. Logical and character arrays are not considered to be numeric. -@seealso{isinteger, isfloat, isreal, iscomplex, islogical, ischar, iscell, isstruct, isa} +@seealso{isinteger, isfloat, isreal, iscomplex, ischar, islogical, isstring, iscell, isstruct, isa} @end deftypefn */) { if (args.length () != 1)
--- a/libinterp/corefcn/strfns.cc Wed Dec 27 08:59:41 2017 -0800 +++ b/libinterp/corefcn/strfns.cc Wed Dec 27 11:22:26 2017 -0800 @@ -286,7 +286,7 @@ doc: /* -*- texinfo -*- @deftypefn {} {} ischar (@var{x}) Return true if @var{x} is a character array. -@seealso{isfloat, isinteger, islogical, isnumeric, iscellstr, isa} +@seealso{isfloat, isinteger, islogical, isnumeric, isstring, iscellstr, isa} @end deftypefn */) { if (args.length () != 1)
--- a/libinterp/octave-value/ov-cell.cc Wed Dec 27 08:59:41 2017 -0800 +++ b/libinterp/octave-value/ov-cell.cc Wed Dec 27 11:22:26 2017 -0800 @@ -1269,7 +1269,7 @@ @deftypefn {} {} iscellstr (@var{cell}) Return true if every element of the cell array @var{cell} is a character string. -@seealso{ischar} +@seealso{ischar, isstring} @end deftypefn */) { if (args.length () != 1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/strings/isstring.m Wed Dec 27 11:22:26 2017 -0800 @@ -0,0 +1,55 @@ +## Copyright (C) 2017 Rik Wehbring +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {} {} isstring (@var{x}) +## Return true if @var{x} is a string array. +## +## A string array is a data type that stores strings (row vectors of characters) +## at each element in the array. It is distinct from character arrays which +## are N-dimensional arrays where each element is a single 1x1 character. It +## is also distinct from cell arrays of strings which store strings at each +## element, but use cell indexing @samp{@{@}} to access elements rather than +## string arrays which use ordinary array indexing @samp{()}. +## +## Programming Note: Octave does not yet implement string arrays so this +## function will always return false. +## @seealso{ischar, iscellstr, isfloat, isinteger, islogical, isnumeric, isa} +## @end deftypefn + +function retval = isstring (s) + + if (nargin != 1) + print_usage (); + endif + + retval = false; + +endfunction + + +%!assert (isstring ([]), false) +%!assert (isstring (1), false) +%!assert (isstring ('a'), false) +## FIXME: when string arrays are implemented, this should return true. +#%!assert (isstring ("b"), true) +%!assert (isstring ({'a'}), false) +%!assert (isstring ({"b"}), false) + +%!error isstring () +%!error isstring ("a", "b")
--- a/scripts/strings/module.mk Wed Dec 27 08:59:41 2017 -0800 +++ b/scripts/strings/module.mk Wed Dec 27 11:22:26 2017 -0800 @@ -14,6 +14,7 @@ %reldir%/hex2dec.m \ %reldir%/index.m \ %reldir%/isletter.m \ + %reldir%/isstring.m \ %reldir%/isstrprop.m \ %reldir%/mat2str.m \ %reldir%/native2unicode.m \