[Goodies-commits] r5674 - xfbib/branches/gobject/src

David Gustafsson tssj at xfce.org
Sat Oct 18 03:10:31 CEST 2008


Author: tssj
Date: 2008-10-18 01:10:31 +0000 (Sat, 18 Oct 2008)
New Revision: 5674

Added:
   xfbib/branches/gobject/src/xfbib-string.c
   xfbib/branches/gobject/src/xfbib-string.h
Modified:
   xfbib/branches/gobject/src/Makefile.am
   xfbib/branches/gobject/src/xfbib-bibtex-comment.c
   xfbib/branches/gobject/src/xfbib-bibtex-entry.c
   xfbib/branches/gobject/src/xfbib-bibtex-entry.h
   xfbib/branches/gobject/src/xfbib-bibtex-field.c
   xfbib/branches/gobject/src/xfbib-bibtex-string.c
   xfbib/branches/gobject/src/xfbib-bibtex-value.c
   xfbib/branches/gobject/src/xfbib-bibtex.c
   xfbib/branches/gobject/src/xfbib-file-io.c
   xfbib/branches/gobject/src/xfbib-integer.c
   xfbib/branches/gobject/src/xfbib-integer.h
   xfbib/branches/gobject/src/xfbib-window.c
Log:
Merging from XfbibStrbuf to GString, also added an object for strings
much like have already been done with integer.


Modified: xfbib/branches/gobject/src/Makefile.am
===================================================================
--- xfbib/branches/gobject/src/Makefile.am	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/Makefile.am	2008-10-18 01:10:31 UTC (rev 5674)
@@ -34,6 +34,8 @@
 	xfbib-statusbar.h \
 	xfbib-strbuf.c \
 	xfbib-strbuf.h \
+	xfbib-string.c \
+	xfbib-string.h \
 	xfbib-bibtex-string.c \
 	xfbib-bibtex-string.h \
 	xfbib-toolbar.c \

Modified: xfbib/branches/gobject/src/xfbib-bibtex-comment.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-comment.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-bibtex-comment.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -23,12 +23,11 @@
 #include <gtk/gtk.h>
 
 #include "xfbib-bibtex-comment.h"
-#include "xfbib-strbuf.h"
 
 struct _XfbibBibtexComment
 {
 	GObject parent;
-	XfbibStrbuf *strbuf;
+	gchar *str;
 };
 
 typedef struct _XfbibBibtexCommentClass
@@ -53,12 +52,13 @@
 static void
 xfbib_bibtex_comment_init(XfbibBibtexComment *instance)
 {
-	instance->strbuf = xfbib_strbuf_new();
+	instance->str = NULL;
 }
 
 static void
 xfbib_bibtex_comment_finalize(GObject *obj)
 {
+	free(XFBIB_BIBTEX_COMMENT(obj)->str);
 	G_OBJECT_CLASS(xfbib_bibtex_comment_parent_class)->finalize(obj);
 }
 
@@ -67,6 +67,6 @@
 {
 	XfbibBibtexComment *comment;
 	comment = g_object_new(XFBIB_TYPE_BIBTEX_COMMENT, NULL);
-	xfbib_strbuf_append(comment->strbuf, str);
+	comment->str = g_strdup(str);
 	return comment;
 }

Modified: xfbib/branches/gobject/src/xfbib-bibtex-entry.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-entry.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-bibtex-entry.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -26,13 +26,12 @@
 
 #include "xfbib-bibtex-entry.h"
 #include "xfbib-bibtex-field.h"
-#include "xfbib-strbuf.h"
 
 struct _XfbibBibtexEntry
 {
 	GObject parent;
-	XfbibStrbuf *bibtype;
-	XfbibStrbuf *key;
+	gchar *bibtype;
+	gchar *key;
 	GList *fields;
 };
 
