[Goodies-commits] r5295 - in xfbib/branches/gobject: src tests
Jesper Karlsson
zarper at xfce.org
Sun Aug 24 17:28:45 CEST 2008
Author: zarper
Date: 2008-08-24 15:28:45 +0000 (Sun, 24 Aug 2008)
New Revision: 5295
Modified:
xfbib/branches/gobject/src/xfbib-value.c
xfbib/branches/gobject/src/xfbib-value.h
xfbib/branches/gobject/tests/Makefile.am
xfbib/branches/gobject/tests/test-xfbib-value.c
Log:
Started adding fuctionality to xfbib_value_parse() for basic parsing and added xfbib_value_wipe() for clearing a XfbibValue object.
Modified: xfbib/branches/gobject/src/xfbib-value.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-value.c 2008-08-24 13:25:13 UTC (rev 5294)
+++ xfbib/branches/gobject/src/xfbib-value.c 2008-08-24 15:28:45 UTC (rev 5295)
@@ -2,12 +2,16 @@
#include <config.h>
#endif
#include <gtk/gtk.h>
+#include <string.h>
#include "xfbib-value.h"
+#include "xfbib-strbuf.h"
struct _XfbibValue
{
GObject parent;
+ XfbibStrbuf *str;
+ XfbibValue *next;
};
typedef struct _XfbibValueClass
@@ -45,19 +49,58 @@
{
XfbibValue *value;
value = g_object_new(XFBIB_TYPE_VALUE, NULL);
+
+ value->str = xfbib_strbuf_new();
+ value->next = NULL;
+
return value;
}
gboolean
+xfbib_value_wipe(XfbibValue *value)
+{
+ if (value->next != NULL)
+ {
+ xfbib_value_wipe(value->next);
+ value->next = NULL;
+ }
+ xfbib_strbuf_wipe(value->str);
+ return TRUE;
+}
+
+gboolean
xfbib_value_parse(XfbibValue *value, const gchar *str)
{
-
- return FALSE;
+ int n;
+ gchar *lcb;
+ for (n = 0; n < strlen(str); n++)
+ {
+ switch (str[n])
+ {
+ case '#':
+ value->next = xfbib_value_new();
+ xfbib_value_parse(value->next, &str[n+1]);
+ n=strlen(str);
+ break;
+ default:
+ xfbib_strbuf_append_char(value->str, str[n]);
+ }
+ }
+ return TRUE;
}
-
-gchar *
+const gchar *
xfbib_value_get_str(XfbibValue *value)
{
- return "";
+ XfbibStrbuf *tmp;
+ tmp = xfbib_strbuf_new();
+
+ xfbib_strbuf_append(tmp, xfbib_strbuf_get_str(value->str));
+ if (value->next != NULL)
+ {
+ xfbib_strbuf_append_char(tmp, '#');
+ xfbib_strbuf_append(tmp, xfbib_value_get_str(value->next));
+ }
+
+ return xfbib_strbuf_get_str(tmp);
}
Modified: xfbib/branches/gobject/src/xfbib-value.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-value.h 2008-08-24 13:25:13 UTC (rev 5294)
+++ xfbib/branches/gobject/src/xfbib-value.h 2008-08-24 15:28:45 UTC (rev 5295)
@@ -18,8 +18,10 @@
XfbibValue *xfbib_value_new();
+
+gboolean xfbib_value_wipe(XfbibValue *value);
gboolean xfbib_value_parse(XfbibValue *, const gchar *);
-gchar *xfbib_value_get_str(XfbibValue *);
+const gchar *xfbib_value_get_str(XfbibValue *);
G_END_DECLS
#endif //__XFBIB_VALUE_H
Modified: xfbib/branches/gobject/tests/Makefile.am
===================================================================
--- xfbib/branches/gobject/tests/Makefile.am 2008-08-24 13:25:13 UTC (rev 5294)
+++ xfbib/branches/gobject/tests/Makefile.am 2008-08-24 15:28:45 UTC (rev 5295)
@@ -99,6 +99,7 @@
test-xfbib-value.c
test_xfbib_value_DEPENDENCIES = \
+ $(top_builddir)/src/xfbib-xfbib-strbuf.o \
$(top_builddir)/src/xfbib-xfbib-value.o
test_xfbib_value_LDADD = \
Modified: xfbib/branches/gobject/tests/test-xfbib-value.c
===================================================================
--- xfbib/branches/gobject/tests/test-xfbib-value.c 2008-08-24 13:25:13 UTC (rev 5294)
+++ xfbib/branches/gobject/tests/test-xfbib-value.c 2008-08-24 15:28:45 UTC (rev 5295)
@@ -26,6 +26,7 @@
* TODO:
* Implement a getter method that returns a list of objects.
* Check that the returned list contains the right objects
+ * What should happen if # sign is at the beginning or end?
*/
int main(int argc, char **argv)
@@ -38,30 +39,50 @@
g_assert(xfbib_value_parse(value, "\"Maintained by \" # maintainer"));
g_assert(strcmp(xfbib_value_get_str(value), "\"Maintained by \" # maintainer") == 0);
+ xfbib_value_wipe(value);
+
g_assert(xfbib_value_parse(value, "1921"));
g_assert(strcmp(xfbib_value_get_str(value), "1921") == 0);
+ xfbib_value_wipe(value);
+
g_assert(xfbib_value_parse(value, "\"april\""));
g_assert(strcmp(xfbib_value_get_str(value), "\"april\"") == 0);
+ xfbib_value_wipe(value);
+
g_assert(xfbib_value_parse(value, "firstname # \".\" # lastname # \"@imag.fr\""));
g_assert(strcmp(xfbib_value_get_str(value), "firstname # \".\" # lastname # \"@imag.fr\"") == 0);
+ xfbib_value_wipe(value);
+
g_assert(xfbib_value_parse(value, "\"The history of @ sign\""));
g_assert(strcmp(xfbib_value_get_str(value), "\"The history of @ sign\"") == 0);
+ xfbib_value_wipe(value);
+
g_assert(xfbib_value_parse(value, "\"Simon {\"}the {saint\"} Templar\""));
g_assert(strcmp(xfbib_value_get_str(value), "\"Simon {\"}the {saint\"} Templar\"") == 0);
+ xfbib_value_wipe(value);
+
g_assert(xfbib_value_parse(value, "\"A {bunch {of} braces {in}} title\""));
g_assert(strcmp(xfbib_value_get_str(value), "\"A {bunch {of} braces {in}} title\"") == 0);
+ xfbib_value_wipe(value);
+
g_assert(!xfbib_value_parse(value, "{ The history of @ sign }"));
+ xfbib_value_wipe(value);
+
g_assert(!xfbib_value_parse(value, "\"Simon \\\"the saint\\\" Templar\""));
+ xfbib_value_wipe(value);
+
g_assert(!xfbib_value_parse(value, "\"The lonely { brace\""));
+ xfbib_value_wipe(value);
+
g_object_unref(value);
return EXIT_SUCCESS;
More information about the Goodies-commits
mailing list