# HG changeset patch # User Rik # Date 1378863099 25200 # Node ID 3f0ed69d21c6d22b00a9259b9096df196c119858 # Parent 5e552cd9315a1cc4fba53d6f5a7d6bc844cc89cc Replace unnecessary instances of strncmp with strcmp. * scripts/optimization/optimget.m, scripts/plot/__gnuplot_drawnow__.m, scripts/plot/fill.m, scripts/plot/private/__go_draw_axes__.m, scripts/plot/private/__pie__.m, scripts/plot/private/__print_parse_opts__.m, scripts/plot/private/__quiver__.m, scripts/plot/private/__tight_eps_bbox__.m, scripts/plot/stairs.m, scripts/plot/uigetfile.m, scripts/strings/strsplit.m, scripts/strings/validatestring.m: Replace unnecessary instances of strncmp with strcmp. diff --git a/scripts/optimization/optimget.m b/scripts/optimization/optimget.m --- a/scripts/optimization/optimget.m +++ b/scripts/optimization/optimget.m @@ -33,7 +33,7 @@ endif opts = __all_opts__ (); - idx = strncmpi (opts, parname, numel (parname)); + idx = strncmpi (opts, parname, length (parname)); nmatch = sum (idx); diff --git a/scripts/plot/__gnuplot_drawnow__.m b/scripts/plot/__gnuplot_drawnow__.m --- a/scripts/plot/__gnuplot_drawnow__.m +++ b/scripts/plot/__gnuplot_drawnow__.m @@ -225,7 +225,7 @@ otherwise size_str = ""; endswitch - if ((strncmpi (term, "x11", 3) + if ((strcmp (term, "x11") && __gnuplot_has_feature__ ("x11_figure_position")) || (strcmpi (term, "windows") && __gnuplot_has_feature__ ("windows_figure_position"))) diff --git a/scripts/plot/fill.m b/scripts/plot/fill.m --- a/scripts/plot/fill.m +++ b/scripts/plot/fill.m @@ -94,7 +94,7 @@ hlist(end + 1, 1) = htmp; endfor - if (strncmp (old_nxtplt, "replace", 7)) + if (strcmp (old_nxtplt, "replace")) set (hax, "nextplot", old_nxtplt); endif diff --git a/scripts/plot/private/__go_draw_axes__.m b/scripts/plot/private/__go_draw_axes__.m --- a/scripts/plot/private/__go_draw_axes__.m +++ b/scripts/plot/private/__go_draw_axes__.m @@ -480,7 +480,7 @@ ## Check for facecolor interpolation for surfaces. doing_interp_color = ... - isfield (obj, "facecolor") && strncmp (obj.facecolor, "interp", 6); + isfield (obj, "facecolor") && strcmp (obj.facecolor, "interp"); switch (obj.type) case "image" @@ -547,10 +547,10 @@ withclause{data_idx} = sprintf ("with %s;", imagetype); case "line" - if (strncmp (obj.linestyle, "none", 4) + if (strcmp (obj.linestyle, "none") && (! isfield (obj, "marker") || (isfield (obj, "marker") - && strncmp (obj.marker, "none", 4)))) + && strcmp (obj.marker, "none")))) continue; endif data_idx++; @@ -643,7 +643,7 @@ if (! isnan (xcol) && ! isnan (ycol)) ## Is the patch closed or not - if (strncmp (obj.facecolor, "none", 4)) + if (strncmp (obj.facecolor, "none")) hidden_removal = false; else @@ -684,8 +684,8 @@ titlespec{local_idx} = ['title "' tmp '"']; endif if (isfield (obj, "facecolor")) - if ((strncmp (obj.facecolor, "flat", 4) - || strncmp (obj.facecolor, "interp", 6)) + if ((strcmp (obj.facecolor, "flat") + || strcmp (obj.facecolor, "interp")) && isfield (obj, "cdata")) if (ndims (obj.cdata) == 2 && (columns (obj.cdata) == nc @@ -702,7 +702,7 @@ else ccol = cdat; endif - if (strncmp (obj.facecolor, "flat", 4)) + if (strcmp (obj.facecolor, "flat")) if (isequal (size (ccol), [1, 3])) ## RGB Triplet color = ccol; @@ -718,7 +718,7 @@ r = max (1, min (r, rows (cmap))); color = cmap(r, :); endif - elseif (strncmp (obj.facecolor, "interp", 6)) + elseif (strcmp (obj.facecolor, "interp")) if (nd == 3 && numel (xcol) == 3) ccdat = ccol; if (! isvector (ccdat)) @@ -782,10 +782,10 @@ endif ## patch outline - if (!(strncmp (obj.edgecolor, "none", 4) - && (strncmp (obj.marker, "none", 4) - || (strncmp (obj.markeredgecolor, "none", 4) - && strncmp (obj.markerfacecolor, "none", 4))))) + if (!(strcmp (obj.edgecolor, "none") + && (strcmp (obj.marker, "none") + || (strcmp (obj.markeredgecolor, "none") + && strcmp (obj.markerfacecolor, "none"))))) data_idx++; is_image_data(data_idx) = false; @@ -806,8 +806,8 @@ ## treat them seperately. However, the below allow the scatter ## functions to work as expected, where only one of these values ## is set - if (strncmp (obj.edgecolor, "none", 4)) - if (strncmp (obj.markeredgecolor, "none", 4)) + if (strcmp (obj.edgecolor, "none")) + if (strcmp (obj.markeredgecolor, "none")) ec = obj.markerfacecolor; else ec = obj.markeredgecolor; @@ -816,8 +816,8 @@ ec = obj.edgecolor; endif - if ((strncmp (ec, "flat", 4) - || strncmp (ec, "interp", 6)) + if ((strcmp (ec, "flat") + || strcmp (ec, "interp")) && isfield (obj, "cdata")) if (ndims (obj.cdata) == 2 && (columns (obj.cdata) == nc @@ -834,7 +834,7 @@ else ccol = cdat; endif - if (strncmp (ec, "flat", 4)) + if (strcmp (ec, "flat")) if (numel (ccol) == 3) color = ccol; else @@ -844,7 +844,7 @@ color = "flat"; have_cdata(data_idx) = true; endif - elseif (strncmp (ec, "interp", 6)) + elseif (strcmp (ec, "interp")) if (numel (ccol) == 3) warning ("\"interp\" not supported, using 1st entry of cdata"); color = ccol(1,:); @@ -919,8 +919,8 @@ facesame = true; if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor") - && !strncmp (obj.markerfacecolor, "none", 4)) - if (strncmp (obj.markerfacecolor, "auto", 4) + && !strcmp (obj.markerfacecolor, "none")) + if (strcmp (obj.markerfacecolor, "auto") || ! isnumeric (obj.markerfacecolor) || (isnumeric (obj.markerfacecolor) && isequal (color, obj.markerfacecolor))) @@ -969,9 +969,9 @@ endif if (isfield (obj, "markeredgecolor") - && !strncmp (obj.markeredgecolor, "none", 4)) + && !strcmp (obj.markeredgecolor, "none")) if (facesame && !isempty (pt) - && (strncmp (obj.markeredgecolor, "auto", 4) + && (strcmp (obj.markeredgecolor, "auto") || ! isnumeric (obj.markeredgecolor) || (isnumeric (obj.markeredgecolor) && isequal (color, obj.markeredgecolor)))) @@ -1005,7 +1005,7 @@ if (!isempty (pt)) if (! mono) - if (strncmp (obj.markeredgecolor, "auto", 4)) + if (strcmp (obj.markeredgecolor, "auto")) colorspec = sprintf ("lc rgb \"#%02x%02x%02x\"", round (255*color)); elseif (isnumeric (obj.markeredgecolor) && ! mono) @@ -1102,8 +1102,8 @@ case "surface" view_map = true; - if (! (strncmp (obj.edgecolor, "none", 4) - && strncmp (obj.facecolor, "none", 4))) + if (! (strcmp (obj.edgecolor, "none") + && strcmp (obj.facecolor, "none"))) data_idx++; is_image_data(data_idx) = false; parametric(data_idx) = false; @@ -1175,12 +1175,12 @@ endif usingclause{data_idx} = sprintf ("record=%dx%d using ($1):($2):($3):($4)", ylen, xlen); - flat_interp_face = (strncmp (obj.facecolor, "flat", 4) - || strncmp (obj.facecolor, "interp", 6)); - flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) - || strncmp (obj.edgecolor, "interp", 6)); + flat_interp_face = (strcmp (obj.facecolor, "flat") + || strcmp (obj.facecolor, "interp")); + flat_interp_edge = (strcmp (obj.edgecolor, "flat") + || strcmp (obj.edgecolor, "interp")); - facecolor_none_or_white = (strncmp (obj.facecolor, "none", 4) + facecolor_none_or_white = (strcmp (obj.facecolor, "none") || (isnumeric (obj.facecolor) && all (obj.facecolor == 1))); hidden_removal = false; @@ -1211,11 +1211,11 @@ dord = "depthorder"; endif - if (flat_interp_face && strncmp (obj.edgecolor, "flat", 4)) + if (flat_interp_face && strcmp (obj.edgecolor, "flat")) fprintf (plot_stream, "set pm3d explicit at s %s %s corners2color c3;\n", interp_str, dord); elseif (!facecolor_none_or_white) - if (strncmp (obj.edgecolor, "none", 4)) + if (strcmp (obj.edgecolor, "none")) if (__gnuplot_has_feature__ ("transparent_surface") && isscalar (obj.facealpha)) fprintf (plot_stream, @@ -1274,7 +1274,7 @@ withclause{data_idx} = sprintf ("with %s linestyle %d", style{3}, data_idx); endif - if (withpm3d && strncmp (style {1}, "linespoints", 11)) + if (withpm3d && strcmp (style{1}, "linespoints")) if (isempty (zz)) len = 3 * xlen; zz = zeros (ylen, len); @@ -1831,8 +1831,8 @@ facesame = true; if (! isequal (pt, pt2) && isfield (obj, "markerfacecolor") - && !strncmp (obj.markerfacecolor, "none", 4)) - if (strncmp (obj.markerfacecolor, "auto", 4) + && !strcmp (obj.markerfacecolor, "none")) + if (strcmp (obj.markerfacecolor, "auto") || ! isnumeric (obj.markerfacecolor) || (isnumeric (obj.markerfacecolor) && isequal (color, obj.markerfacecolor))) @@ -1871,14 +1871,14 @@ endif endif if (isfield (obj, "markeredgecolor") - && !strncmp (obj.markeredgecolor, "none", 4)) + && !strcmp (obj.markeredgecolor, "none")) if (facesame && !isempty (pt) - && (strncmp (obj.markeredgecolor, "auto", 4) + && (strcmp (obj.markeredgecolor, "auto") || ! isnumeric (obj.markeredgecolor) || (isnumeric (obj.markeredgecolor) && isequal (color, obj.markeredgecolor)))) if (sidx == 1 && ((length (style {sidx}) == 5 - && strncmp (style {sidx}, "lines", 5)) || isempty (style {sidx}))) + && strncmp (style{sidx}, "lines", 5)) || isempty (style {sidx}))) if (! isempty (pt)) style {sidx} = strcat (style{sidx}, "points"); fprintf (plot_stream, " pointtype %s", pt); @@ -1901,7 +1901,7 @@ fprintf (plot_stream, "set style line %d default;\n", idx); fprintf (plot_stream, "set style line %d", idx); if (! mono) - if (strncmp (obj.markeredgecolor, "auto", 4)) + if (strcmp (obj.markeredgecolor, "auto")) fprintf (plot_stream, " linecolor rgb \"#%02x%02x%02x\"", round (255*color)); elseif (isnumeric (obj.markeredgecolor) && ! mono) @@ -1945,7 +1945,7 @@ pt = "6"; pt2 = "7"; if (isfield (obj, "markerfacecolor") - || strncmp (obj.markerfacecolor, "none", 4)) + || strcmp (obj.markerfacecolor, "none")) obj.markerfacecolor = "auto"; endif if (isfield (obj, "markersize")) diff --git a/scripts/plot/private/__pie__.m b/scripts/plot/private/__pie__.m --- a/scripts/plot/private/__pie__.m +++ b/scripts/plot/private/__pie__.m @@ -114,7 +114,7 @@ set (h, "clim", [1, len]); endif - if (strncmp (caller, "pie3", 4)) + if (strcmp (caller, "pie3")) ln = length (xn); zlvl = 0.35; sx = repmat (xoff + [0, -sind(xn), 0], [2, 1]); @@ -128,7 +128,7 @@ patch(xoff + [0, -sind(xn)], yoff + [0, cosd(xn)], zlvl * ones (1, ln + 1), i); text(xt, yt, zlvl, labels{i})]; - elseif (strncmp (caller, "pie", 3)) + elseif (strcmp (caller, "pie")) if (xt > 0) align = "left"; else @@ -145,10 +145,10 @@ addlistener (gca, "view", {@update_text_pos, hlist}); - if (strncmp (caller, "pie3", 4)) + if (strcmp (caller, "pie3")) axis ([-1.25, 1.25, -1.25, 1.25, -0.05, 0.4], "equal", "off"); view (-37.5, 30); - elseif (strncmp (caller, "pie", 3)) + elseif (strcmp (caller, "pie")) axis ([-1.5, 1.5, -1.5, 1.5], "square", "off"); endif endfunction diff --git a/scripts/plot/private/__print_parse_opts__.m b/scripts/plot/private/__print_parse_opts__.m --- a/scripts/plot/private/__print_parse_opts__.m +++ b/scripts/plot/private/__print_parse_opts__.m @@ -90,9 +90,9 @@ arg_st.force_solid = 1; elseif (strcmp (arg, "-dashed")) arg_st.force_solid = -1; - elseif (strncmp (arg, "-portrait", numel (arg))) + elseif (strncmp (arg, "-portrait", length (arg))) arg_st.orientation = "portrait"; - elseif (strncmp (arg, "-landscape", numel (arg))) + elseif (strncmp (arg, "-landscape", length (arg))) arg_st.orientation = "landscape"; elseif (strcmp (arg, "-loose")) arg_st.loose = true; @@ -122,14 +122,14 @@ arg_st.pstoedit_binary = arg{10:end}; elseif (strncmpi (arg, "-textalphabits=", 15)) n = find (arg == "="); - if (! isempty (n) && n == numel (arg) - 1 && ismember (arg(end), "124")) + if (! isempty (n) && n == numel (arg) - 1 && any (arg(end) == "124")) arg_st.ghostscript.antialiasing_textalphabits = str2num (arg(end)); else error ("print: improper syntax, or value, for TextAlphaBits"); endif elseif (strncmpi (arg, "-graphicsalphabits=", 19)) n = find (arg == "="); - if (! isempty (n) && n == numel (arg) - 1 && ismember (arg(end), "124")) + if (! isempty (n) && n == numel (arg) - 1 && any (arg(end) == "124")) arg_st.ghostscript.antialiasing_graphicsalphabits = str2num (arg(end)); else error ("print: improper syntax, or value, for GraphicsAlphaBits"); diff --git a/scripts/plot/private/__quiver__.m b/scripts/plot/private/__quiver__.m --- a/scripts/plot/private/__quiver__.m +++ b/scripts/plot/private/__quiver__.m @@ -81,14 +81,14 @@ args = {}; while (ioff <= nargin) arg = varargin{ioff++}; - if (ischar (arg) && strncmpi (arg, "filled", 6)) + if (ischar (arg) && strcmpi (arg, "filled")) have_filled = true; elseif ((ischar (arg) || iscell (arg)) && ! have_line_spec) [linespec, valid] = __pltopt__ ("quiver", arg, false); if (valid) have_line_spec = true; - if (strncmp (linespec.linestyle, "none", 4)) + if (strcmp (linespec.linestyle, "none")) linespec.linestyle = "-"; endif else @@ -228,7 +228,7 @@ if (have_line_spec) if (isfield (linespec, "marker") - && ! strncmp (linespec.marker, "none", 4)) + && ! strcmp (linespec.marker, "none")) if (is3d) h2 = plot3 ([xarrw1.'; xend.'; xarrw2.'; NaN(1, length (x))](:), [yarrw1.'; yend.'; yarrw2.'; NaN(1, length (y))](:), @@ -266,7 +266,7 @@ if (! have_line_spec || (isfield (linespec, "marker") - && strncmp (linespec.marker, "none", 4))) + && strcmp (linespec.marker, "none"))) if (is3d) h3 = plot3 (x, y, z, "linestyle", "none", "marker", "none", "parent", hg); diff --git a/scripts/plot/private/__tight_eps_bbox__.m b/scripts/plot/private/__tight_eps_bbox__.m --- a/scripts/plot/private/__tight_eps_bbox__.m +++ b/scripts/plot/private/__tight_eps_bbox__.m @@ -58,7 +58,7 @@ looking_for_bbox = true; while (looking_for_bbox) current_line = fgetl (fid); - if (strncmpi (current_line, box_string, numel (box_string))) + if (strncmpi (current_line, box_string, length (box_string))) line_length = numel (current_line); num_spaces = line_length - numel (tight_bbox_line); if (numel (current_line) >= numel (tight_bbox_line)) diff --git a/scripts/plot/uigetfile.m b/scripts/plot/uigetfile.m --- a/scripts/plot/uigetfile.m +++ b/scripts/plot/uigetfile.m @@ -103,9 +103,9 @@ val = varargin{i}; if (ischar (val)) val = tolower (val); - if (strncmp (val, "multiselect", 11)) + if (strcmp (val, "multiselect")) idx1 = i; - elseif (strncmp (val, "position", 8)) + elseif (strcmp (val, "position")) idx2 = i; endif endif @@ -168,13 +168,13 @@ for i = stridx : 2 : nargin prop = varargin{i}; val = varargin{i + 1}; - if (strncmp (tolower (prop), "position", 8)) + if (strcmpi (prop, "position")) if (ismatrix (val) && length (val) == 2) outargs{4} = val; else error ("uigetfile: expecting 2-element vector for position argument"); endif - elseif (strncmp (tolower (prop), "multiselect", 11)) + elseif (strcmpi (prop, "multiselect", 11)) if (ischar (val)) outargs{5} = tolower (val); else diff --git a/scripts/strings/strsplit.m b/scripts/strings/strsplit.m --- a/scripts/strings/strsplit.m +++ b/scripts/strings/strsplit.m @@ -160,7 +160,7 @@ endif ## Save the length of the "delimitertype" parameter - length_deltype = numel (args.delimitertype); + length_deltype = length (args.delimitertype); if (nargin == 1 || (nargin > 1 && (islogical (del) || isnumeric (del)))) if (nargin > 1) @@ -168,7 +168,7 @@ args.collapsedelimiters = del; endif ## Set proper default for the delimiter type - if (strncmpi (args.delimitertype, "simple", numel (args.delimitertype))) + if (strncmpi (args.delimitertype, "simple", length (args.delimitertype))) del = {" ","\f","\n","\r","\t","\v"}; else del = "\\s"; diff --git a/scripts/strings/validatestring.m b/scripts/strings/validatestring.m --- a/scripts/strings/validatestring.m +++ b/scripts/strings/validatestring.m @@ -52,7 +52,7 @@ ## blue, black ## @end group ## @end smallexample -## +## ## @seealso{strcmp, strcmpi} ## @end deftypefn @@ -70,7 +70,7 @@ position = varargin{end}; varargin(end) = []; endif - + funcname = varname = ""; char_idx = cellfun ("isclass", varargin, "char"); n_chararg = sum (char_idx); @@ -112,7 +112,7 @@ errstr(end:end+1) = ":\n"; endif - matches = strncmpi (str, strarray(:), numel (str)); + matches = strncmpi (str, strarray(:), length (str)); nmatches = sum (matches); if (nmatches == 0) error ("validatestring: %s'%s' does not match any of\n%s", errstr, str, @@ -124,9 +124,9 @@ ## If true, choose the shortest. If not, raise an error. match_idx = find (matches); match_len = cellfun ("length", strarray(match_idx)); - [min_len, min_idx] = min (match_len); + [min_len, min_idx] = min (match_len); short_str = strarray{match_idx(min_idx)}; - submatch = strncmpi (short_str, strarray(match_idx), min_len); + submatch = strncmpi (short_str, strarray(match_idx), min_len); if (all (submatch)) str = short_str; else