@@ -58,8 +57,8 @@
 static void
 xfbib_bibtex_entry_init(XfbibBibtexEntry *instance)
 {
-	instance->key = xfbib_strbuf_new();
-	instance->bibtype = xfbib_strbuf_new();
+	instance->key = NULL;
+	instance->bibtype = NULL;
 	instance->fields = NULL;
 }
 
@@ -67,8 +66,8 @@
 xfbib_bibtex_entry_finalize(GObject *obj)
 {
 	XfbibBibtexEntry *entry = XFBIB_BIBTEX_ENTRY(obj);
-	g_object_unref(entry->key);
-	g_object_unref(entry->bibtype);
+	free(entry->key);
+	free(entry->bibtype);
 	g_list_foreach (entry->fields, (GFunc) g_object_unref, NULL);
 	g_list_free (entry->fields);
 	G_OBJECT_CLASS(xfbib_bibtex_entry_parent_class)->finalize(obj);
@@ -86,36 +85,41 @@
 xfbib_bibtex_entry_parse(XfbibBibtexEntry *entry, const gchar *str)
 {
 	gchar *tmp;
-	XfbibStrbuf *buf;
+	GString *buf;
 	XfbibBibtexField *field;
 	gint i, brackets, quotes;
 
 	DBG("str = %s", str);
 
+	buf = g_string_new("");
+
 	/* Dont copy the last bracket */
 	tmp = g_strndup(str, strlen(str) - 1);
 
 	/* Parse entry type */
 	for (i = 0; i < strlen(tmp) && tmp[i] != '{' && tmp[i] != '('; i++)
-		xfbib_strbuf_append_char(entry->bibtype, tmp[i]);
+		buf = g_string_append_c(buf, tmp[i]);
+	entry->bibtype = g_strdup(buf->str);
 
 	if (i == strlen(tmp)) {
 		return FALSE;
 	}
 
+	buf = g_string_erase(buf, 0, -1);
 	/* Parse the entry key */
 	for (i++; tmp[i] != '\0' && tmp[i] != ','; i++)
-		xfbib_strbuf_append_char(entry->key, tmp[i]);
+		buf = g_string_append_c(buf, tmp[i]);
+	entry->key = g_strdup(buf->str);
 
-	buf = xfbib_strbuf_new();
+	buf = g_string_erase(buf, 0, -1);
 
 	for (i++, brackets = 0, quotes = 0; i < strlen(tmp); i++) {
 		if (tmp[i] == ',' && brackets == 0 && quotes%2 == 0) {
 			field = xfbib_bibtex_field_new();
-			if (!xfbib_bibtex_field_parse(field, xfbib_strbuf_get_str(buf)))
+			if (!xfbib_bibtex_field_parse(field, buf->str))
 				return FALSE;
 			entry->fields = g_list_append(entry->fields, field);
-			xfbib_strbuf_wipe(buf);
+			buf = g_string_erase(buf, 0, -1);
 			continue;
 		} else if (tmp[i] == '{' || tmp[i] == '(') {
 			brackets++;
@@ -124,23 +128,24 @@
 		} else if (tmp[i] == '"') {
 			quotes++;
 		}
-		xfbib_strbuf_append_char(buf, tmp[i]);
+		buf = g_string_append_c(buf, tmp[i]);
 	}
 
 	/* When the last row has a comma their will be nothing here to parse */
-	for (i = 0; i < xfbib_strbuf_len(buf); i++) {
-		if(!g_ascii_isspace(xfbib_strbuf_get_nth_char(buf, i)))
+	for (i = 0; i < buf->len; i++) {
+		if(!g_ascii_isspace(buf->str[i]))
 			break;
 	}
 
-	if (i < xfbib_strbuf_len(buf)) {
+	if (i < buf->len) {
 		field = xfbib_bibtex_field_new();
-		if (!xfbib_bibtex_field_parse(field, xfbib_strbuf_get_str(buf)))
+		if (!xfbib_bibtex_field_parse(field, buf->str))
 			return FALSE;
 		entry->fields = g_list_append(entry->fields, field);
 	}
-
-	g_object_unref(G_OBJECT(buf));
+	
+	g_string_free(buf, TRUE);
+//	g_object_unref(G_OBJECT(buf));
 	g_free(tmp);
 
 	return TRUE;
@@ -163,26 +168,26 @@
 	entry->fields = list;
 }
 
-const gchar *
+gchar *
 xfbib_bibtex_entry_get_key(XfbibBibtexEntry *entry)
 {
 	g_return_val_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry), NULL);
-	return xfbib_strbuf_get_str(entry->key);
+	return entry->key;
 }
 
 void 
 xfbib_bibtex_entry_set_key(XfbibBibtexEntry *entry, const gchar *key)
 {
 	g_return_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry));
