INLINE ident *id_from_str (const char *str, int len)
{
- assert (len > 0);
+ assert(len > 0);
return set_hinsert0(id_set, str, len, ID_HASH(str, len));
}
+ident *new_id_from_str(const char *str)
+{
+ assert(str);
+ return id_from_str(str, strlen(str));
+}
+
INLINE const char *id_to_str(ident *id)
{
return (const char *)id->dptr;
return id->size;
}
-int id_is_prefix (ident *prefix, ident *id)
+int id_is_prefix(ident *prefix, ident *id)
{
if (id_to_strlen(prefix) > id_to_strlen(id)) return 0;
return 0 == memcmp(prefix->dptr, id->dptr, id_to_strlen(prefix));
}
-int id_is_suffix (ident *suffix, ident *id)
+int id_is_suffix(ident *suffix, ident *id)
{
int suflen = id_to_strlen(suffix);
int idlen = id_to_strlen(id);
return 0 == memcmp(suffix->dptr, part, suflen);
}
+int id_contains_char(ident *id, char c)
+{
+ return strchr(id_to_str(id), c) != NULL;
+}
+
int print_id (ident *id)
{
return xprintf("%I", id);
* Store a string and create an ident.
*
* Stores a string in the ident module and returns a handle for the string.
- * Copies the string.
+ *
+ * Copies the string. @p str must be zero terminated
+ *
+ * @param str - the string which shall be stored
+ *
+ * @return id - a handle for the generated ident
+ *
+ * @see id_to_str(), id_to_strlen()
+ */
+ident *new_id_from_str (const char *str);
+
+/**
+ * Store a string and create an ident.
+ *
+ * Stores a string in the ident module and returns a handle for the string.
+ *
+ * Copies the string. This version can take non-zero-terminated strings
*
* @param str - the string (or whatever) which shall be stored
* @param len - the length of the data in bytes
*
* @return id - a handle for the generated ident
*
- * @see id_to_str(), id_to_strlen()
+ * @see new_id_to_str(), id_to_strlen()
*/
INLINE ident *id_from_str (const char *str, int len);
*
* @return cp - a string
*
- * @see id_from_str(), id_to_strlen()
+ * @see new_id_to_str(), id_from_str(), id_to_strlen()
*/
INLINE const char *id_to_str (ident *id);
*
* @return len - the length of the string
*
- * @see id_from_str(), id_to_str()
+ * @see new_id_to_str(), id_from_str(), id_to_str()
*/
INLINE int id_to_strlen(ident *id);
* @param prefix - the prefix
* @param id - the ident
*
- * @see id_from_str(), id_to_str(), id_is_prefix()
+ * @see new_id_to_str(), id_from_str(), id_to_str(), id_is_prefix()
*/
int id_is_prefix (ident *prefix, ident *id);
* @param suffix - the suffix
* @param id - the ident
*
- * @see id_from_str(), id_to_str(), id_is_prefix()
+ * @see new_id_to_str(), id_from_str(), id_to_str(), id_is_prefix()
*/
int id_is_suffix (ident *suffix, ident *id);
+/**
+ * Return true if an ident contains a given character.
+ *
+ * @param id - the ident
+ * @param c - the character
+ *
+ * @see new_id_to_str(), id_from_str(), id_to_str()
+ */
+int id_contains_char (ident *id, char c);
+
/**
* Prints the ident to stdout.
*
* @return
* number of btes written
*
- * @see id_from_str(), id_to_str(), id_is_prefix(), fprint_id()
+ * @see new_id_to_str(), id_from_str(), id_to_str(), id_is_prefix(), fprint_id()
*/
int print_id (ident *id);
* @return
* number of btes written
*
- * @see id_from_str(), id_to_str(), id_is_prefix(), print_id()
+ * @see new_id_to_str(), id_from_str(), id_to_str(), id_is_prefix(), print_id()
*/
int fprint_id (FILE *F, ident *id);