return G_VALUE_TYPE (val);
}
-/* keep in sync with gstvalue.c */
-#define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
- ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
- ((c) == '.'))
-
gboolean
priv_gst_structure_append_to_gstring (const GstStructure * structure,
GString * s)
s++;
c = *name_end;
- *name_end = 0;
+ *name_end = '\0';
field->name = g_quark_from_string (name);
*name_end = c;
int ret = 0;
GType type = default_type;
-
s = str;
while (g_ascii_isspace (*s))
s++;
return FALSE;
c = *value_end;
- *value_end = 0;
+ *value_end = '\0';
if (type == G_TYPE_INVALID) {
GType try_types[] =
{ G_TYPE_INT, G_TYPE_DOUBLE, GST_TYPE_FRACTION, G_TYPE_BOOLEAN,
}
save = *w;
- *w = 0;
+ *w = '\0';
structure = gst_structure_empty_new (name);
*w = save;
if (!gst_structure_parse_field (r, &r, &field))
goto error;
gst_structure_set_field (structure, &field);
-
} while (TRUE);
if (end)
static gint gst_value_compare_with_func (const GValue * value1,
const GValue * value2, GstValueCompareFunc compare);
+static gchar *gst_string_wrap (const gchar * s);
+static gchar *gst_string_unwrap (const gchar * s);
+
/********
* list *
********/
{
GstStructure *structure = g_value_get_boxed (value);
- return gst_structure_to_string (structure);
+ return gst_string_wrap (gst_structure_to_string (structure));
}
static gboolean
{
GstStructure *structure;
- structure = gst_structure_from_string (s, NULL);
+ if (*s != '"') {
+ structure = gst_structure_from_string (s, NULL);
+ } else {
+ gchar *str = gst_string_unwrap (s);
+
+ if (!str)
+ return FALSE;
+
+ structure = gst_structure_from_string (str, NULL);
+ }
if (structure) {
g_value_set_boxed (dest, structure);
}
}
-/* keep in sync with gststructure.c */
-#define GST_ASCII_IS_STRING(c) (g_ascii_isalnum((c)) || ((c) == '_') || \
- ((c) == '-') || ((c) == '+') || ((c) == '/') || ((c) == ':') || \
- ((c) == '.'))
-
static gchar *
gst_string_wrap (const gchar * s)
{
GstStructure *sp, *sc1, *sc2;
gchar *str;
- sc1 =
- gst_structure_new ("Camera", "XResolution", G_TYPE_INT, 72, "YResolution",
- G_TYPE_INT, 73, NULL);
+ sc1 = gst_structure_new ("Camera",
+ "XResolution", G_TYPE_INT, 72, "YResolution", G_TYPE_INT, 73, NULL);
fail_unless (sc1 != NULL);
- sc2 =
- gst_structure_new ("Image-Data", "Orientation", G_TYPE_STRING, "top-left",
- NULL);
+ sc2 = gst_structure_new ("Image-Data",
+ "Orientation", G_TYPE_STRING, "top-left",
+ "Comment", G_TYPE_STRING, "super photo", NULL);
fail_unless (sc2 != NULL);
sp = gst_structure_new ("Exif", "Camera", GST_TYPE_STRUCTURE, sc1,
"Image Data", GST_TYPE_STRUCTURE, sc2, NULL);
fail_unless (sp != NULL);
+ fail_unless (gst_structure_n_fields (sp) == 2);
+
fail_unless (gst_structure_has_field_typed (sp, "Camera",
GST_TYPE_STRUCTURE));
str = gst_structure_to_string (sp);
fail_unless (str != NULL);
+ GST_DEBUG ("serialized to '%s'", str);
+
fail_unless (g_str_equal (str,
"Exif"
- ", Camera=(structure)Camera, XResolution=(int)72, YResolution=(int)73;"
- ", Image Data=(structure)Image-Data, Orientation=(string)top-left;;"));
+ ", Camera=(structure)\"Camera\\,\\ XResolution\\=\\(int\\)72\\,\\ YResolution\\=\\(int\\)73\\;\""
+ ", Image Data=(structure)\"Image-Data\\,\\ Orientation\\=\\(string\\)top-left\\,\\ Comment\\=\\(string\\)\\\"super\\\\\\ photo\\\"\\;\";"));
g_free (str);
str = NULL;
gst_structure_free (sc1);
gst_structure_free (sc2);
gst_structure_free (sp);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_structure_nested_from_and_to_string)
+{
+ GstStructure *s;
+ gchar *str1, *str2, *end = NULL;
+
+ str1 = "main"
+ ", main-sub1=(structure)\"type-b\\,\\ machine-type\\=\\(int\\)0\\;\""
+ ", main-sub2=(structure)\"type-a\\,\\ plugin-filename\\=\\(string\\)\\\"/home/user/lib/lib\\\\\\ with\\\\\\ spaces.dll\\\"\\,\\ machine-type\\=\\(int\\)1\\;\""
+ ", main-sub3=(structure)\"type-b\\,\\ plugin-filename\\=\\(string\\)/home/user/lib/lib_no_spaces.so\\,\\ machine-type\\=\\(int\\)1\\;\""
+ ";";
+ s = gst_structure_from_string (str1, &end);
+ fail_unless (s != NULL);
+
+ GST_DEBUG ("not parsed part : %s", end);
+ fail_unless (*end == '\0');
+
+ fail_unless (gst_structure_n_fields (s) == 3);
+
+ fail_unless (gst_structure_has_field_typed (s, "main-sub1",
+ GST_TYPE_STRUCTURE));
+
+ str2 = gst_structure_to_string (s);
+ fail_unless (str2 != NULL);
+
+ fail_unless (g_str_equal (str1, str2));
+
+ g_free (str2);
+
+ gst_structure_free (s);
}
GST_END_TEST;
tcase_add_test (tc_chain, test_fixate);
tcase_add_test (tc_chain, test_fixate_frac_list);
tcase_add_test (tc_chain, test_structure_nested);
+ tcase_add_test (tc_chain, test_structure_nested_from_and_to_string);
tcase_add_test (tc_chain, test_empty_string_fields);
return s;
}