changeset 29703:777c16616c40

Make disp() Matlab-compatible for scalar struct variables (bug #60643). * ov-struct.cc (octave_struct::print_raw): Use parentheses around initialization of variable "max_depth_reached" with a conditional for readability. * ov-struct.cc (octave_scaler_struct::print_raw): Use parentheses around initialization of variable "max_depth_reached" with a conditional for readability. Delete code to print tag "scalar structure containing the fields:". * ov-struct.cc (octave_scaler_struct::print_name_tag): Add code to print tag "scalar struct containing the fields:".
author Rik <rik@octave.org>
date Tue, 25 May 2021 09:15:29 -0700
parents 3a684b0e7406
children 887410ef55aa
files libinterp/octave-value/ov-struct.cc
diffstat 1 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.cc	Mon May 24 18:39:30 2021 -0400
+++ b/libinterp/octave-value/ov-struct.cc	Tue May 25 09:15:29 2021 -0700
@@ -602,10 +602,10 @@
 
   if (Vstruct_levels_to_print >= 0)
     {
-      bool max_depth_reached = Vstruct_levels_to_print-- == 0;
-
-      bool print_fieldnames_only
-        = (max_depth_reached || ! Vprint_struct_array_contents);
+      bool max_depth_reached = (Vstruct_levels_to_print-- == 0);
+
+      bool print_fieldnames_only = (max_depth_reached
+                                    || ! Vprint_struct_array_contents);
 
       increment_indent_level ();
 
@@ -1320,18 +1320,11 @@
 
   if (Vstruct_levels_to_print >= 0)
     {
-      bool max_depth_reached = Vstruct_levels_to_print-- == 0;
+      bool max_depth_reached = (Vstruct_levels_to_print-- == 0);
 
       bool print_fieldnames_only = max_depth_reached;
 
       increment_indent_level ();
-
-      indent (os);
-      os << "scalar structure containing the fields:";
-      newline (os);
-      if (! Vcompact_format)
-        newline (os);
-
       increment_indent_level ();
 
       string_vector key_list = map.fieldnames ();
@@ -1382,6 +1375,16 @@
       if (! Vcompact_format)
         newline (os);
 
+      increment_indent_level ();
+
+      indent (os);
+      os << "scalar structure containing the fields:";
+      newline (os);
+      if (! Vcompact_format)
+        newline (os);
+
+      decrement_indent_level ();
+
       retval = true;
     }