Author: miguel
Date: 2006-09-18 06:28:24 -0400 (Mon, 18 Sep 2006)
New Revision: 65568
Modified:
trunk/mono/eglib/ChangeLog
trunk/mono/eglib/TODO
trunk/mono/eglib/src/glib.h
trunk/mono/eglib/src/gstr.c
trunk/mono/eglib/test/string-util.c
Log:
2006-09-18 Miguel de Icaza <[EMAIL PROTECTED]>
* test/string-util.c (test_filename_from_uri): tests for new
methods.
* src/gstr.c (g_filename_to_uri, g_filename_from_uri): implement.
Modified: trunk/mono/eglib/ChangeLog
===================================================================
--- trunk/mono/eglib/ChangeLog 2006-09-18 09:45:24 UTC (rev 65567)
+++ trunk/mono/eglib/ChangeLog 2006-09-18 10:28:24 UTC (rev 65568)
@@ -1,3 +1,10 @@
+2006-09-18 Miguel de Icaza <[EMAIL PROTECTED]>
+
+ * test/string-util.c (test_filename_from_uri): tests for new
+ methods.
+
+ * src/gstr.c (g_filename_to_uri, g_filename_from_uri): implement.
+
2006-09-14 Atsushi Enomoto <[EMAIL PROTECTED]>
* src/gutf8.c, test/utf8.c : EOL fix.
Modified: trunk/mono/eglib/TODO
===================================================================
--- trunk/mono/eglib/TODO 2006-09-18 09:45:24 UTC (rev 65567)
+++ trunk/mono/eglib/TODO 2006-09-18 10:28:24 UTC (rev 65568)
@@ -19,9 +19,6 @@
3 g_thread_supported
3 g_thread_init
- * Path string manipulation and utilities.
- 2 g_filename_from_uri
-
* Information retrieval
1 g_get_charset
1 g_win32_getlocale
Modified: trunk/mono/eglib/src/glib.h
===================================================================
--- trunk/mono/eglib/src/glib.h 2006-09-18 09:45:24 UTC (rev 65567)
+++ trunk/mono/eglib/src/glib.h 2006-09-18 10:28:24 UTC (rev 65568)
@@ -142,8 +142,8 @@
} GError;
void g_error_free (GError *error);
-GError *g_error_new (gpointer domain, gint code, const char *format, ...);
-void g_set_error (GError **err, gpointer domain, gint code, const gchar
*format, ...);
+GError *g_error_new (gpointer domain, gint code, const char *format, ...);
+void g_set_error (GError **err, gpointer domain, gint code, const gchar
*format, ...);
/*
* Strings utility
@@ -163,8 +163,10 @@
gchar *g_strjoin (const gchar *separator, ...);
gchar *g_strchug (gchar *str);
gchar *g_strchomp (gchar *str);
-gchar *g_filename_to_uri (const gchar *filename, const gchar *hostname,
GError **error);
+gchar *g_filename_to_uri (const gchar *filename, const gchar
*hostname, GError **error);
+gchar *g_filename_from_uri (const gchar *uri, gchar **hostname, GError
**error);
+
gint g_printf (gchar const *format, ...);
gint g_fprintf (FILE *file, gchar const *format, ...);
gint g_sprintf (gchar *string, gchar const *format, ...);
Modified: trunk/mono/eglib/src/gstr.c
===================================================================
--- trunk/mono/eglib/src/gstr.c 2006-09-18 09:45:24 UTC (rev 65567)
+++ trunk/mono/eglib/src/gstr.c 2006-09-18 10:28:24 UTC (rev 65568)
@@ -386,7 +386,7 @@
g_return_val_if_fail (filename != NULL, NULL);
if (hostname != NULL)
- g_warning ("g_filename_to_uri: hostname and error not handled");
+ g_warning ("eglib: g_filename_to_uri: hostname not handled");
if (*filename != '/'){
if (error != NULL)
@@ -415,3 +415,63 @@
*rp = 0;
return ret;
}
+
+static int
+decode (char p)
+{
+ if (p >= '0' && p <= '9')
+ return p - '0';
+ if (p >= 'A' && p <= 'F')
+ return p - 'A';
+ if (p >= 'a' && p <= 'f')
+ return p - 'a';
+ g_assert_not_reached ();
+ return 0;
+}
+
+gchar *
+g_filename_from_uri (const gchar *uri, gchar **hostname, GError **error)
+{
+ const char *p;
+ char *r, *result;
+ int flen = 0;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ if (hostname != NULL)
+ g_warning ("eglib: g_filename_from_uri: hostname not handled");
+
+ if (strncmp (uri, "file:///", 8) != 0){
+ if (error != NULL)
+ *error = g_error_new (NULL, 2, "URI does not start with
the file: scheme");
+ return NULL;
+ }
+
+ for (p = uri + 8; *p; p++){
+ if (*p == '%'){
+ if (p [1] && p [2] && isxdigit (p [1]) && isxdigit (p
[2])){
+ p += 2;
+ } else {
+ if (error != NULL)
+ *error = g_error_new (NULL, 2, "URI
contains an invalid escape sequence");
+ return NULL;
+ }
+ }
+ flen++;
+ }
+ flen++;
+
+ result = g_malloc (flen + 1);
+ *result = '/';
+ result [flen] = 0;
+
+ for (p = uri + 8, r = result + 1; *p; p++){
+ if (*p == '%'){
+ *r++ = (decode (p [1]) << 4) | decode (p [2]);
+ p += 2;
+ } else
+ *r++ = *p;
+ flen++;
+ }
+ return result;
+}
Modified: trunk/mono/eglib/test/string-util.c
===================================================================
--- trunk/mono/eglib/test/string-util.c 2006-09-18 09:45:24 UTC (rev 65567)
+++ trunk/mono/eglib/test/string-util.c 2006-09-18 10:28:24 UTC (rev 65568)
@@ -201,6 +201,30 @@
return OK;
}
+#define fileit(so,j) do { s = g_filename_from_uri (so, NULL, NULL); if (strcmp
(s, j) != 0) return FAILED("Got %s expected %s", s, j); g_free (s); } while (0);
+
+#define ferrit(so) do { s = g_filename_from_uri (so, NULL, NULL); if (s !=
NULL) return FAILED ("got %s, expected NULL", s); } while (0);
+
+RESULT
+test_filename_from_uri ()
+{
+ char *s;
+
+ fileit ("file:///a", "/a");
+ fileit ("file:///%41", "/A");
+ fileit ("file:///home/miguel", "/home/miguel");
+ fileit ("file:///home/mig%20uel", "/home/mig uel");
+ ferrit ("/a");
+ ferrit ("a");
+ ferrit ("file://a");
+ ferrit ("file:a");
+ ferrit ("file:///%");
+ ferrit ("file:///%0");
+ ferrit ("file:///%jj");
+
+ return OK;
+}
+
static Test strutil_tests [] = {
{"g_strfreev", test_strfreev},
{"g_strconcat", test_concat},
@@ -211,6 +235,7 @@
{"g_strchomp", test_strchomp},
{"g_strstrip", test_strstrip},
{"g_filename_to_uri", test_filename_to_uri},
+ {"g_filename_from_uri", test_filename_from_uri},
{NULL, NULL}
};
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches