]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/uri.cpp
applied patch 1683441
[wxWidgets.git] / src / common / uri.cpp
index ccc0149a4b33e20eb297aaaff2c6401a8667eb9b..022b66b590a347e99e114a1c3993789beeb1b66d 100644 (file)
@@ -109,26 +109,29 @@ const wxChar* wxURI::Create(const wxString& uri)
 // Unescape unencodes all 3 character URL escape sequences in a wxString
 // ---------------------------------------------------------------------------
 
 // Unescape unencodes all 3 character URL escape sequences in a wxString
 // ---------------------------------------------------------------------------
 
-wxChar wxURI::TranslateEscape(const wxChar* s)
+wxUniChar wxURI::TranslateEscape(const wxString::const_iterator& s)
 {
 {
-    wxASSERT_MSG( IsHex(s[0]) && IsHex(s[1]), wxT("Invalid escape sequence!"));
+    wxChar c1(*s);
+    wxChar c2(*(s + 1));
 
 
-    return wx_truncate_cast(wxChar, (CharToHex(s[0]) << 4 ) | CharToHex(s[1]));
+    wxASSERT_MSG( IsHex(c1) && IsHex(c2), wxT("Invalid escape sequence!"));
+
+    return wx_truncate_cast(wxChar, (CharToHex(c1) << 4 ) | CharToHex(c2));
 }
 
 wxString wxURI::Unescape(const wxString& uri)
 {
     wxString new_uri;
 
 }
 
 wxString wxURI::Unescape(const wxString& uri)
 {
     wxString new_uri;
 
-    for(size_t i = 0; i < uri.length(); ++i)
+    for (wxString::const_iterator i = uri.begin(); i != uri.end(); ++i)
     {
     {
-        if (uri[i] == wxT('%'))
+        if ( *i == wxT('%') )
         {
         {
-            new_uri += wxURI::TranslateEscape( &(uri.c_str()[i+1]) );
+            new_uri += wxURI::TranslateEscape(i + 1);
             i += 2;
         }
         else
             i += 2;
         }
         else
-            new_uri += uri[i];
+            new_uri += *i;
     }
 
     return new_uri;
     }
 
     return new_uri;
@@ -870,18 +873,18 @@ void wxURI::Resolve(const wxURI& base, int flags)
         if (m_path[0u] != wxT('/'))
         {
             //Merge paths
         if (m_path[0u] != wxT('/'))
         {
             //Merge paths
-            const wxChar* op = m_path.c_str();
-            const wxChar* bp = base.m_path.c_str() + base.m_path.Length();
+            wxString::const_iterator op = m_path.begin();
+            wxString::const_iterator bp = base.m_path.begin() + base.m_path.length();
 
             //not a ending directory?  move up
             if (base.m_path[0] && *(bp-1) != wxT('/'))
 
             //not a ending directory?  move up
             if (base.m_path[0] && *(bp-1) != wxT('/'))
-                UpTree(base.m_path, bp);
+                UpTree(base.m_path.begin(), bp);
 
             //normalize directories
             while(*op == wxT('.') && *(op+1) == wxT('.') &&
                        (*(op+2) == '\0' || *(op+2) == wxT('/')) )
             {
 
             //normalize directories
             while(*op == wxT('.') && *(op+1) == wxT('.') &&
                        (*(op+2) == '\0' || *(op+2) == wxT('/')) )
             {
-                UpTree(base.m_path, bp);
+                UpTree(base.m_path.begin(), bp);
 
                 if (*(op+2) == '\0')
                     op += 2;
 
                 if (*(op+2) == '\0')
                     op += 2;
@@ -889,8 +892,8 @@ void wxURI::Resolve(const wxURI& base, int flags)
                     op += 3;
             }
 
                     op += 3;
             }
 
-            m_path = base.m_path.substr(0, bp - base.m_path.c_str()) +
-                    m_path.substr((op - m_path.c_str()), m_path.Length());
+            m_path = base.m_path.substr(0, bp - base.m_path.begin()) +
+                     m_path.substr((op - m_path.begin()), m_path.length());
         }
     }
 
         }
     }
 
@@ -904,7 +907,31 @@ void wxURI::Resolve(const wxURI& base, int flags)
 // ---------------------------------------------------------------------------
 
 //static
 // ---------------------------------------------------------------------------
 
 //static
-void wxURI::UpTree(const wxChar* uristart, const wxChar*& uri)
+void wxURI::UpTree(wxString::const_iterator uristart,
+                   wxString::const_iterator& uri)
+{
+    if (uri != uristart && *(uri-1) == wxT('/'))
+    {
+        uri -= 2;
+    }
+
+    for(;uri != uristart; --uri)
+    {
+        if (*uri == wxT('/'))
+        {
+            ++uri;
+            break;
+        }
+    }
+
+    //!!!TODO:HACK!!!//
+    if (uri == uristart && *uri == wxT('/'))
+        ++uri;
+    //!!!//
+}
+
+// FIXME-UTF8: fix Normalize() to use iterators instead of having this method!
+/*static*/ void wxURI::UpTree(const wxChar* uristart, const wxChar*& uri)
 {
     if (uri != uristart && *(uri-1) == wxT('/'))
     {
 {
     if (uri != uristart && *(uri-1) == wxT('/'))
     {
@@ -925,6 +952,7 @@ void wxURI::UpTree(const wxChar* uristart, const wxChar*& uri)
         ++uri;
     //!!!//
 }
         ++uri;
     //!!!//
 }
+// end of FIXME-UTF8
 
 // ---------------------------------------------------------------------------
 // Normalize
 
 // ---------------------------------------------------------------------------
 // Normalize