changeset 12964:8ec12d686796

new string_vector::join method * str-vec.cc, str-vec.h (string_vector::join): New method.
author John W. Eaton <jwe@octave.org>
date Mon, 15 Aug 2011 10:05:28 -0400
parents 27e5f0e79f19
children 22bc9ec80c2c
files liboctave/str-vec.cc liboctave/str-vec.h
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/str-vec.cc
+++ b/liboctave/str-vec.cc
@@ -163,6 +163,26 @@
   return *this;
 }
 
+std::string
+string_vector::join (const std::string& sep) const
+{
+  std::string retval;
+
+  octave_idx_type len = length ();
+
+  if (len > 0)
+    {
+      octave_idx_type i;
+
+      for (i = 0; i < len - 1; i++)
+        retval += elem(i) + sep;
+
+      retval += elem(i);
+    }
+
+  return retval;
+}
+
 char **
 string_vector::c_str_vec (void) const
 {
--- a/liboctave/str-vec.h
+++ b/liboctave/str-vec.h
@@ -105,6 +105,8 @@
 
   string_vector& append (const string_vector& sv);
 
+  std::string join (const std::string& sep = std::string ()) const;
+
   char **c_str_vec (void) const;
 
   static void delete_c_str_vec (const char * const*);