diff options
| author | MenTaLguY <mental@rydia.net> | 2006-01-16 02:36:01 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2006-01-16 02:36:01 +0000 |
| commit | 179fa413b047bede6e32109e2ce82437c5fb8d34 (patch) | |
| tree | a5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/helper/gnome-utils.cpp | |
| download | inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip | |
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/helper/gnome-utils.cpp')
| -rw-r--r-- | src/helper/gnome-utils.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/helper/gnome-utils.cpp b/src/helper/gnome-utils.cpp new file mode 100644 index 000000000..aa70dd1a2 --- /dev/null +++ b/src/helper/gnome-utils.cpp @@ -0,0 +1,108 @@ +#define __GNOME_UTILS_C__ + +/* + * Helpers + * + * Author: + * Mitsuru Oka + * Lauris Kaplinski <lauris@kaplinski.com> + * + * Copyright (C) 2002 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <string.h> +#include <ctype.h> +#include <glib.h> + +/** + * gnome_uri_list_extract_uris: + * @uri_list: an uri-list in the standard format. + * + * Returns a GList containing strings allocated with g_malloc + * that have been splitted from @uri-list. + */ +GList* +gnome_uri_list_extract_uris (const gchar* uri_list) +{ + const gchar *p, *q; + gchar *retval; + GList *result = NULL; + + g_return_val_if_fail (uri_list != NULL, NULL); + + p = uri_list; + + /* We don't actually try to validate the URI according to RFC + * 2396, or even check for allowed characters - we just ignore + * comments and trim whitespace off the ends. We also + * allow LF delimination as well as the specified CRLF. + */ + while (p) { + if (*p != '#') { + while (isspace(*p)) + p++; + + q = p; + while (*q && (*q != '\n') && (*q != '\r')) + q++; + + if (q > p) { + q--; + while (q > p && isspace(*q)) + q--; + + retval = (gchar*)g_malloc (q - p + 2); + strncpy (retval, p, q - p + 1); + retval[q - p + 1] = '\0'; + + result = g_list_prepend (result, retval); + } + } + p = strchr (p, '\n'); + if (p) + p++; + } + + return g_list_reverse (result); +} + +/** + * gnome_uri_list_extract_filenames: + * @uri_list: an uri-list in the standard format + * + * Returns a GList containing strings allocated with g_malloc + * that contain the filenames in the uri-list. + * + * Note that unlike gnome_uri_list_extract_uris() function, this + * will discard any non-file uri from the result value. + */ +GList* +gnome_uri_list_extract_filenames (const gchar* uri_list) +{ + GList *tmp_list, *node, *result; + + g_return_val_if_fail (uri_list != NULL, NULL); + + result = gnome_uri_list_extract_uris (uri_list); + + tmp_list = result; + while (tmp_list) { + gchar *s = (gchar*)tmp_list->data; + + node = tmp_list; + tmp_list = tmp_list->next; + + if (!strncmp (s, "file:", 5)) { + node->data = g_filename_from_uri (s, NULL, NULL); + /* not sure if this fallback is useful at all */ + if (!node->data) node->data = g_strdup (s+5); + } else { + result = g_list_remove_link(result, node); + g_list_free_1 (node); + } + g_free (s); + } + return result; +} |