-	xfbib_strbuf_wipe(entry->key);
-	xfbib_strbuf_append(entry->key, key);
+	free(entry->key);
+	entry->key = g_strdup(key);
 }
 
-const gchar *
+gchar *
 xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *entry)
 {
 	g_return_val_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry), NULL);
-	return xfbib_strbuf_get_str(entry->bibtype);
+	return entry->bibtype;
 }
 
 
@@ -190,55 +195,7 @@
 xfbib_bibtex_entry_set_bibtype(XfbibBibtexEntry *entry, const gchar *bibtype)
 {
 	g_return_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry));
-	xfbib_strbuf_wipe(entry->bibtype);
-	xfbib_strbuf_append(entry->bibtype, bibtype);
+	free(entry->bibtype);
+	entry->bibtype = g_strdup(bibtype);
 }
 
-#if 0
-XfbibBibtexField *
-xfbib_bibtex_entry_get_field_by_column(XfbibBibtexEntry *entry, gint column)
-{
-	XfbibBibtexField *field;
-	gint i;
-	g_return_val_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry), NULL);
-
-	for (i = 0; i < g_list_length(entry->fields); i++) {
-		field = g_list_nth_data(entry->fields, i);
-		if (xfbib_bibtex_field_is_column(field, column)) {
-			return field;
-		}
-	}
-
-	return NULL;
-}
-
-XfbibStrbuf *
-xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *entry)
-{
-	return entry->bibtype;
-}
-
-XfbibStrbuf *
-xfbib_bibtex_entry_get_key(XfbibBibtexEntry *entry)
-{
-	return entry->key;
-}
-
-void
-xfbib_bibtex_entry_set_key(XfbibBibtexEntry *entry, const gchar *key)
-{
-	xfbib_strbuf_append(entry->key, key);
-}
-
-void
-xfbib_bibtex_entry_set_bibtype(XfbibBibtexEntry *entry, const gchar *bibtype)
-{
-	xfbib_strbuf_append(entry->bibtype, bibtype);
-}
-
-void
-xfbib_bibtex_entry_set_fields(XfbibBibtexEntry *entry, GList *fields)
-{
-	entry->fields = fields;
-}
-#endif

Modified: xfbib/branches/gobject/src/xfbib-bibtex-entry.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-entry.h	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-bibtex-entry.h	2008-10-18 01:10:31 UTC (rev 5674)
@@ -41,9 +41,9 @@
 gboolean xfbib_bibtex_entry_parse(XfbibBibtexEntry *, const gchar *);
 GList *xfbib_bibtex_entry_get_fields(XfbibBibtexEntry *);
 void xfbib_bibtex_entry_set_fields(XfbibBibtexEntry *, GList *);
-const gchar *xfbib_bibtex_entry_get_key(XfbibBibtexEntry *);
+gchar *xfbib_bibtex_entry_get_key(XfbibBibtexEntry *);
 void xfbib_bibtex_entry_set_key(XfbibBibtexEntry *, const gchar *);
