-/*
- * r will still point to the string. if end == next, the string will not be
- * null-terminated. In all other cases it will be.
- * end = pointer to char behind end of string, next = pointer to start of
- * unread data.
- * THIS FUNCTION MODIFIES THE STRING AND DETECTS INSIDE A NONTERMINATED STRING
- */
-static gboolean
-gst_structure_parse_string (gchar * s, gchar ** end, gchar ** next,
- gboolean unescape)
-{
- gchar *w;
-
- if (*s == 0)
- return FALSE;
-
- if (*s != '"') {
- int ret;
-
- ret = gst_structure_parse_simple_string (s, end);
- *next = *end;
-
- return ret;
- }
-
- if (unescape) {
- w = s;
- s++;
- while (*s != '"') {
- if (G_UNLIKELY (*s == 0))
- return FALSE;
- if (G_UNLIKELY (*s == '\\'))
- s++;
- *w = *s;
- w++;
- s++;
- }
- s++;
- } else {
- /* Find the closing quotes */
- s++;
- while (*s != '"') {
- if (G_UNLIKELY (*s == 0))
- return FALSE;
- if (G_UNLIKELY (*s == '\\'))
- s++;
- s++;
- }
- s++;
- w = s;
- }
-
- *end = w;
- *next = s;
-
- return TRUE;
-}
-
-static gboolean
-gst_structure_parse_range (gchar * s, gchar ** after, GValue * value,
- GType type)
-{
- GValue value1 = { 0 };
- GValue value2 = { 0 };
- GValue value3 = { 0 };
- GType range_type;
- gboolean ret, have_step = FALSE;
-
- if (*s != '[')
- return FALSE;
- s++;
-
- ret = gst_structure_parse_value (s, &s, &value1, type);
- if (ret == FALSE)
- return FALSE;
-
- while (g_ascii_isspace (*s))
- s++;
-
- if (*s != ',')
- return FALSE;
- s++;
-
- while (g_ascii_isspace (*s))
- s++;
-
- ret = gst_structure_parse_value (s, &s, &value2, type);
- if (ret == FALSE)
- return FALSE;
-
- while (g_ascii_isspace (*s))
- s++;
-
- /* optional step for int and int64 */
- if (G_VALUE_TYPE (&value1) == G_TYPE_INT
- || G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
- if (*s == ',') {
- s++;
-
- while (g_ascii_isspace (*s))
- s++;
-
- ret = gst_structure_parse_value (s, &s, &value3, type);
- if (ret == FALSE)
- return FALSE;
-
- while (g_ascii_isspace (*s))
- s++;
-
- have_step = TRUE;
- }
- }
-
- if (*s != ']')
- return FALSE;
- s++;
-
- if (G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value2))
- return FALSE;
- if (have_step && G_VALUE_TYPE (&value1) != G_VALUE_TYPE (&value3))
- return FALSE;
-
- if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
- range_type = GST_TYPE_DOUBLE_RANGE;
- g_value_init (value, range_type);
- gst_value_set_double_range (value,
- gst_g_value_get_double_unchecked (&value1),
- gst_g_value_get_double_unchecked (&value2));
- } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
- range_type = GST_TYPE_INT_RANGE;
- g_value_init (value, range_type);
- if (have_step)
- gst_value_set_int_range_step (value,
- gst_g_value_get_int_unchecked (&value1),
- gst_g_value_get_int_unchecked (&value2),
- gst_g_value_get_int_unchecked (&value3));
- else
- gst_value_set_int_range (value, gst_g_value_get_int_unchecked (&value1),
- gst_g_value_get_int_unchecked (&value2));
- } else if (G_VALUE_TYPE (&value1) == G_TYPE_INT64) {
- range_type = GST_TYPE_INT64_RANGE;
- g_value_init (value, range_type);
- if (have_step)
- gst_value_set_int64_range_step (value,
- gst_g_value_get_int64_unchecked (&value1),
- gst_g_value_get_int64_unchecked (&value2),
- gst_g_value_get_int64_unchecked (&value3));
- else
- gst_value_set_int64_range (value,
- gst_g_value_get_int64_unchecked (&value1),
- gst_g_value_get_int64_unchecked (&value2));
- } else if (G_VALUE_TYPE (&value1) == GST_TYPE_FRACTION) {
- range_type = GST_TYPE_FRACTION_RANGE;
- g_value_init (value, range_type);
- gst_value_set_fraction_range (value, &value1, &value2);
- } else {
- return FALSE;
- }
-
- *after = s;
- return TRUE;
-}
-
-static gboolean
-gst_structure_parse_any_list (gchar * s, gchar ** after, GValue * value,
- GType type, GType list_type, char begin, char end)
-{
- GValue list_value = { 0 };
- gboolean ret;
- GArray *array;
-
- g_value_init (value, list_type);
- array = g_value_peek_pointer (value);
-
- if (*s != begin)
- return FALSE;
- s++;
-
- while (g_ascii_isspace (*s))
- s++;
- if (*s == end) {
- s++;
- *after = s;
- return TRUE;
- }
-
- ret = gst_structure_parse_value (s, &s, &list_value, type);
- if (ret == FALSE)
- return FALSE;
-
- g_array_append_val (array, list_value);
-
- while (g_ascii_isspace (*s))
- s++;
-
- while (*s != end) {
- if (*s != ',')
- return FALSE;
- s++;
-
- while (g_ascii_isspace (*s))
- s++;
-
- memset (&list_value, 0, sizeof (list_value));
- ret = gst_structure_parse_value (s, &s, &list_value, type);
- if (ret == FALSE)
- return FALSE;
-
- g_array_append_val (array, list_value);
- while (g_ascii_isspace (*s))
- s++;
- }
-
- s++;
-
- *after = s;
- return TRUE;
-}
-
-static gboolean
-gst_structure_parse_list (gchar * s, gchar ** after, GValue * value, GType type)
-{
- return gst_structure_parse_any_list (s, after, value, type, GST_TYPE_LIST,
- '{', '}');
-}
-
-static gboolean
-gst_structure_parse_array (gchar * s, gchar ** after, GValue * value,
- GType type)
-{
- return gst_structure_parse_any_list (s, after, value, type,
- GST_TYPE_ARRAY, '<', '>');
-}
-
-static gboolean
-gst_structure_parse_simple_string (gchar * str, gchar ** end)
-{
- char *s = str;
-
- while (G_LIKELY (GST_ASCII_IS_STRING (*s))) {
- s++;
- }
-
- *end = s;
-
- return (s != str);
-}
-