Mercurial > octave
diff libinterp/parse-tree/bp-table.cc @ 23824:061a343089be
Miscellaneous cleanups of C++11 std::string code.
* gl2ps-print.cc (escape_character): Use insert() function prototype for a
single character, rather than for a string.
* oct-stream.cc (textscan::scan_string): Grow string in an exponential manner
using append() to fill with '\0' nulls. For case of fixed delimiter, use
string constructor to pre-size the array. Use back() instead of
[tmp.length()-1)].
* bp-table.cc (get_user_code): Use iterators and std::replace rather
than hand-coded for loop. Remove check for "! name.empty()" since checking
for "name.length () > 2" will obviously include this case.
* cmd-edit.cc (do_decod_prompt_string, ): Be specific and use character '\\'
rather than string constructor "\\".
author | Rik <rik@octave.org> |
---|---|
date | Wed, 02 Aug 2017 12:04:45 -0700 |
parents | 336f89b6208b |
children | 4d4ba038d103 |
line wrap: on
line diff
--- a/libinterp/parse-tree/bp-table.cc Wed Aug 02 00:43:38 2017 -0500 +++ b/libinterp/parse-tree/bp-table.cc Wed Aug 02 12:04:45 2017 -0700 @@ -25,6 +25,7 @@ # include "config.h" #endif +#include <algorithm> #include <fstream> #include <limits> #include <list> @@ -63,8 +64,8 @@ std::set<std::string> bp_table::caught_that_stop; std::set<std::string> bp_table::warnings_that_stop; -// Return a pointer to the user-defined function FNAME. If FNAME is -// empty, search backward for the first user-defined function in the +// Return a pointer to the user-defined function FNAME. If FNAME is empty, +// search backward for the first user-defined function in the // current call stack. octave_user_code * @@ -84,18 +85,18 @@ if (octave::sys::file_ops::dir_sep_char () != '/' && name[0] == '@') { - int len = name.length () - 1; // -1: can't have trailing '/' - for (int i = 2; i < len; i++) // 2: can't have @/method - if (name[i] == '/') - name[i] = octave::sys::file_ops::dir_sep_char (); + auto beg = name.begin () + 2; // never have @/method + auto end = name.end () - 1; // never have trailing '/' + std::replace (beg, end, octave::sys::file_ops::dir_sep_char (), '/'); } size_t name_len = name.length (); - if (! name.empty () && name_len > 2 && name.substr (name_len-2) == ".m") + if (name_len > 2 && name.substr (name_len-2) == ".m") name = name.substr (0, name_len-2); - octave::symbol_table& symtab = octave::__get_symbol_table__ ("get_user_code"); + octave::symbol_table& symtab = + octave::__get_symbol_table__ ("get_user_code"); octave_value fcn = symtab.find_function (name);