-const gchar *xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *);
+gchar *xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *);
 void xfbib_bibtex_entry_set_bibtype(XfbibBibtexEntry *, const gchar *);
 #if 0
 XfbibBibtexField *xfbib_bibtex_entry_get_field_by_column(XfbibBibtexEntry *, gint);

Modified: xfbib/branches/gobject/src/xfbib-bibtex-field.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-field.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-bibtex-field.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -23,13 +23,12 @@
 #include <gtk/gtk.h>
 
 #include "xfbib-bibtex-field.h"
-#include "xfbib-strbuf.h"
 #include "xfbib-bibtex-value.h"
 
 struct _XfbibBibtexField
 {
 	GObject parent;
-	XfbibStrbuf *variable;
+	gchar *variable;
 	XfbibBibtexValue *value;
 };
 
@@ -55,13 +54,14 @@
 static void
 xfbib_bibtex_field_init(XfbibBibtexField *instance)
 {
-	instance->variable = xfbib_strbuf_new();
+	instance->variable = NULL;
 	instance->value = xfbib_bibtex_value_new();
 }
 
 static void
 xfbib_bibtex_field_finalize(GObject *obj)
 {
+	free(XFBIB_BIBTEX_FIELD(obj)->variable);
 	G_OBJECT_CLASS(xfbib_bibtex_field_parent_class)->finalize(obj);
 }
 
@@ -89,9 +89,9 @@
 	}
 
 	/* Variable */
-	xfbib_strbuf_wipe(field->variable);
+	free(field->variable);
 	g_strstrip(split[0]);
-	xfbib_strbuf_append(field->variable, split[0]);
+	field->variable = g_strdup(split[0]);
 
 	/* Value */
 	if (!xfbib_bibtex_value_parse(field->value, split[1])) {
@@ -107,7 +107,7 @@
 xfbib_bibtex_field_get_variable(XfbibBibtexField *field)
 {
 	g_return_val_if_fail(XFBIB_IS_BIBTEX_FIELD(field), NULL);	
-	return xfbib_strbuf_get_str(field->variable);
+	return field->variable;
 }
 
 void 
@@ -115,8 +115,8 @@
 {
 	g_return_if_fail(XFBIB_IS_BIBTEX_FIELD(field));
 	
-	xfbib_strbuf_wipe(field->variable);
-	xfbib_strbuf_append(field->variable, str);
+	free(field->variable);
+	field->variable = g_strdup(str);
 }
 
 XfbibBibtexValue *
@@ -134,36 +134,3 @@
 	field->value = value;
 }
 
-
-#if 0
-gboolean
-xfbib_bibtex_field_is_column(XfbibBibtexField *field, gint column)
-{
-	if (strcasecmp(xfbib_strbuf_get_str(field->variable),
-				xfbib_bibtex_field_constants[column].label) == 0) {
-		return TRUE;
-	}
-	return FALSE;
-}
-
-const gchar *
-xfbib_bibtex_field_get_value_str(XfbibBibtexField *field)
-{
-	return xfbib_bibtex_value_get_str(field->value);
-}
-
-void
-xfbib_bibtex_field_set_variable(XfbibBibtexField *field, const gchar *str)
-{
-	xfbib_strbuf_append(field->variable,str);
-}
-
-void
-xfbib_bibtex_field_set_value(XfbibBibtexField *field, XfbibBibtexValue *value)
-{
-	if(field->value != NULL) {
-		free(field->value);
-	}
-	field->value = value;
-}
-#endif

Modified: xfbib/branches/gobject/src/xfbib-bibtex-string.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-string.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-bibtex-string.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -24,13 +24,12 @@
 #include <string.h>
 
 #include "xfbib-bibtex-string.h"
-#include "xfbib-strbuf.h"
 #include "xfbib-bibtex-value.h"
 
 struct _XfbibBibtexString
 {
 	GObject parent;
-	XfbibStrbuf *variable;
+	gchar *variable;
 	XfbibBibtexValue *value;
 };
 
