Mercurial > octave
diff liboctave/util/kpse.cc @ 23812:057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
* error.cc (maybe_extract_message): Use "back()" rather than "[length () -1]".
* input.cc (base_reader::octave_gets): Use "back()" rather than
"[length () -1]".
* ls-hdf5.cc (read_hdf5_data)): Use "clear()" rather than "resize (0)" to erase
string.
* ls-mat-ascii.cc (get_lines_and_columns): Reformat comment.
* ls-oct-binary.cc (read_binary_data): Use "clear()" rather than "resize (0)"
to erase string.
* oct-stream.cc (delimited_stream::getline): Declare and initialize only one
variable per line as per Octave coding convention.
* oct-stream.cc (textscan_format_list::read_first_row): Use back() and pop_back()
to potentially remove last character from string.
* strfns.cc (Fstrvcat): Use "empty()" rather than "length() > 0".
* sysdep.cc (w32_set_octav_home): Use back() and push_back() to potentially add
dir separator to string.
* gzip.cc (uchar_array): Space out code for readability.
* file-ops.cc (tilde_expand): Call string_vector constructor with size n rather
than resize.
* file-ops.cc (concat): Use "back()" rather than "[length () -1]".
* file-stat.cc (update_internal): Use "back()" rather than "[length () -1]".
Use pop_back() rather than resize() to remove last character.
* oct-env.cc (do_chdir): Use pop_back() rather than resize() to remove last
character.
* cmd-edit.cc (do_generate_filename_completions): Reformat comment.
* cmd-hist.cc (): Use back() and pop_back() to potentially remove "\n" from end
of string.
* data-conv.cc (strip_spaces): Initialize string with null character rather
than space.
* kpse.cc (kpse_tilde_expand): Use "back()" rather than "[length () -1]".
* kpse.cc (kpse_expand_kpse_dot, kpse_brace_expand, kpse_path_expand): Use
pop_back() to potentially remove last character.
* kpse.cc (kpse_brace_expand_element, kpse_element_dir): Use pop_back() to
remove last character.
* lo-utils.cc (octave_fgetl): Use "back()" rather than "[length () -1]".
Use pop_back() rather than resize() to remove last character.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 30 Jul 2017 09:21:58 -0700 |
parents | 336f89b6208b |
children | 01899bdd2a3a |
line wrap: on
line diff
--- a/liboctave/util/kpse.cc Sun Jul 30 09:21:39 2017 -0700 +++ b/liboctave/util/kpse.cc Sun Jul 30 09:21:58 2017 -0700 @@ -724,7 +724,7 @@ home = home.substr (1); /* If HOME ends in /, omit the / after ~user. */ - if (name.length () > c && IS_DIR_SEP (home[home.length () - 1])) + if (name.length () > c && IS_DIR_SEP (home.back ())) c++; expansion = (name.length () > c ? home : home + name.substr (c)); @@ -782,9 +782,8 @@ ret += kpse_dot + DIR_SEP_STRING + elt + ENV_SEP_STRING; } - int len = ret.length (); - if (len > 0) - ret.resize (len-1); + if (! ret.empty ()) + ret.pop_back (); return ret; } @@ -818,7 +817,7 @@ ret += x + ENV_SEP_STRING; } - ret.resize (ret.length () - 1); + ret.pop_back (); return ret; } @@ -849,9 +848,8 @@ ret += expansion + ENV_SEP_STRING; } - size_t len = ret.length (); - if (len > 0) - ret.resize (len-1); + if (! ret.empty ()) + ret.pop_back (); return kpse_expand_kpse_dot (ret); } @@ -924,8 +922,8 @@ } } - if (len > 0) - ret.resize (len-1); + if (! ret.empty ()) + ret.pop_back (); return ret; } @@ -1214,7 +1212,7 @@ { ret = elt; - char last_char = ret[ret.length () - 1]; + char last_char = ret.back (); if (! (IS_DIR_SEP (last_char) || IS_DEVICE_SEP (last_char))) ret += DIR_SEP_STRING;