summaryrefslogtreecommitdiffstats
path: root/src/H5Gname.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5Gname.c')
-rw-r--r--src/H5Gname.c116
1 files changed, 107 insertions, 9 deletions
diff --git a/src/H5Gname.c b/src/H5Gname.c
index 9f135f8..62875dc 100644
--- a/src/H5Gname.c
+++ b/src/H5Gname.c
@@ -113,6 +113,104 @@ H5FL_BLK_EXTERN(str_buf);
/*-------------------------------------------------------------------------
+ * Function: H5G__component
+ *
+ * Purpose: Returns the pointer to the first component of the
+ * specified name by skipping leading slashes. Returns
+ * the size in characters of the component through SIZE_P not
+ * counting leading slashes or the null terminator.
+ *
+ * Return: Success: Ptr into NAME.
+ *
+ * Failure: Ptr to the null terminator of NAME.
+ *
+ * Programmer: Robb Matzke
+ * matzke@llnl.gov
+ * Aug 11 1997
+ *
+ *-------------------------------------------------------------------------
+ */
+const char *
+H5G__component(const char *name, size_t *size_p)
+{
+ FUNC_ENTER_PACKAGE_NOERR
+
+ assert(name);
+
+ while ('/' == *name)
+ name++;
+ if (size_p)
+ *size_p = HDstrcspn(name, "/");
+
+ FUNC_LEAVE_NOAPI(name)
+} /* end H5G__component() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5G_normalize
+ *
+ * Purpose: Returns a pointer to a new string which has duplicate and
+ * trailing slashes removed from it.
+ *
+ * Return: Success: Ptr to normalized name.
+ * Failure: NULL
+ *
+ * Programmer: Quincey Koziol
+ * Saturday, August 16, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+char *
+H5G_normalize(const char *name)
+{
+ char *norm; /* Pointer to the normalized string */
+ size_t s,d; /* Positions within the strings */
+ unsigned last_slash; /* Flag to indicate last character was a slash */
+ char *ret_value; /* Return value */
+
+ FUNC_ENTER_NOAPI_NOINIT
+
+ /* Sanity check */
+ HDassert(name);
+
+ /* Duplicate the name, to return */
+ if(NULL == (norm = H5MM_strdup(name)))
+ HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for normalized string")
+
+ /* Walk through the characters, omitting duplicated '/'s */
+ s = d = 0;
+ last_slash = 0;
+ while(name[s] != '\0') {
+ if(name[s] == '/')
+ if(last_slash)
+ ;
+ else {
+ norm[d++] = name[s];
+ last_slash = 1;
+ } /* end else */
+ else {
+ norm[d++] = name[s];
+ last_slash = 0;
+ } /* end else */
+ s++;
+ } /* end while */
+
+ /* Terminate normalized string */
+ norm[d] = '\0';
+
+ /* Check for final '/' on normalized name & eliminate it */
+ if(d > 1 && last_slash)
+ norm[d - 1] = '\0';
+
+ /* Set return value */
+ ret_value = norm;
+
+done:
+ FUNC_LEAVE_NOAPI(ret_value)
+} /* end H5G_normalize() */
+
+
+/*-------------------------------------------------------------------------
* Function: H5G_common_path
*
* Purpose: Determine if one path is a valid prefix of another path
@@ -139,11 +237,11 @@ H5G_common_path(const H5RS_str_t *fullpath_r, const H5RS_str_t *prefix_r)
/* Get component of each name */
fullpath=H5RS_get_str(fullpath_r);
assert(fullpath);
- fullpath=H5G_component(fullpath,&nchars1);
+ fullpath=H5G__component(fullpath,&nchars1);
assert(fullpath);
prefix=H5RS_get_str(prefix_r);
assert(prefix);
- prefix=H5G_component(prefix,&nchars2);
+ prefix=H5G__component(prefix,&nchars2);
assert(prefix);
/* Check if we have a real string for each component */
@@ -157,9 +255,9 @@ H5G_common_path(const H5RS_str_t *fullpath_r, const H5RS_str_t *prefix_r)
prefix+=nchars2;
/* Get next component of each name */
- fullpath=H5G_component(fullpath,&nchars1);
+ fullpath=H5G__component(fullpath,&nchars1);
assert(fullpath);
- prefix=H5G_component(prefix,&nchars2);
+ prefix=H5G__component(prefix,&nchars2);
assert(prefix);
} /* end if */
else
@@ -310,7 +408,7 @@ H5G_build_fullpath_refstr_refstr(const H5RS_str_t *prefix_r, const H5RS_str_t *n
/*-------------------------------------------------------------------------
- * Function: H5G_name_init
+ * Function: H5G__name_init
*
* Purpose: Set the initial path for a group hierarchy name
*
@@ -323,9 +421,9 @@ H5G_build_fullpath_refstr_refstr(const H5RS_str_t *prefix_r, const H5RS_str_t *n
*-------------------------------------------------------------------------
*/
herr_t
-H5G_name_init(H5G_name_t *name, const char *path)
+H5G__name_init(H5G_name_t *name, const char *path)
{
- FUNC_ENTER_NOAPI_NOINIT_NOERR
+ FUNC_ENTER_PACKAGE
/* Check arguments */
HDassert(name);
@@ -338,7 +436,7 @@ H5G_name_init(H5G_name_t *name, const char *path)
name->obj_hidden = 0;
FUNC_LEAVE_NOAPI(SUCCEED)
-} /* end H5G_name_init() */
+} /* end H5G__name_init() */
/*-------------------------------------------------------------------------
@@ -355,7 +453,7 @@ H5G_name_init(H5G_name_t *name, const char *path)
*-------------------------------------------------------------------------
*/
herr_t
-H5G_name_set(H5G_name_t *loc, H5G_name_t *obj, const char *name)
+H5G_name_set(const H5G_name_t *loc, H5G_name_t *obj, const char *name)
{
herr_t ret_value = SUCCEED;