@@ -70,7 +69,7 @@
 	XfbibBibtexString *string;
 	string = g_object_new(XFBIB_TYPE_BIBTEX_STRING, NULL);
 
-	string->variable = xfbib_strbuf_new();
+	string->variable = NULL;
 	string->value = xfbib_bibtex_value_new();
 
 	return string;
@@ -79,14 +78,14 @@
 const gchar *
 xfbib_bibtex_string_get_variable(XfbibBibtexString *string)
 {
-	return xfbib_strbuf_get_str(string->variable);
+	return string->variable;
 }
 
 void
 xfbib_bibtex_string_set_variable(XfbibBibtexString *string, const gchar *variable)
 {
-	xfbib_strbuf_wipe(string->variable);
-	xfbib_strbuf_append(string->variable, variable);
+	free(string->variable);
+	string->variable = g_strdup(variable);
 }
 
 void
@@ -110,9 +109,9 @@
 	}
 
 	/* Variable */
-	xfbib_strbuf_wipe(string->variable);
+	free(string->variable);
 	g_strstrip(split[0] + 7);
-	xfbib_strbuf_append(string->variable, split[0] + 8);
+	string->variable = g_strdup(split[0] + 8);
 
 	/* Value */
 	tmp = g_strndup(split[1], strlen(split[1]) - 1);

Modified: xfbib/branches/gobject/src/xfbib-bibtex-value.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-value.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-bibtex-value.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -5,8 +5,8 @@
 #include <string.h>
 
 #include "xfbib-bibtex-value.h"
-#include "xfbib-strbuf.h"
 #include "xfbib-bibtex-string.h"
+#include "xfbib-string.h"
 #include "xfbib-integer.h"
 
 
@@ -122,8 +122,8 @@
 				return FALSE;
 			}
 
-			obj = G_OBJECT(xfbib_strbuf_new());
-			xfbib_strbuf_append(XFBIB_STRBUF(obj), split[i]);
+			obj = G_OBJECT(xfbib_string_new());
+			xfbib_string_set(XFBIB_STRING(obj), split[i]);
 			value->list = g_list_prepend(value->list, obj);
 		} else if(g_ascii_isalpha(split[i][0])) {
 			/* Variable */
@@ -191,12 +191,12 @@
 		if (XFBIB_IS_BIBTEX_STRING(obj)) {
 			/* variable */
 			return "todo: variable";
-		} else if (XFBIB_IS_STRBUF(obj)) {
+		} else if (XFBIB_IS_STRING(obj)) {
 			/* regular string */
-			return xfbib_strbuf_get_str(XFBIB_STRBUF(obj));
+			return xfbib_string_get(XFBIB_STRING(obj));
 		} else if (XFBIB_IS_INTEGER(obj)) {
 			/* integer value */
-			return "todo: integer";
+			return xfbib_integer_get(XFBIB_INTEGER(obj));
 		}	
 	}
 	return NULL;
@@ -208,7 +208,7 @@
 void
 xfbib_bibtex_value_set_str(XfbibBibtexValue *value, const gchar *str)
 {
-	XfbibStrbuf *strbuf;
+	XfbibString *string;
 	g_return_if_fail(XFBIB_IS_BIBTEX_VALUE(value));
 	
 	/* Remove all values */
@@ -216,8 +216,8 @@
 	g_list_free (value->list);
 	value->list = NULL;
 	
-	strbuf = xfbib_strbuf_new();
-	xfbib_strbuf_append(strbuf, str);
-	value->list = g_list_append(value->list, G_OBJECT(strbuf));	
+	string = xfbib_string_new();
+	xfbib_string_set(string, str);
+	value->list = g_list_append(value->list, G_OBJECT(string));	
 }
 

Modified: xfbib/branches/gobject/src/xfbib-bibtex.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-bibtex.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -6,7 +6,6 @@
 
 #include "xfbib-bibtex.h"
 #include "xfbib-bibtex-entry.h"
