]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/url.cpp
basic support for encodings for wxMSW::wxFont
[wxWidgets.git] / src / common / url.cpp
index db4517e3d97f3b2a901af5da2e477eea03982c6a..1e142f1ef1d6215b619e48f7561e3b1a43012c63 100644 (file)
@@ -256,6 +256,8 @@ wxInputStream *wxURL::GetInputStream(void)
   }
 
 #if wxUSE_SOCKETS
+    wxIPV4address addr;
+
   // m_protoinfo is NULL when we use a proxy
   if (!m_useProxy && m_protoinfo->m_needhost) {
     if (!addr.Hostname(m_hostname)) {
@@ -263,7 +265,6 @@ wxInputStream *wxURL::GetInputStream(void)
       return NULL;
     }
 
-    wxIPV4address addr;
     addr.Service(m_servname);
 
     if (!m_protocol->Connect(addr, TRUE)) // Watcom needs the 2nd arg for some reason
@@ -373,14 +374,41 @@ wxString wxURL::ConvertToValidURI(const wxString& uri)
     if (c == _T(' '))
       out_str += _T('+');
     else {
-      if (!isalpha(c) && c != _T('.') && c != _T('+') && c != _T('/')) { 
+      if (!isalpha(c) && c != _T('.') && c != _T('+') && c != _T('/')) {
         hexa_code.Printf(_T("%%%02X"), c);
         out_str += hexa_code;
       } else
         out_str += c;
     }
   }
-  
+
   return out_str;
 }
 
+wxString wxURL::ConvertFromURI(const wxString& uri)
+{
+  wxString new_uri;
+
+  size_t i = 0;
+  while (i<uri.Len()) {
+    int code;
+    if (uri[i] == _T('%')) {
+      i++;
+      if (uri[i] >= _T('A') && uri[i] <= _T('F'))
+        code = (uri[i] - _T('A') + 10) * 16;
+      else
+        code = (uri[i] - _T('0')) * 16;
+      i++;
+      if (uri[i] >= _T('A') && uri[i] <= _T('F'))
+        code += (uri[i] - _T('A')) + 10;
+      else
+        code += (uri[i] - _T('0'));
+      i++;
+      new_uri += (wxChar)code;
+      continue;
+    }
+    new_uri += uri[i];
+    i++;
+  }
+  return new_uri;
+}