[Opensrf-commits] r1028 - branches/new-json2/src/libopensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Jul 12 13:58:07 EDT 2007


Author: erickson
Date: 2007-07-12 13:53:15 -0400 (Thu, 12 Jul 2007)
New Revision: 1028

Modified:
   branches/new-json2/src/libopensrf/osrf_json_object.c
   branches/new-json2/src/libopensrf/osrf_json_tools.c
Log:
removed some commented-out code.  making use of buffer_release

Modified: branches/new-json2/src/libopensrf/osrf_json_object.c
===================================================================
--- branches/new-json2/src/libopensrf/osrf_json_object.c	2007-07-12 01:17:52 UTC (rev 1027)
+++ branches/new-json2/src/libopensrf/osrf_json_object.c	2007-07-12 17:53:15 UTC (rev 1028)
@@ -140,7 +140,6 @@
 char* jsonObjectToJSONRaw( const jsonObject* obj ) {
 	if(!obj) return NULL;
 	growing_buffer* buf = buffer_init(32);
-    //jsonObject* tmp;
 	int i;
     char* json;
 
@@ -203,7 +202,6 @@
 			while( (item = osrfHashIteratorNext(itr)) ) {
 				if(i++ > 0) OSRF_BUFFER_ADD(buf, ",");
 				buffer_fadd(buf, "\"%s\":", itr->current);
-				//char* json = jsonObjectToJSON(item);
 				char* json = jsonObjectToJSONRaw(item);
 				OSRF_BUFFER_ADD(buf, json);
 				free(json);
@@ -215,9 +213,7 @@
 		}
 	}
 
-	char* data = buffer_data(buf);
-	buffer_free(buf);
-	return data;
+    return buffer_release(buf);
 }
 
 

Modified: branches/new-json2/src/libopensrf/osrf_json_tools.c
===================================================================
--- branches/new-json2/src/libopensrf/osrf_json_tools.c	2007-07-12 01:17:52 UTC (rev 1027)
+++ branches/new-json2/src/libopensrf/osrf_json_tools.c	2007-07-12 17:53:15 UTC (rev 1028)
@@ -27,9 +27,7 @@
 	growing_buffer* buf = buffer_init(24);
 	int i;
 	for(i=0;i<count;i++) OSRF_BUFFER_ADD(buf, "  ");
-	char* final = buffer_data( buf );
-	buffer_free( buf );
-	return final;
+    return buffer_release(buf);
 }
 
 char* jsonFormatString( const char* string ) {
@@ -72,9 +70,7 @@
 
 	}
 
-	char* result = buffer_data(buf);
-	buffer_free(buf);
-	return result;
+    return buffer_release(buf);
 }
 
 
@@ -177,146 +173,6 @@
 	return newObj;
 }
 
-
-
-
-/*
-static char* _escape_xml (char*);
-static int _recurse_jsonObjectToXML(jsonObject*, growing_buffer*);
-
-char* jsonObjectToXML(jsonObject* obj) {
-
-	growing_buffer * res_xml;
-	char * output;
-
-	res_xml = buffer_init(1024);
-
-	if (!obj)
-		return strdup("<null/>");
-	
-	_recurse_jsonObjectToXML( obj, res_xml );
-	output = buffer_data(res_xml);
-	
-	buffer_free(res_xml);
-
-	return output;
-
-}
-
-int _recurse_jsonObjectToXML(jsonObject* obj, growing_buffer* res_xml) {
-
-	char * hint = NULL;
-	char * bool_val = NULL;
-	int i = 0;
-	
-	if (obj->classname)
-		hint = strdup(obj->classname);
-
-	if(obj->type == JSON_NULL) {
-
-		if (hint)
-			buffer_fadd(res_xml, "<null class_hint=\"%s\"/>",hint);
-		else
-			buffer_add(res_xml, "<null/>");
-
-	} else if(obj->type == JSON_BOOL) {
-
-		if (obj->value.b)
-			bool_val = strdup("true");
-		else
-			bool_val = strdup("false");
-
-		if (hint)
-			buffer_fadd(res_xml, "<boolean value=\"%s\" class_hint=\"%s\"/>", bool_val, hint);
-		else
-			buffer_fadd(res_xml, "<boolean value=\"%s\"/>", bool_val);
-
-		free(bool_val);
-                
-	} else if (obj->type == JSON_STRING) {
-		if (hint) {
-			char * t = _escape_xml(jsonObjectGetString(obj));
-			buffer_fadd(res_xml,"<string class_hint=\"%s\">%s</string>", hint, t);
-			free(t);
-		} else {
-			char * t = _escape_xml(jsonObjectGetString(obj));
-			buffer_fadd(res_xml,"<string>%s</string>", t);
-			free(t);
-		}
-
-	} else if(obj->type == JSON_NUMBER) {
-		double x = jsonObjectGetNumber(obj);
-		if (hint) {
-			if (x == (int)x)
-				buffer_fadd(res_xml,"<number class_hint=\"%s\">%d</number>", hint, (int)x);
-			else
-				buffer_fadd(res_xml,"<number class_hint=\"%s\">%lf</number>", hint, x);
-		} else {
-			if (x == (int)x)
-				buffer_fadd(res_xml,"<number>%d</number>", (int)x);
-			else
-				buffer_fadd(res_xml,"<number>%lf</number>", x);
-		}
-
-	} else if (obj->type == JSON_ARRAY) {
-
-		if (hint) 
-        	       	buffer_fadd(res_xml,"<array class_hint=\"%s\">", hint);
-		else
-               		buffer_add(res_xml,"<array>");
-
-	       	for ( i = 0; i!= obj->size; i++ )
-			_recurse_jsonObjectToXML(jsonObjectGetIndex(obj,i), res_xml);
-
-		buffer_add(res_xml,"</array>");
-
-	} else if (obj->type == JSON_HASH) {
-
-		if (hint)
-        	       	buffer_fadd(res_xml,"<object class_hint=\"%s\">", hint);
-		else
-			buffer_add(res_xml,"<object>");
-
-		jsonIterator* itr = jsonNewIterator(obj);
-		jsonObject* tmp;
-		while( (tmp = jsonIteratorNext(itr)) ) {
-			buffer_fadd(res_xml,"<element key=\"%s\">",itr->key);
-			_recurse_jsonObjectToXML(tmp, res_xml);
-			buffer_add(res_xml,"</element>");
-		}
-		jsonIteratorFree(itr);
-
-		buffer_add(res_xml,"</object>");
-	}
-
-	if (hint)
-		free(hint);
-
-	return 1;
-}
-
-char* _escape_xml (char* text) {
-	char* out;
-	growing_buffer* b = buffer_init(256);
-	int len = strlen(text);
-	int i;
-	for (i = 0; i < len; i++) {
-		if (text[i] == '&')
-			buffer_add(b,"&amp;");
-		else if (text[i] == '<')
-			buffer_add(b,"&lt;");
-		else if (text[i] == '>')
-			buffer_add(b,"&gt;");
-		else
-			buffer_add_char(b,text[i]);
-	}
-	out = buffer_data(b);
-	buffer_free(b);
-	return out;
-}
-
-*/
-
 jsonObject* jsonParseFile( char* filename ) {
 	if(!filename) return NULL;
 	char* data = file_to_string(filename);



More information about the opensrf-commits mailing list