// headers
// ---------------------------------------------------------------------------
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
- #pragma implementation "uri.h"
-#endif
-
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
// definitions
// ---------------------------------------------------------------------------
-IMPLEMENT_CLASS(wxURI, wxObject);
+IMPLEMENT_CLASS(wxURI, wxObject)
// ===========================================================================
// implementation
// 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 (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;
- 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
- new_uri += uri[i];
+ new_uri += *i;
}
return new_uri;
// authority = [ userinfo "@" ] host [ ":" port ]
if (*uri == wxT('/') && *(uri+1) == wxT('/'))
{
+ //skip past the two slashes
uri += 2;
+ // ############# DEVIATION FROM RFC #########################
+ // Don't parse the server component for file URIs
+ if(m_scheme != wxT("file"))
+ {
+ //normal way
uri = ParseUserInfo(uri);
uri = ParseServer(uri);
return ParsePort(uri);
+ }
}
return uri;
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('/'))
- 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('/')) )
{
- UpTree(base.m_path, bp);
+ UpTree(base.m_path.begin(), bp);
if (*(op+2) == '\0')
op += 2;
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());
}
}
// ---------------------------------------------------------------------------
//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('/'))
{
++uri;
//!!!//
}
+// end of FIXME-UTF8
// ---------------------------------------------------------------------------
// Normalize