changeset 21021:a5b99b09f8fd

maint: Use comparison operators rather than compare() for strings. * graphics.cc, graphics.in.h, load-path.cc, ls-oct-text.cc, ls-oct-text.h, __init_fltk__.cc, oct-parse.in.yy, file-ops.cc: Use comparison operators rather than compare() for strings.
author Rik <rik@octave.org>
date Thu, 31 Dec 2015 13:39:25 -0800
parents 7ebc9f38b312
children ebc439187d29
files libinterp/corefcn/graphics.cc libinterp/corefcn/graphics.in.h libinterp/corefcn/load-path.cc libinterp/corefcn/ls-oct-text.cc libinterp/corefcn/ls-oct-text.h libinterp/dldfcn/__init_fltk__.cc libinterp/parse-tree/oct-parse.in.yy liboctave/system/file-ops.cc
diffstat 8 files changed, 32 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/graphics.cc	Thu Dec 31 12:01:01 2015 +0100
+++ b/libinterp/corefcn/graphics.cc	Thu Dec 31 13:39:25 2015 -0800
@@ -2022,7 +2022,7 @@
             {
               std::string sval = val.string_value ();
 
-              remove = (sval.compare ("remove") == 0);
+              remove = (sval == "remove");
             }
 
           pval_map_type& pval_map = plist_map[pfx];
@@ -2367,13 +2367,13 @@
 
       octave_value default_val;
 
-      if (sval.compare ("default") == 0)
+      if (sval == "default")
         {
           default_val = get_default (pname);
 
           rep->set (pname, default_val);
         }