-#include "xfbib-strbuf.h"
 #include "xfbib-bibtex-comment.h"
 #include "xfbib-bibtex-preamble.h"
 #include "xfbib-bibtex-string.h"
@@ -65,13 +64,13 @@
 
 
 static gboolean
-parse_balanced_brackets(XfbibStrbuf *buf, const gchar *str, gint *i)
+parse_balanced_brackets(GString *buf, const gchar *str, gint *i)
 {
 	gint brackets;
 	gchar bracket_type;
 
 	while (str[(*i)] != '{' && str[(*i)] != '(') {
-		xfbib_strbuf_append_char(buf, str[(*i)]);
+		buf = g_string_append_c(buf, str[(*i)]);
 		(*i)++;
 	}
 
@@ -84,7 +83,7 @@
 		return FALSE;
 	}
 
-	xfbib_strbuf_append_char(buf, str[(*i)]);
+	buf = g_string_append_c(buf, str[(*i)]);
 	(*i)++;
 
 	for (brackets = 1; brackets > 0; (*i)++) {
@@ -103,7 +102,7 @@
 			return FALSE;;
 			/* Strange */
 		}
-		xfbib_strbuf_append_char(buf, str[(*i)]);
+		buf = g_string_append_c(buf, str[(*i)]);
 	}
 	return TRUE;
 }
@@ -115,9 +114,9 @@
 	gint i;
 	GRegex *regex;
 	GObject *obj;
-	XfbibStrbuf *buf;
+	GString *buf;
 
