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

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

[Octave-bug-tracker] [bug #57867] strrep: unexpected substitution behavi


From: Abdelrhman_Adel_Moawad
Subject: [Octave-bug-tracker] [bug #57867] strrep: unexpected substitution behavior on a char array
Date: Wed, 22 Apr 2020 15:32:18 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.113 Safari/537.36

Follow-up Comment #55, bug #57867 (project octave):

Ok, I will describe the main problem and how I think to fix it and what I have
done in the source code.
The Problem:
the substitution of character array in 2D-array .. the sequence of the
characters will be confused for example:
> a=["What is this ?"; "How is this ?"]  
> a=
  What is this?
  How is this?
if we use that command: a(:), the answer will be...
W H h o a w t  i i s s  t t h h i i s s
so when we use strrep function, it make nothing as it can't find the expected
sequence 
> strrep(a,"is", "does")
> ans=
  What is this ?
  How is this ?
but cell string works well so if we treat char array as cell string by change
the if(input.is_string()) condition behavior to convert input to cell string
by: input' =input.cell_str()
and treat input' to make replacement then use char(input',input'.numel()) to
convert back to char array to make output compatible.
and this only in case: if(input.is_string()).
The only change in the test will be:
from: %!assert (size (strrep ("a", "a", "")), [0 0])
to: %!assert (size (strrep ("a", "a", "")), [1 0])
So the result of all that is:
> strrep(a,"is","does")
> ans=
     What does this?
     How does this? 

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?57867>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

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