Mercurial > octave
diff libinterp/octave-value/ov-str-mat.cc @ 20962:3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Invert conditional in if statement and place error next to if.
Delete else, and decrease code indent by 4.
* cellfun.cc, data.cc, debug.cc, dirfns.cc, dynamic-ld.cc, file-io.cc,
gl2ps-renderer.cc, graphics.cc, graphics.in.h, hex2num.cc, load-save.cc,
ls-mat-ascii.cc, ls-oct-text.cc, oct-hist.cc, oct-lvalue.cc, oct-map.cc,
toplev.cc, __init_fltk__.cc, ov-base-int.cc, ov-bool-mat.cc, ov-cell.cc,
ov-class.cc, ov-classdef.cc, ov-cx-mat.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-oncleanup.cc, ov-re-mat.cc, ov-str-mat.cc, ov-struct.cc,
ov-usr-fcn.cc, ov.cc, pt-arg-list.cc, pt-assign.cc, pt-colon.cc, pt-eval.cc,
pt-exp.cc:
Invert conditional in if statement and place error next to if.
Delete else, and decrease code indent by 4.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 22 Dec 2015 10:29:22 -0800 |
parents | 850e3d2533d4 |
children | 0963ed389012 |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-str-mat.cc Tue Dec 22 07:43:44 2015 -0500 +++ b/libinterp/octave-value/ov-str-mat.cc Tue Dec 22 10:29:22 2015 -0800 @@ -344,118 +344,114 @@ std::string kw; int val = 0; - if (extract_keyword (is, keywords, kw, val, true)) + if (! extract_keyword (is, keywords, kw, val, true)) + error ("load: failed to extract number of rows and columns"); + + if (kw == "ndims") { - if (kw == "ndims") + int mdims = val; + + if (mdims >= 0) { - int mdims = val; + dim_vector dv; + dv.resize (mdims); + + for (int i = 0; i < mdims; i++) + is >> dv(i); - if (mdims >= 0) + if (! is) + error ("load: failed to read dimensions"); + + charNDArray tmp(dv); + + if (tmp.is_empty ()) + matrix = tmp; + else { - dim_vector dv; - dv.resize (mdims); + char *ftmp = tmp.fortran_vec (); + + skip_preceeding_newline (is); - for (int i = 0; i < mdims; i++) - is >> dv(i); + if (! is.read (ftmp, dv.numel ()) || ! is) + error ("load: failed to load string constant"); + else + matrix = tmp; + } + } + else + error ("load: failed to extract matrix size"); + } + else if (kw == "elements") + { + int elements = val; - if (is) + if (elements >= 0) + { + // FIXME: need to be able to get max length before doing anything. + + charMatrix chm (elements, 0); + int max_len = 0; + for (int i = 0; i < elements; i++) + { + int len; + if (extract_keyword (is, "length", len) && len >= 0) { - charNDArray tmp(dv); + // Use this instead of a C-style character + // buffer so that we can properly handle + // embedded NUL characters. + charMatrix tmp (1, len); + char *ptmp = tmp.fortran_vec (); - if (tmp.is_empty ()) - matrix = tmp; + if (len > 0 && ! is.read (ptmp, len)) + error ("load: failed to load string constant"); else { - char *ftmp = tmp.fortran_vec (); - - skip_preceeding_newline (is); + if (len > max_len) + { + max_len = len; + chm.resize (elements, max_len, 0); + } - if (! is.read (ftmp, dv.numel ()) || ! is) - error ("load: failed to load string constant"); - else - matrix = tmp; + chm.insert (tmp, i, 0); } } else - error ("load: failed to read dimensions"); + error ("load: failed to extract string length for element %d", + i+1); } - else - error ("load: failed to extract matrix size"); - } - else if (kw == "elements") - { - int elements = val; - - if (elements >= 0) - { - // FIXME: need to be able to get max length before doing anything. - charMatrix chm (elements, 0); - int max_len = 0; - for (int i = 0; i < elements; i++) - { - int len; - if (extract_keyword (is, "length", len) && len >= 0) - { - // Use this instead of a C-style character - // buffer so that we can properly handle - // embedded NUL characters. - charMatrix tmp (1, len); - char *ptmp = tmp.fortran_vec (); - - if (len > 0 && ! is.read (ptmp, len)) - error ("load: failed to load string constant"); - else - { - if (len > max_len) - { - max_len = len; - chm.resize (elements, max_len, 0); - } + matrix = chm; + } + else + error ("load: failed to extract number of string elements"); + } + else if (kw == "length") + { + int len = val; - chm.insert (tmp, i, 0); - } - } - else - error ("load: failed to extract string length for element %d", - i+1); - } - - matrix = chm; - } - else - error ("load: failed to extract number of string elements"); - } - else if (kw == "length") + if (len >= 0) { - int len = val; + // This is cruft for backward compatibility, + // but relatively harmless. - if (len >= 0) - { - // This is cruft for backward compatibility, - // but relatively harmless. - - // Use this instead of a C-style character buffer so - // that we can properly handle embedded NUL characters. - charMatrix tmp (1, len); - char *ptmp = tmp.fortran_vec (); + // Use this instead of a C-style character buffer so + // that we can properly handle embedded NUL characters. + charMatrix tmp (1, len); + char *ptmp = tmp.fortran_vec (); - if (len > 0 && ! is.read (ptmp, len)) - error ("load: failed to load string constant"); + if (len > 0 && ! is.read (ptmp, len)) + error ("load: failed to load string constant"); + else + { + if (is) + matrix = tmp; else - { - if (is) - matrix = tmp; - else - error ("load: failed to load string constant"); - } + error ("load: failed to load string constant"); } } - else - panic_impossible (); } else - error ("load: failed to extract number of rows and columns"); + panic_impossible (); return success; }