comparison liboctave/system/file-ops.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 8057d3f0673d
children 194eb4bd202b
comparison
equal deleted inserted replaced
23811:e8eb1b86e935 23812:057a894914df
330 } 330 }
331 } 331 }
332 332
333 string_vector tilde_expand (const string_vector& names) 333 string_vector tilde_expand (const string_vector& names)
334 { 334 {
335 string_vector retval;
336
337 int n = names.numel (); 335 int n = names.numel ();
338 336
339 retval.resize (n); 337 string_vector retval (n);
340 338
341 for (int i = 0; i < n; i++) 339 for (int i = 0; i < n; i++)
342 retval[i] = tilde_expand (names[i]); 340 retval[i] = tilde_expand (names[i]);
343 341
344 return retval; 342 return retval;
346 344
347 std::string concat (const std::string& dir, const std::string& file) 345 std::string concat (const std::string& dir, const std::string& file)
348 { 346 {
349 return dir.empty () 347 return dir.empty ()
350 ? file 348 ? file
351 : (is_dir_sep (dir[dir.length ()-1]) 349 : (is_dir_sep (dir.back ())
352 ? dir + file 350 ? dir + file
353 : dir + dir_sep_char () + file); 351 : dir + dir_sep_char () + file);
354 } 352 }
355 353
356 std::string dirname (const std::string& path) 354 std::string dirname (const std::string& path)