-      else if (sval.compare ("factory") == 0)
+      else if (sval == "factory")
         {
           default_val = get_factory_default (pname);
 
@@ -2382,9 +2382,9 @@
       else
         {
           // Matlab specifically uses "\default" to escape string setting
-          if (sval.compare ("\\default") == 0)
+          if (sval == "\\default")
             rep->set (pname, "default");
-          else if (sval.compare ("\\factory") == 0)
+          else if (sval == "\\factory")
             rep->set (pname, "factory");
           else
             rep->set (pname, val);
@@ -3459,33 +3459,33 @@
 void
 root_figure::properties::update_units (void)
 {
-  caseless_str xunits = get_units ();
+  std::string xunits = get_units ();
 
   Matrix scrn_sz = default_screensize ();
 
   double dpi = get_screenpixelsperinch ();
 
-  if (xunits.compare ("inches"))
+  if (xunits == "inches")
     {
       scrn_sz(0) = 0;
       scrn_sz(1) = 0;
       scrn_sz(2) /= dpi;
       scrn_sz(3) /= dpi;
     }
-  else if (xunits.compare ("centimeters"))
+  else if (xunits == "centimeters")
     {
       scrn_sz(0) = 0;
       scrn_sz(1) = 0;
       scrn_sz(2) *= 2.54 / dpi;
       scrn_sz(3) *= 2.54 / dpi;
     }
-  else if (xunits.compare ("normalized"))
+  else if (xunits == "normalized")
     {
       scrn_sz = Matrix (1, 4, 1.0);
       scrn_sz(0) = 0;
       scrn_sz(1) = 0;
     }
-  else if (xunits.compare ("points"))
+  else if (xunits == "points")
     {
       scrn_sz(0) = 0;
       scrn_sz(1) = 0;
@@ -4109,8 +4109,8 @@
 void
 figure::properties::update_papertype (void)
 {
-  caseless_str typ = get_papertype ();
-  if (! typ.compare ("<custom>"))
+  std::string typ = get_papertype ();
+  if (typ != "<custom>")
     {
       Matrix sz = papersize_from_type (get_paperunits (), typ);
       if (get_paperorientation () == "landscape")
@@ -5593,9 +5593,9 @@
 {
   ColumnVector retval;
 
-  caseless_str to_units = props.get_units ();
-
-  if (! to_units.compare ("data"))
+  std::string to_units = props.get_units ();
+
+  if (to_units != "data")
     {
       ColumnVector v = xform.transform (p(0), p(1), p(2));
 
@@ -9372,9 +9372,9 @@
                                                                   data));
           else
             {
-              caseless_str busy_action (go.get_properties ().get_busyaction ());
-
-              if (busy_action.compare ("queue"))
+              std::string busy_action (go.get_properties ().get_busyaction ());
+
+              if (busy_action == "queue")
                 do_post_event (graphics_event::create_callback_event (h, name,
                                                                       data));
               else
--- a/libinterp/corefcn/graphics.in.h	Thu Dec 31 12:01:01 2015 +0100
+++ b/libinterp/corefcn/graphics.in.h	Thu Dec 31 13:39:25 2015 -0800
@@ -1970,7 +1970,7 @@
     const_iterator it;
 
     for (it = (*this).begin (); it != (*this).end (); it++)
-      if (pname.compare ((*it).first) == 0)
+      if (pname == (*it).first)
         return it;
 
     return (*this).end ();
@@ -1981,7 +1981,7 @@
     iterator it;
 
     for (it = (*this).begin (); it != (*this).end (); it++)
-      if (pname.compare ((*it).first) == 0)
+      if (pname == (*it).first)
         return it;
 
     return (*this).end ();
--- a/libinterp/corefcn/load-path.cc	Thu Dec 31 12:01:01 2015 +0100
+++ b/libinterp/corefcn/load-path.cc	Thu Dec 31 13:39:25 2015 -0800
@@ -1416,7 +1416,7 @@
 
           if (dname_len > dir_len
               && file_ops::is_dir_sep (dname[dname_len - dir_len - 1])
-              && dir.compare (dname.substr (dname_len - dir_len)) == 0)
+              && dir == dname.substr (dname_len - dir_len))
             {
               file_stat fs (p->dir_name);
 
@@ -1463,7 +1463,7 @@
 
           if (dname_len > dir_len
               && file_ops::is_dir_sep (dname[dname_len - dir_len - 1])
-              && dir.compare (dname.substr (dname_len - dir_len)) == 0)
+              && dir == dname.substr (dname_len - dir_len))
             {
               file_stat fs (p->dir_name);
 
--- a/libinterp/corefcn/ls-oct-text.cc	Thu Dec 31 12:01:01 2015 +0100
+++ b/libinterp/corefcn/ls-oct-text.cc	Thu Dec 31 13:39:25 2015 -0800
@@ -102,7 +102,7 @@
             buf << c;
 
           std::string tmp = buf.str ();
-          bool match = (tmp.compare (0, strlen (keyword), keyword) == 0);
+          bool match = (tmp.substr (0, strlen (keyword)) == keyword);
 
           if (match)
             {
--- a/libinterp/corefcn/ls-oct-text.h	Thu Dec 31 12:01:01 2015 +0100
+++ b/libinterp/corefcn/ls-oct-text.h	Thu Dec 31 13:39:25 2015 -0800
@@ -93,7 +93,7 @@
             buf << c;
 
           std::string tmp = buf.str ();
-          bool match = (tmp.compare (0, strlen (keyword), keyword) == 0);
+          bool match = (tmp.substr (0, strlen (keyword)) == keyword);
 
           if (match)
             {
--- a/libinterp/dldfcn/__init_fltk__.cc	Thu Dec 31 12:01:01 2015 +0100
+++ b/libinterp/dldfcn/__init_fltk__.cc	Thu Dec 31 13:39:25 2015 -0800
@@ -297,7 +297,7 @@
               menupath += "/";
             menupath += m->label ();
 
-            if (menupath.compare (findname) == 0)
+            if (menupath == findname)
               return (t);
           }
         else
@@ -318,7 +318,7 @@
               itempath += "/";
             itempath += m->label ();
 
-            if (itempath.compare (findname) == 0)
+            if (itempath == findname)
               return (t);
           }
       }
@@ -672,9 +672,9 @@
           }
       }
 
-    if (type.compare ("uimenu") == 0)
+    if (type == "uimenu")
       delete_entry (dynamic_cast<uimenu::properties&> (prop));
-    else if (type.compare ("figure") == 0)
+    else if (type == "figure")
       menubar->clear ();
   }
 
@@ -1591,7 +1591,7 @@
                         (ax_obj.get_properties ());
 
                       // Don't pan or rotate legend
-                      if (ap.get_tag ().compare ("legend") < 0)
+                      if (ap.get_tag () == "legend")
                         {
                           if (rotate_enabled ())
                             view2status (ax_obj);
--- a/libinterp/parse-tree/oct-parse.in.yy	Thu Dec 31 12:01:01 2015 +0100
+++ b/libinterp/parse-tree/oct-parse.in.yy	Thu Dec 31 13:39:25 2015 -0800
@@ -4419,7 +4419,7 @@
         autoload_map[argv[1]] = nm;
       else if (nargin == 3)
         {
-          if (argv[3].compare ("remove") != 0)
+          if (argv[3] != "remove")
             error_with_id ("Octave:invalid-input-arg",
                            "autoload: third argument can only be 'remove'");
 
--- a/liboctave/system/file-ops.cc	Thu Dec 31 12:01:01 2015 +0100
+++ b/liboctave/system/file-ops.cc	Thu Dec 31 13:39:25 2015 -0800
@@ -160,7 +160,7 @@
             {
               size_t pfx_len = prefixes[j].length ();
 
-              if (prefixes[j].compare (s.substr (i, pfx_len)) == 0)
+              if (prefixes[j] == s.substr (i, pfx_len))
                 {
                   len = pfx_len - 1;
                   return i + len;
@@ -195,7 +195,7 @@
             {
               size_t sfx_len = suffixes[j].length ();
 
-              if (suffixes[j].compare (s.substr (i, sfx_len)) == 0)
+              if (suffixes[j] == s.substr (i, sfx_len))
                 return i;
             }
         }