changeset 4528:7a85d54d0cbd

[project @ 2003-10-03 18:15:57 by jwe]
author jwe
date Fri, 03 Oct 2003 18:15:57 +0000
parents c0a23a13eea2
children 78954aeaf321
files src/ChangeLog src/load-save.cc
diffstat 2 files changed, 51 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Oct 03 02:52:46 2003 +0000
+++ b/src/ChangeLog	Fri Oct 03 18:15:57 2003 +0000
@@ -1,3 +1,10 @@
+2003-10-03  John W. Eaton  <jwe@bevo.che.wisc.edu>
+
+	* load-save.cc (make_valid_identifier): Return new string.
+	Arg is now string, not char *.
+	(ident_is_all_digits): New function.
+	(hdf5_read_next_data): Use it.
+
 2003-10-02  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	* input.cc (input_event_hook): Clear the event hook if hook_fcn
--- a/src/load-save.cc	Fri Oct 03 02:52:46 2003 +0000
+++ b/src/load-save.cc	Fri Oct 03 18:15:57 2003 +0000
@@ -141,15 +141,45 @@
 #ifdef HAVE_HDF5
 // this is only used for HDF5 import
 // try to convert s into a valid identifier, replacing invalid chars with "_":
-static void
-make_valid_identifier (char *s)
+static std::string
+make_valid_identifier (const std::string& nm)
 {
-  if (s)
+  std::string retval;
+
+  size_t nm_len = nm.length ();
+
+  if (nm_len > 0)
     {
-      for (; *s; ++s)
-	if (! (isalnum (*s) || *s == '_'))
-	  *s = '_';
+      if (! isalpha (nm[0]))
+	retval += '_';
+
+      for (size_t i = 0; i < nm_len; i++)
+	{
+	  char c = nm[i];
+	  retval += (isalnum (c) || c == '_') ? c : '_';
+	}
     }
+
+  return retval;
+}
+
+static bool
+ident_is_all_digits (const std::string& id)
+{
+  bool retval = true;
+
+  size_t len = 0;
+
+  for (size_t i = 0; i < len; i++)
+    {
+      if (! isdigit (id[i]))
+	{
+	  retval = false;
+	  break;
+	}
+    }
+
+  return retval;
 }
 #endif /* HAVE_HDF5 */
 
@@ -1406,14 +1436,15 @@
   herr_t retval = 0;
   bool ident_valid = valid_identifier (name);
 
-  OCTAVE_LOCAL_BUFFER (char, vname, strlen (name) + 1);
-
-  strcpy (vname, name);
-
-  if (! ident_valid && d->import)
+  std::string vname = name;
+
+  // Allow identifiers as all digits so we can load lists saved by
+  // earlier versions of Octave.
+
+  if (! ident_valid && (d->import || ident_is_all_digits (vname)))
     {
       // fix the identifier, replacing invalid chars with underscores
-      make_valid_identifier (vname);
+      vname = make_valid_identifier (vname);
 
       // check again (in case vname was null, empty, or some such thing):
       ident_valid = valid_identifier (vname); 
@@ -1792,7 +1823,7 @@
 	  H5Gget_comment (group_id, name, comment_length, tdoc);
 	  d->doc = tdoc;
 	}
-      else if (strcmp (name, vname) != 0)
+      else if (vname != name)
 	{
 	  // the name was changed by import; store the original name
 	  // as the documentation string: