fix bug in finding expression in string

time-shift
Houtan Bastani 2017-11-02 15:30:01 +01:00
parent 4da12aac5e
commit 1f308aef41
1 changed files with 9 additions and 8 deletions

View File

@ -31,15 +31,10 @@ function retval = getStrMoveLeft(str)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
mathops = '[\+\*\^\-\/]'; arithops = '[\+\-]';
if str(end) ~= ')' if str(end) ~= ')'
mathidxs = regexp(str, mathops); arithidxs = regexp(str, arithops);
if isempty(mathidxs)
retval = str;
else
retval = str(max(mathidxs)+1:end);
end
else else
closedidxs = strfind(str, ')'); closedidxs = strfind(str, ')');
closedidxs = [(length(closedidxs):-1:1)' closedidxs']; closedidxs = [(length(closedidxs):-1:1)' closedidxs'];
@ -52,5 +47,11 @@ else
break; break;
end end
end end
retval = str(max(regexp(str(1:openidxs(openparenidx,2)), mathops))+1:closedidxs(end)); arithidxs = regexp(str(1:openidxs(openparenidx,2)), arithops);
end
if isempty(arithidxs)
retval = str;
else
retval = str(max(arithidxs)+1:end);
end end