octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #49659] Non-empty ouput for non-matching regex


From: Rik
Subject: [Octave-bug-tracker] [bug #49659] Non-empty ouput for non-matching regexp with 'names' option
Date: Mon, 21 Nov 2016 17:50:35 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0

Follow-up Comment #2, bug #49659 (project octave):

Interesting.  This feature was probably implemented without a lot of checking
for Matlab compatibility.  It should be relatively easy to return a struct
array, rather than a scalar structure.

The file to modify is regexp.cc in libinterp/corefcn.

There are two functions, octregexp and octcellregexp, which probably need
modification.  The relevant code for octregexp is shown below.


  // Converted the linked list in the correct form for the return values

  octave_idx_type i = 0;
  octave_scalar_map nmap;

  retval.resize (7);

  if (sz == 1)
    {
      string_vector named_tokens = rx_lst.begin ()->named_tokens ();

      for (int j = 0; j < named_pats.numel (); j++)
        nmap.assign (named_pats(j), named_tokens(j));

      retval(5) = nmap;
    }
  else
    {
      for (int j = 0; j < named_pats.numel (); j++)
        {
          Cell tmp (dim_vector (1, sz));

          i = 0;
          for (octave::regexp::match_data::const_iterator p = rx_lst.begin
();
               p != rx_lst.end (); p++)
            {
              string_vector named_tokens = p->named_tokens ();

              tmp(i++) = named_tokens(j);
            }

          nmap.assign (named_pats(j), octave_value (tmp));
        }

      retval(5) = nmap;
    }


As you can see, in the case of multiple return arguments, it creates a
temporary cell and stuffs the results into that cell array, and then assigns
to the structure, under the ptn name, the temporary cell array.



    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?49659>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]