-	buf = xfbib_strbuf_new();
+	buf = g_string_new("");
 
 	/* Compile the regex for the entry types */
 	regex = g_regex_new("^@(article|book|booklet|conference|inbook|incollection|inproceedings|manual|"
@@ -126,49 +125,49 @@
 
 	for (i = 0; i < strlen(str); i++) {
 		if (str[i] == '@') {
-			if (xfbib_strbuf_len(buf) > 0) {
+			if (buf->len > 0) {
 				/* The comment ended put it in the list */
-				obj = G_OBJECT(xfbib_bibtex_comment_new(xfbib_strbuf_get_str(buf)));
+				obj = G_OBJECT(xfbib_bibtex_comment_new(buf->str));
 				elements->list = g_list_append(elements->list, obj);
-				xfbib_strbuf_wipe(buf);
+				buf = g_string_erase(buf, 0, -1);
 			}
 			if (g_ascii_strncasecmp(&str[i], "@comment", 8) == 0) {
 				/* Comment */
 				for (; str[i] != '\n'; i++)
-					xfbib_strbuf_append_char(buf, str[i]);
+					buf = g_string_append_c(buf, str[i]);
 
 				/* Dont forget the newline character */
-				xfbib_strbuf_append_char(buf, str[i]);
+				buf = g_string_append_c(buf, str[i]);
 
-				obj = G_OBJECT(xfbib_bibtex_comment_new(xfbib_strbuf_get_str(buf)));
+				obj = G_OBJECT(xfbib_bibtex_comment_new(buf->str));
 				elements->list = g_list_append(elements->list, obj);
-				xfbib_strbuf_wipe(buf);
+				buf = g_string_erase(buf, 0, -1);
 			} else if (g_ascii_strncasecmp(&str[i], "@preamble", 9) == 0) {
 				/* Preamble */
 				if (parse_balanced_brackets(buf, str, &i)) {
 					obj = G_OBJECT(xfbib_bibtex_preamble_new());
-					if (xfbib_bibtex_preamble_parse(XFBIB_BIBTEX_PREAMBLE(obj), xfbib_strbuf_get_str(buf)))
+					if (xfbib_bibtex_preamble_parse(XFBIB_BIBTEX_PREAMBLE(obj), buf->str))
 						elements->list = g_list_append(elements->list, obj);
 				}
-				xfbib_strbuf_wipe(buf);
+				buf = g_string_erase(buf, 0, -1);
 			} else if (g_ascii_strncasecmp(&str[i], "@string", 7) == 0) {
 				/* String */
 				if (parse_balanced_brackets(buf, str, &i)) {
 					obj = G_OBJECT(xfbib_bibtex_string_new());
-					if (xfbib_bibtex_string_parse(XFBIB_BIBTEX_STRING(obj), xfbib_strbuf_get_str(buf)))
+					if (xfbib_bibtex_string_parse(XFBIB_BIBTEX_STRING(obj), buf->str))
 						elements->list = g_list_append(elements->list, obj);
 				}
-				xfbib_strbuf_wipe(buf);
+				buf = g_string_erase(buf, 0, -1);
 			} else if (g_regex_match (regex, &str[i], 0, NULL)) {
 				/* Entry */
 				if (parse_balanced_brackets(buf, str, &i)) {
 					obj = G_OBJECT(xfbib_bibtex_entry_new());
-					if (xfbib_bibtex_entry_parse(XFBIB_BIBTEX_ENTRY(obj), xfbib_strbuf_get_str(buf))) {
+					if (xfbib_bibtex_entry_parse(XFBIB_BIBTEX_ENTRY(obj), buf->str)) {
 						elements->n_entries++;
 						elements->list = g_list_append(elements->list, obj);
 					}
 				}
-				xfbib_strbuf_wipe(buf);
+				buf = g_string_erase(buf, 0, -1);
 			} else {
 				/* Error */
 				g_warning("Error, on line %d(TODO)\n", __LINE__);
@@ -176,9 +175,11 @@
 					continue;
 			}
 		} else {
-			xfbib_strbuf_append_char(buf, str[i]);
+			buf = g_string_append_c(buf, str[i]);
 		}
 	}
+
+	g_string_free(buf, TRUE);
 	g_regex_unref(regex);
 	return TRUE;
 }

Modified: xfbib/branches/gobject/src/xfbib-file-io.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-file-io.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-file-io.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -24,7 +24,6 @@
 #include <libxfcegui4/libxfcegui4.h>
 
 #include "xfbib-file-io.h"
-#include "xfbib-strbuf.h"
 #include "xfbib-state.h"
 #include "xfbib-bibtex.h"
 #include "xfbib-window.h"

Modified: xfbib/branches/gobject/src/xfbib-integer.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-integer.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-integer.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -23,12 +23,11 @@
 #include <gtk/gtk.h>
 
 #include "xfbib-integer.h"
-#include "xfbib-strbuf.h"
 
 struct _XfbibInteger
 {
 	GObject parent;
-	XfbibStrbuf *str;
+	gchar *str;
 };
 
 typedef struct _XfbibIntegerClass
@@ -53,7 +52,7 @@
 static void
 xfbib_integer_init(XfbibInteger *instance)
 {
-	instance->str = xfbib_strbuf_new();
+	instance->str = NULL;
 }
 
 static void
@@ -70,16 +69,15 @@
 	return integer;
 }
 
-const gchar *
+gchar *
 xfbib_integer_get(XfbibInteger *integer)
 {
-	return xfbib_strbuf_get_str(integer->str);
+	return integer->str;
 }
 
 void
 xfbib_integer_set(XfbibInteger *integer, const gchar *str)
 {
-	xfbib_strbuf_wipe(integer->str);
-	xfbib_strbuf_append(integer->str, str);
+	free(integer->str);
+	integer->str = g_strdup(str);
 }
-

Modified: xfbib/branches/gobject/src/xfbib-integer.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-integer.h	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-integer.h	2008-10-18 01:10:31 UTC (rev 5674)
@@ -36,7 +36,7 @@
 GType xfbib_integer_get_type() G_GNUC_CONST;
 
 XfbibInteger *xfbib_integer_new();
-const gchar *xfbib_integer_get(XfbibInteger *);
+gchar *xfbib_integer_get(XfbibInteger *);
 void xfbib_integer_set(XfbibInteger *, const gchar *);
 
 G_END_DECLS

Added: xfbib/branches/gobject/src/xfbib-string.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.c	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-string.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -0,0 +1,84 @@
+/* 
+ * Copyright (c) 2008 Jesper Karlsson & David Gustafsson
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <gtk/gtk.h>
+
+#include "xfbib-string.h"
+
+struct _XfbibString
+{
+	GObject parent;
+	gchar *str;
+};
+
+typedef struct _XfbibStringClass
+{
+	GObjectClass parent;
+} XfbibStringClass;
+
+static void xfbib_string_class_init(XfbibStringClass *klass);
+
+static void xfbib_string_init(XfbibString *instance);
+static void xfbib_string_finalize(GObject *obj);
+
+G_DEFINE_TYPE(XfbibString, xfbib_string, G_TYPE_OBJECT)
+
+static void
+xfbib_string_class_init(XfbibStringClass *klass)
+{
+	GObjectClass *object_class = (GObjectClass *)klass;
+	object_class->finalize = xfbib_string_finalize;
+}
+
+static void
+xfbib_string_init(XfbibString *instance)
+{
+	instance->str = NULL;
+}
+
+static void
+xfbib_string_finalize(GObject *obj)
+{
+	G_OBJECT_CLASS(xfbib_string_parent_class)->finalize(obj);
+}
+
+XfbibString *
+xfbib_string_new()
+{
+	XfbibString *string;
+	string = g_object_new(XFBIB_TYPE_STRING, NULL);
+	return string;
+}
+
+gchar *
+xfbib_string_get(XfbibString *string)
+{
+	return string->str;
+}
+
+void
+xfbib_string_set(XfbibString *string, const gchar *str)
+{
+	free(string->str);
+	string->str = g_strdup(str);
+}
+

Added: xfbib/branches/gobject/src/xfbib-string.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.h	                        (rev 0)
+++ xfbib/branches/gobject/src/xfbib-string.h	2008-10-18 01:10:31 UTC (rev 5674)
@@ -0,0 +1,45 @@
+/* 
+ * Copyright (c) 2008 Jesper Karlsson & David Gustafsson
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __XFBIB_STRING_H
+#define __XFBIB_STRING_H
+
+#include <glib-object.h>
+
+#define XFBIB_TYPE_STRING             (xfbib_string_get_type())
+#define XFBIB_STRING(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_STRING, XfbibString))
+#define XFBIB_IS_STRING(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFBIB_TYPE_STRING))
+#define XFBIB_STRING_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass), XFBIB_TYPE_STRING, XfbibStringClass))
+#define XFBIB_IS_STRING_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass), XFBIB_TYPE_STRING))
+#define XFBIB_STRING_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), XFBIB_TYPE_STRING, XfbibStringClass))
+
+G_BEGIN_DECLS
+
+typedef struct _XfbibString         XfbibString;
+
+GType xfbib_string_get_type() G_GNUC_CONST;
+
+XfbibString *xfbib_string_new();
+gchar *xfbib_string_get(XfbibString *);
+void xfbib_string_set(XfbibString *, const gchar *);
+
+G_END_DECLS
+
+#endif //__XFBIB_STRING_H
+

Modified: xfbib/branches/gobject/src/xfbib-window.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-window.c	2008-10-17 23:35:19 UTC (rev 5673)
+++ xfbib/branches/gobject/src/xfbib-window.c	2008-10-18 01:10:31 UTC (rev 5674)
@@ -27,7 +27,6 @@
 #include "xfbib-toolbar.h"
 #include "xfbib-tree-view.h"
 #include "xfbib-statusbar.h"
-#include "xfbib-strbuf.h"
 #include "xfbib-file-io.h"
 
 struct _XfbibWindow




More information about the Goodies-commits mailing list