summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2012-06-10 09:24:33 +0000
committerManolo Gouy <Manolo>2012-06-10 09:24:33 +0000
commit3c87a80279a1d1d1f0cf37e1d925d37de543875f (patch)
treedd5fd817e043271683f0dabd222fb254a25d05a5 /src
parent145b44110b119a3cc4707b751ea375f9fbdbdd98 (diff)
Added function fl_decode_uri(char*) to support the drag-and-drop of files to FLTK widgets
on the X11 platform (see STR#2849). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9580 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/fl_open_uri.cxx21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/fl_open_uri.cxx b/src/fl_open_uri.cxx
index 00fa018bd..9a0cedd06 100644
--- a/src/fl_open_uri.cxx
+++ b/src/fl_open_uri.cxx
@@ -236,6 +236,27 @@ fl_open_uri(const char *uri, char *msg, int msglen) {
#endif // WIN32
}
+/** Decodes a URL-encoded string.
+
+ In a Uniform Resource Identifier (URI), all non-ASCII bytes and several others (e.g., '<', '%', ' ')
+ are URL-encoded using 3 bytes by "%XY" where XY is the hexadecimal value of the byte. This function
+ decodes the URI restoring its original UTF-8 encoded content. Decoding is done in-place.
+ */
+void fl_decode_uri(char *uri)
+{
+ char *last = uri + strlen(uri);
+ while (uri < last-2) {
+ if (*uri == '%') {
+ int h;
+ if ( sscanf(uri+1, "%2X", &h) != 1 ) break;
+ *uri = h;
+ memmove(uri+1, uri+3, last - (uri+2));
+ last -= 2;
+ }
+ uri++;
+ }
+}
+
/** @} */
#if !defined(WIN32) && !defined(__APPLE__)