Mercurial > hg > octave-lyh
changeset 11032:c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 28 Sep 2010 09:25:14 -0700 |
parents | d81b6144c4ba |
children | d9c8916bb9dd |
files | doc/ChangeLog doc/interpreter/mk_doc_cache.m scripts/ChangeLog scripts/io/dlmwrite.m scripts/miscellaneous/edit.m scripts/miscellaneous/ls.m scripts/path/savepath.m scripts/pkg/get_forge_pkg.m scripts/plot/__gnuplot_get_var__.m scripts/plot/__gnuplot_ginput__.m scripts/plot/__go_draw_axes__.m scripts/plot/private/__ezplot__.m scripts/plot/private/__gnuplot_has_terminal__.m scripts/plot/refreshdata.m scripts/plot/whitebg.m scripts/testfun/runtests.m scripts/testfun/test.m scripts/time/datestr.m src/ChangeLog src/DLD-FUNCTIONS/regexp.cc src/load-path.cc test/ChangeLog test/fntests.m |
diffstat | 23 files changed, 126 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,4 +1,9 @@ -2010-08-15 Rik <octave@nomad.inbox5.com> +2010-09-27 Rik <octave@nomad.inbox5.com> + + * interpreter/mk_doc_cache.m: Use single quotes for regular expression + patterns where possible. + +2010-09-25 Rik <octave@nomad.inbox5.com> * interpreter/mk_doc_cache.m: Remove requirement for PCRE to build doc cache. Correctly parse first sentence from docstrings with
--- a/doc/interpreter/mk_doc_cache.m +++ b/doc/interpreter/mk_doc_cache.m @@ -45,10 +45,10 @@ text = [text{:}, doc_delim]; ## Modify Octave-specific macros before passing to makeinfo -text = regexprep (text, "@seealso *\\{([^}]*)\\}", "See also: $1."); -text = regexprep (text, "@nospell *\\{([^}]*)\\}", "$1"); +text = regexprep (text, '@seealso *\{([^}]*)\}', "See also: $1."); +text = regexprep (text, '@nospell *\{([^}]*)\}', "$1"); text = regexprep (text, "-\\*- texinfo -\\*-[ \t]*[\r\n]*", ""); -text = regexprep (text, "@", "@@"); +text = regexprep (text, '@', "@@"); ## Write data to temporary file for input to makeinfo [fid, name, msg] = mkstemp ("octave_doc_XXXXXX", true); @@ -89,7 +89,7 @@ ## Skip internal functions that start with __ as these aren't ## indexed by lookfor. - if (length (symbol) > 2 && regexp (symbol, "^__.+__$")) + if (length (symbol) > 2 && regexp (symbol, '^__.+__$')) continue; endif @@ -111,7 +111,7 @@ continue; endif - end_of_first_sentence = regexp (tmp, '(\.|[\r\n][\r\n])', "once"); + end_of_first_sentence = regexp (tmp, "(\\.|[\r\n][\r\n])", "once"); if (isempty (end_of_first_sentence)) end_of_first_sentence = length (tmp); else @@ -119,8 +119,8 @@ endif first_sentence = tmp(1:end_of_first_sentence); - first_sentence = regexprep (first_sentence, "([\r\n]| *)", " "); - first_sentence = regexprep (first_sentence, "^ +", ""); + first_sentence = regexprep (first_sentence, "([\r\n]| {2,})", " "); + first_sentence = regexprep (first_sentence, '^ +', ""); cache{1,k} = symbol; cache{2,k} = doc;
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,22 @@ +2010-09-27 Rik <octave@nomad.inbox5.com> + + * scripts/io/dlmwrite.m: Replace non-POSIX '\d' regex pattern. + + * scripts/miscellaneous/edit.m, scripts/path/savepath.m, + scripts/plot/__gnuplot_get_var__.m, + scripts/plot/private/__gnuplot_has_terminal__.m, + scripts/plot/refreshdata.m, scripts/plot/whitebg.m, + scripts/testfun/runtests.m, scripts/time/datestr.m: Use single quotes + for regular expression patterns when possible. + + * scripts/miscellaneous/ls.m, scripts/plot/__gnuplot_ginput__.m, + scripts/plot/__go_draw_axes__.m, scripts/plot/private/__ezplot__.m, + scripts/testfun/test.m: Remove uses of shorthand character classes + within list operators which is unsupported by POSIX regex. + + * scripts/pkg/get_forge_pkg.m: Select desired output from regexp + rather than ignoring most outputs. + 2010-09-28 Ben Abbott <bpabbott@mac.com> * plot/__print_parse_opts__.m: Fix test. @@ -10,6 +29,13 @@ * plot/__print_parse_opts__.m: Properly crop eps image and fix tests. + scripts/plot/__go_draw_axes__.m, scripts/plot/private/__ezplot__.m, + scripts/testfun/test.m: Remove uses of shorthand character classes + within list operators which is unsupported by POSIX regex. + + * scripts/pkg/get_forge_pkg.m: Select desired output from regexp + rather than ignoring most outputs. + 2010-09-26 Rik <octave@nomad.inbox5.com> * testfun/runtests.m (has_tests): Recode to remove requirement for PCRE.
--- a/scripts/io/dlmwrite.m +++ b/scripts/io/dlmwrite.m @@ -172,7 +172,7 @@ repmat ([repmat(delim, 1, c + columns(a)-1), newline], 1, r)); endif if (iscomplex (a)) - cprecision = regexprep (precision, '^%([-\d.])','%+$1'); + cprecision = regexprep (precision, '^%([-.0-9])','%+$1'); template = [precision, cprecision, "i", ... repmat([delim, precision, cprecision, "i"], 1, ... columns(a) - 1), newline ];
--- a/scripts/miscellaneous/edit.m +++ b/scripts/miscellaneous/edit.m @@ -246,11 +246,11 @@ if (idx == 0) ## Create the list of files to look for filelist = {file}; - if (isempty (regexp (file, "\\.m$"))) + if (isempty (regexp (file, '\.m$'))) ## No ".m" at the end of the file, add to the list. filelist{end+1} = cat (2, file, ".m"); endif - if (isempty (regexp (file, "\\.cc$"))) + if (isempty (regexp (file, '\.cc$'))) ## No ".cc" at the end of the file, add to the list. filelist{end+1} = cat (2, file, ".cc"); endif
--- a/scripts/miscellaneous/ls.m +++ b/scripts/miscellaneous/ls.m @@ -60,7 +60,7 @@ if (nargout == 0) puts (output); else - retval = strvcat (regexp (output, '[^\s]+', 'match'){:}); + retval = strvcat (regexp (output, '\S+', 'match'){:}); endif else error ("ls: command exited abnormally with status %d", status);
--- a/scripts/path/savepath.m +++ b/scripts/path/savepath.m @@ -208,7 +208,7 @@ endfunction function path_elements = parsepath (p) - pat = sprintf ("([^%s]+[%s$])", pathsep, pathsep); + pat = sprintf ('([^%s]+[%s$])', pathsep, pathsep); [jnk1, jnk2, jnk3, path_elements] = regexpi (strcat (p, pathsep), pat); endfunction
--- a/scripts/pkg/get_forge_pkg.m +++ b/scripts/pkg/get_forge_pkg.m @@ -41,8 +41,8 @@ ## Remove blanks for simpler matching. html(isspace(html)) = []; ## Good. Let's grep for the version. - pat = "<tdclass=""package_table"">PackageVersion:</td><td>([0-9\\.]*)</td>"; - [~, ~, ~, ~, t] = regexp (html, pat); + pat = "<tdclass=""package_table"">PackageVersion:</td><td>([0-9.]*)</td>"; + t = regexp (html, pat, "tokens"); if (isempty (t) || isempty(t{1})) error ("get_forge_pkg: could not read version number from package's page."); else @@ -61,7 +61,7 @@ ## Try get the list of all packages. [html, succ] = urlread ("http://octave.sourceforge.net/packages.php"); if (succ) - [~, ~, ~, ~, t] = regexp (html, "<div class=""package"" id=""(\\w+)"">"); + t = regexp (html, "<div class=""package"" id=""(\\w+)"">", "tokens"); t = horzcat (t{:}); if (any (strcmp (t, name))) error ("get_forge_pkg: package name exists, but index page not available");
--- a/scripts/plot/__gnuplot_get_var__.m +++ b/scripts/plot/__gnuplot_get_var__.m @@ -130,7 +130,7 @@ if (isempty (str)) sleep (0.05); else - str = regexp (str, "OCTAVE:.*", "match"); + str = regexp (str, 'OCTAVE:.*', "match"); str = str{end}(8:end); endif fclear (istream);
--- a/scripts/plot/__gnuplot_ginput__.m +++ b/scripts/plot/__gnuplot_ginput__.m @@ -113,7 +113,7 @@ if (isempty (str)) sleep (0.05); else - str = regexp (str, 'OCTAVE:\s+[\d.\+-]+\s+[\d.\+-]+\s+\d*', 'match'); + str = regexp (str, 'OCTAVE:\s+[-+.0-9]+\s+[-+.0-9]+\s+[0-9]*', 'match'); endif fclear (istream); endwhile
--- a/scripts/plot/__go_draw_axes__.m +++ b/scripts/plot/__go_draw_axes__.m @@ -1990,7 +1990,7 @@ tickdir, ticklength, axispos); endif - labels = regexprep(labels, "%", "%%"); + labels = regexprep(labels, '%', "%%"); for i = 1:ntics fprintf (plot_stream, " \"%s\" %.15g", labels{k++}, tics(i)); if (i < ntics) @@ -2315,7 +2315,7 @@ function l = length_string (s) l = length (s) - length (strfind(s,'{')) - length (strfind(s,'}')); - m = regexp (s, '/([\w\-]+|[\w\-]+=\d+)', 'matches'); + m = regexp (s, '/([a-zA-Z0-9_-]+|[a-zA-Z0-9_-]+=[0-9]+)', 'matches'); if (!isempty (m)) l = l - sum (cellfun (@length, m)); endif
--- a/scripts/plot/private/__ezplot__.m +++ b/scripts/plot/private/__ezplot__.m @@ -119,7 +119,7 @@ fstr = func2str (fun); if (length (findstr (fstr, ")")) != 0) args = regexp (substr (fstr, 3, findstr (fstr, ")")(1) - 3), - '(\w[\w\d]*)', 'tokens'); + '(\w+)', 'tokens'); fstr = substr (fstr, findstr (fstr, ")")(1) + 1); else args = {{"x"}}; @@ -177,7 +177,7 @@ fstry = func2str (funy); if (length (findstr (fstry, ")")) != 0) args = regexp (substr (fstry, 3, findstr (fstry, ")")(1) - 3), - '(\w[\w\d]*)', 'tokens'); + '(\w+)', 'tokens'); fstry = substr (fstry, findstr (fstry, ")")(1) + 1); else args = {{"y"}}; @@ -217,7 +217,7 @@ elseif (isa (funz, "function_handle")) fstrz = func2str (funz); args = regexp (substr (fstrz, 3, findstr (fstrz, ")")(1) - 3), - '(\w[\w\d]*)', 'tokens'); + '(\w+)', 'tokens'); if (length (args) != nargs) error ("%s: excepting a function of %d arguments", func, nargs); endif @@ -330,15 +330,15 @@ Z = __eliminate_sing__ (Z); endif - fstrx = regexprep (regexprep (regexprep (fstrx,'\.\^\s*','^'), - '\./', '/'), '[\.]*\*', ''); - fstry = regexprep (regexprep (regexprep (fstry,'\.\^\s*','^'), - '\./', '/'), '[\.]*\*', ''); + fstrx = regexprep (regexprep (regexprep (fstrx,'\s*\.?\^\s*','^'), + '\./', '/'), '\.?\*', ''); + fstry = regexprep (regexprep (regexprep (fstry,'\s*\.?\^\s*','^'), + '\./', '/'), '\.?\*', ''); if (isplot) fstr = cstrcat ("x = ",fstrx,", y = ",fstry); else - fstrz = regexprep (regexprep (regexprep (fstrz,'\.\^\s*','^'), - '\./', '/'), '[\.]*\*', ''); + fstrz = regexprep (regexprep (regexprep (fstrz,'\s*\.?\^\s*','^'), + '\./', '/'), '\.?\*', ''); fstr = cstrcat ("x = ",fstrx,",y = ",fstry,", z = ",fstrz); endif else @@ -347,8 +347,8 @@ return; endif - fstr = regexprep (regexprep (regexprep (fstr,'\.\^\s*','^'), '\./', '/'), - '[\.]*\*', ''); + fstr = regexprep (regexprep (regexprep (fstr,'\s*\.?\^\s*','^'), '\./', '/'), + '\.?\*', ''); if (isplot && nargs == 2) if (strcmp (typeinfo (fun), "inline function") && !isempty (strfind (formula (fun) , "=")))
--- a/scripts/plot/private/__gnuplot_has_terminal__.m +++ b/scripts/plot/private/__gnuplot_has_terminal__.m @@ -33,7 +33,7 @@ plot_stream = __gnuplot_open_stream__ (2); endif available_terminals = __gnuplot_get_var__ (plot_stream, "GPVAL_TERMINALS"); - available_terminals = regexp (available_terminals, "\\b\\w+\\b", "match"); + available_terminals = regexp (available_terminals, '\b\w+\b', "match"); if (nargin < 2 && ! isempty (plot_stream)) pclose (plot_stream(1)); if (numel (plot_stream) > 1)
--- a/scripts/plot/refreshdata.m +++ b/scripts/plot/refreshdata.m @@ -80,7 +80,7 @@ for i = 1 : numel (h) obj = get (h (i)); fldnames = fieldnames (obj); - m = regexpi (fieldnames(obj), "^.+datasource$", "match"); + m = regexpi (fieldnames(obj), '^.+datasource$', "match"); idx = cellfun (@(x) !isempty(x), m); if (any (idx)) tmp = m(idx);
--- a/scripts/plot/whitebg.m +++ b/scripts/plot/whitebg.m @@ -72,7 +72,7 @@ if (isroot) fac = get (0, "factory"); fields = fieldnames (fac); - fieldindex = intersect (find (!cellfun (@isempty, regexp(fields, ".*color.*"))), union (find (!cellfun (@isempty, regexp(fields, "factoryaxes.*"))), find (!cellfun (@isempty, regexp(fields, "factoryfigure.*"))))); + fieldindex = intersect (find (!cellfun (@isempty, regexp(fields, '.*color.*'))), union (find (!cellfun (@isempty, regexp(fields, 'factoryaxes.*'))), find (!cellfun (@isempty, regexp(fields, 'factoryfigure.*'))))); ## Check whether the factory value has been replaced for nf = 1 : numel (fieldindex); @@ -102,7 +102,7 @@ for nh = 1 : numel(h) p = get (h (nh)); fields = fieldnames (p); - fieldindex = find (!cellfun (@isempty, regexp(fields, ".*color.*"))); + fieldindex = find (!cellfun (@isempty, regexp(fields, '.*color.*'))); if (numel (fieldindex)) for nf = 1 : numel (fieldindex); field = fields {fieldindex (nf)}; @@ -119,7 +119,7 @@ def = get (h (nh), "default"); fields = fieldnames (def); if (! isempty (fields)) - fieldindex = find (!cellfun (@isempty, regexp(fields, ".*color.*"))); + fieldindex = find (!cellfun (@isempty, regexp(fields, '.*color.*'))); for nf = 1 : numel (fieldindex) defaultfield = fields {fieldindex (nf)}; defaultvalue = 1 - subsref (def, struct ("type", ".", "subs", defaultfield));
--- a/scripts/testfun/runtests.m +++ b/scripts/testfun/runtests.m @@ -82,7 +82,7 @@ fclose (fid); ## Avoid PCRE 'lineanchors' by searching for newline followed by PTN. ## Equivalent to regexp ('^PTN','lineanchors') - retval = ! isempty (regexp (str, '[\r\n]\s*%!(test|assert|error|warning)', "once")); + retval = ! isempty (regexp (str, "[\r\n]\\s*%!(test|assert|error|warning)", "once")); else error ("runtests: fopen failed: %s", f); endif
--- a/scripts/testfun/test.m +++ b/scripts/testfun/test.m @@ -444,7 +444,7 @@ ### TESTIF elseif (strcmp (__type, "testif")) - [__e, __feat] = regexp (__code, '^\s*([^\s]+)', 'end', 'tokens'); + [__e, __feat] = regexp (__code, '^\s*(\S+)', 'end', 'tokens'); if (isempty (findstr (octave_config_info ("DEFS"), __feat{1}{1}))) __xskip++; __istest = 0;
--- a/scripts/time/datestr.m +++ b/scripts/time/datestr.m @@ -229,7 +229,7 @@ endif df_orig = df; - df = regexprep (df, "[AP]M", "%p"); + df = regexprep (df, '[AP]M', "%p"); if (strcmp (df, df_orig)) ## PM not set. df = strrep (df, "HH", "%H"); @@ -237,19 +237,19 @@ df = strrep (df, "HH", sprintf ("%2d", v(i,4))); endif - df = regexprep (df, "[Yy][Yy][Yy][Yy]", "%Y"); + df = regexprep (df, '[Yy][Yy][Yy][Yy]', "%Y"); - df = regexprep (df, "[Yy][Yy]", "%y"); + df = regexprep (df, '[Yy][Yy]', "%y"); - df = regexprep (df, "[Dd][Dd][Dd][Dd]", "%A"); + df = regexprep (df, '[Dd][Dd][Dd][Dd]', "%A"); - df = regexprep (df, "[Dd][Dd][Dd]", "%a"); + df = regexprep (df, '[Dd][Dd][Dd]', "%a"); - df = regexprep (df, "[Dd][Dd]", "%d"); + df = regexprep (df, '[Dd][Dd]', "%d"); tmp = names_d{weekday (datenum (v(i,1), v(i,2), v(i,3)))}; - df = regexprep (df, "([^%])[Dd]", sprintf ("$1%s", tmp)); - df = regexprep (df, "^[Dd]", sprintf ("%s", tmp)); + df = regexprep (df, '([^%])[Dd]', sprintf ("$1%s", tmp)); + df = regexprep (df, '^[Dd]', sprintf ("%s", tmp)); df = strrep (df, "mmmm", "%B"); @@ -258,15 +258,15 @@ df = strrep (df, "mm", "%m"); tmp = names_m{v(i,2)}; - pos = regexp (df, "[^%]m") + 1; + pos = regexp (df, '[^%]m') + 1; df(pos) = tmp; - df = regexprep (df, "^m", tmp); + df = regexprep (df, '^m', tmp); df = strrep (df, "MM", "%M"); df = strrep (df, "SS", "%S"); - df = regexprep (df, "[Qq][Qq]", sprintf ("Q%d", fix ((v(i,2) + 2) / 3))); + df = regexprep (df, '[Qq][Qq]', sprintf ("Q%d", fix ((v(i,2) + 2) / 3))); vi = v(i,:); tm.year = vi(1) - 1900;
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -18,6 +18,17 @@ 2010-09-26 Rik <octave@nomad.inbox5.com> + * load-path.cc: Use single quotes for regex when possible. + * DLD-FUNCTIONS/regexp.cc (regexp): Update docstring to highlight + differences between POSIX and PCRE regex. + +2010-09-26 Rik <octave@nomad.inbox5.com> + + * load-path.cc: Use single quotes for regular expression patterns when + possible. + +2010-09-26 Rik <octave@nomad.inbox5.com> + * DLD-FUNCTIONS/regexp.cc (regexp, regexprep, regexpi): Update docstrings to more fully explain PCRE. Modify advanced tests to run only run when PCRE is present.
--- a/src/DLD-FUNCTIONS/regexp.cc +++ b/src/DLD-FUNCTIONS/regexp.cc @@ -921,18 +921,24 @@ \n\ List operators. The pattern will match any character listed between \"[\"\n\ and \"]\". If the first character is \"^\" then the pattern is inverted and\n\ -any character except those listed between brackets will match\n\ +any character except those listed between brackets will match.\n\ +\n\ +With PCRE support, escape sequences defined below can be used inside list\n\ +operators. For example, a template for a floating point number might be\n\ +@code{[-+.\\d]+}. POSIX regular expressions do not use escape sequences\n\ +and any backslash @samp{\\} will be interpreted literally as one\n\ +of the list of characters to match.\n\ \n\ @item ()\n\ Grouping operator\n\ \n\ @item |\n\ Alternation operator. Match one of a choice of regular expressions. The\n\ -alternatives must be delimited by the grouping operator @code{()} above\n\ +alternatives must be delimited by the grouping operator @code{()} above.\n\ \n\ @item ^ $\n\ Anchoring operators. Requires pattern to occur at the start (@code{^}) or\n\ -end (@code{$}) of the string\n\ +end (@code{$}) of the string.\n\ @end table\n\ \n\ In addition, the following escaped characters have special meaning. Note,\n\ @@ -968,30 +974,36 @@ @item \\d\n\ Match any digit\n\ \n\ +This sequence is only available with PCRE support. For POSIX regular\n\ +expressions use the following list operator @code{[0-9]}.\n\ +\n\ @item \\D\n\ Match any non-digit\n\ +\n\ +This sequence is only available with PCRE support. For POSIX regular\n\ +expressions use the following list operator @code{[^0-9]}.\n\ @end table\n\ \n\ The outputs of @code{regexp} default to the order given below\n\ \n\ -@table @asis\n\ -@item @var{s}\n\ +@table @var\n\ +@item s\n\ The start indices of each matching substring\n\ \n\ -@item @var{e}\n\ +@item e\n\ The end indices of each matching substring\n\ \n\ -@item @var{te}\n\ +@item te\n\ The extents of each matched token surrounded by @code{(@dots{})} in\n\ @var{pat}\n\ \n\ -@item @var{m}\n\ +@item m\n\ A cell array of the text of each match\n\ \n\ -@item @var{t}\n\ +@item t\n\ A cell array of the text of each token matched\n\ \n\ -@item @var{nm}\n\ +@item nm\n\ A structure containing the text of each matched named token, with the name\n\ being used as the fieldname. A named token is denoted by\n\ @code{(?<name>@dots{})} and is only available with PCRE support.\n\ @@ -1156,7 +1168,6 @@ %! assert (isempty(t)) %!testif HAVE_PCRE -%! ## This test is expected to fail if PCRE is not installed %! [s, e, te, m, t, nm] = regexp('short test string','(?<word1>\w*t)\s*(?<word2>\w*t)'); %! assert (s,1) %! assert (e,10) @@ -1173,7 +1184,6 @@ %! assert (nm.word2,'test') %!testif HAVE_PCRE -%! ## This test is expected to fail if PCRE is not installed %! [nm, m, te, e, s, t] = regexp('short test string','(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 'tokenExtents', 'end', 'start', 'tokens'); %! assert (s,1) %! assert (e,10) @@ -1190,7 +1200,6 @@ %! assert (nm.word2,'test') %!testif HAVE_PCRE -%! ## This test is expected to fail if PCRE is not installed %! [t, nm] = regexp("John Davis\nRogers, James",'(?<first>\w+)\s+(?<last>\w+)|(?<last>\w+),\s+(?<first>\w+)','tokens','names'); %! assert (size(t), [1,2]); %! assert (t{1}{1},'John'); @@ -1344,7 +1353,6 @@ %! assert (isempty(t)) %!testif HAVE_PCRE -%! ## This test is expected to fail if PCRE is not installed %! [s, e, te, m, t, nm] = regexpi('ShoRt Test String','(?<word1>\w*t)\s*(?<word2>\w*t)'); %! assert (s,1) %! assert (e,10) @@ -1361,7 +1369,6 @@ %! assert (nm.word2,'Test') %!testif HAVE_PCRE -%! ## This test is expected to fail if PCRE is not installed %! [nm, m, te, e, s, t] = regexpi('ShoRt Test String','(?<word1>\w*t)\s*(?<word2>\w*t)', 'names', 'match', 'tokenExtents', 'end', 'start', 'tokens'); %! assert (s,1) %! assert (e,10) @@ -1737,13 +1744,14 @@ %! t = regexprep(xml,'<[!?][^>]*>','','tokenize'); %! assert(t,' <tag v="hello">some stuff</tag>') -%!testif HAVE_PCRE # Capture replacement +## Test capture replacement +%!testif HAVE_PCRE %! data = "Bob Smith\nDavid Hollerith\nSam Jenkins"; %! result = "Smith, Bob\nHollerith, David\nJenkins, Sam"; %! t = regexprep(data,'(?m)^(\w+)\s+(\w+)$','$2, $1'); %! assert(t,result) -# Return the original if no match +## Return the original if no match %!assert(regexprep('hello','world','earth'),'hello') ## Test a general replacement
--- a/src/load-path.cc +++ b/src/load-path.cc @@ -2147,8 +2147,8 @@ { std::string dir = *p; - //dir = regexprep (dir_elts{j}, "//+", "/"); - //dir = regexprep (dir, "/$", ""); + //dir = regexprep (dir_elts{j}, '//+', "/"); + //dir = regexprep (dir, '/$', ""); if (append) load_path::append (dir, true); @@ -2213,8 +2213,8 @@ { std::string dir = *p; - //dir = regexprep (dir_elts{j}, "//+", "/"); - //dir = regexprep (dir, "/$", ""); + //dir = regexprep (dir_elts{j}, '//+', "/"); + //dir = regexprep (dir, '/$', ""); if (! load_path::remove (dir)) warning ("rmpath: %s: not found", dir.c_str ());
--- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2010-09-27 Rik <octave@nomad.inbox5.com> + + * fntests.m: Use single quotes for regex when possible. + 2010-09-26 Rik <octave@nomad.inbox5.com> * fntests.m (has_tests, has_functions): Recode to remove requirement
--- a/test/fntests.m +++ b/test/fntests.m @@ -75,7 +75,7 @@ if (fid >= 0) str = fread (fid, "*char")'; fclose (fid); - retval = ! isempty (regexp (str,'[\r\n](DEFUN|DEFUN_DLD)\b', "once")); + retval = ! isempty (regexp (str,"[\r\n](DEFUN|DEFUN_DLD)\\b", "once")); else error ("fopen failed: %s", f); endif @@ -93,7 +93,7 @@ fclose (fid); ## Avoid PCRE 'lineanchors' by searching for newline followed by PTN. ## Equivalent to regexp ('^PTN','lineanchors') - retval = ! isempty (regexp (str, '[\r\n]\s*%!(test|assert|error|warning)', "once")); + retval = ! isempty (regexp (str, "[\r\n]\\s*%!(test|assert|error|warning)", "once")); else error ("fopen failed: %s", f); endif