changeset 23350:0f18524973eb

Fix initial newline for disp() of cells (bug #50683). * ov-cell.h (octave_cell::print_name_tag): Overloaded function prototype. * ov-cell.cc (octave_cell::print_name_tag): Overload function to display name of variable before printing.. * ov-cell.cc (short_disp, save_ascii, save_binary): Correct comments.
author Rik <rik@octave.org>
date Wed, 05 Apr 2017 14:00:21 -0700
parents 4f07b4770eec
children 5ea6c6d0c2db
files libinterp/octave-value/ov-cell.cc libinterp/octave-value/ov-cell.h
diffstat 2 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-cell.cc	Wed Apr 05 11:58:21 2017 -0700
+++ b/libinterp/octave-value/ov-cell.cc	Wed Apr 05 14:00:21 2017 -0700
@@ -688,6 +688,25 @@
     }
 }
 
+bool
+octave_cell::print_name_tag (std::ostream& os, const std::string& name) const
+{
+  bool retval = false;
+
+  indent (os);
+
+  if (is_empty () || ndims () > 2)
+    os << name << " = ";
+  else
+    {
+      os << name << " =";
+      newline (os);
+      retval = true;
+    }
+
+  return retval;
+}
+
 void
 octave_cell::short_disp (std::ostream& os) const
 {
@@ -714,7 +733,7 @@
         {
           octave_value o_val = tmp.elem (i);
 
-          // Recurse to print sub-value.
+          // Recurse to save sub-value.
           bool b = save_text_data (os, o_val, CELL_ELT_TAG, false, 0);
 
           if (! b)
@@ -736,7 +755,7 @@
             {
               octave_value o_val = tmp.elem (i, j);
 
-              // Recurse to print sub-value.
+              // Recurse to save sub-value.
               bool b = save_text_data (os, o_val, CELL_ELT_TAG, false, 0);
 
               if (! b)
@@ -871,7 +890,7 @@
     {
       octave_value o_val = tmp.elem (i);
 
-      // Recurse to print sub-value.
+      // Recurse to save sub-value.
       bool b = save_binary_data (os, o_val, CELL_ELT_TAG, "", 0,
                                  save_as_floats);
 
--- a/libinterp/octave-value/ov-cell.h	Wed Apr 05 11:58:21 2017 -0700
+++ b/libinterp/octave-value/ov-cell.h	Wed Apr 05 14:00:21 2017 -0700
@@ -152,6 +152,8 @@
 
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
 
+  bool print_name_tag (std::ostream& os, const std::string& name) const;
+
   void short_disp (std::ostream& os) const;
 
   bool save_ascii (std::ostream& os);