added tostring callback
[rrq/rrqmisc.git] / vector / stringitem.c
index db400cebc8f33c54b5a126277dd7971f17446a2a..d53576dd540f62ff6832af3b265de6271339af94 100644 (file)
@@ -38,9 +38,21 @@ static void *stringitem_itemkey(void *this,void *item) {
 static void stringitem_releasekey(void *this,void *key) {
 }
 
+/**
+ * This callback function writes a representation of an item into
+ * a character buffer.
+ */
+static int stringitem_tostring(void *this,void *item,char *buffer,int limit) {
+    if ( item ) {
+       return snprintf( buffer, limit, "\"%s\"", (char*) item );
+    }
+    return snprintf( buffer, limit, "(null)" );
+}
+
 itemkeyfun stringitem = {
     .hashcode = stringitem_hashcode,
     .haskey = stringitem_haskey,
     .itemkey = stringitem_itemkey,
-    .releasekey = stringitem_releasekey
+    .releasekey = stringitem_releasekey,
+    .tostring = stringitem_tostring
 };