X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d8746da256e827b700aaf173669bd5bbc97025c7..ce457f1245754243f17b4efde9ec773a8b3c3067:/src/common/uri.cpp diff --git a/src/common/uri.cpp b/src/common/uri.cpp index c195d13729..022b66b590 100644 --- a/src/common/uri.cpp +++ b/src/common/uri.cpp @@ -109,26 +109,29 @@ const wxChar* wxURI::Create(const wxString& uri) // 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; - 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; @@ -432,11 +435,18 @@ const wxChar* wxURI::ParseAuthority(const wxChar* 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; @@ -863,18 +873,18 @@ void wxURI::Resolve(const wxURI& base, int flags) 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; @@ -882,8 +892,8 @@ void wxURI::Resolve(const wxURI& base, int flags) 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()); } } @@ -897,7 +907,31 @@ void wxURI::Resolve(const wxURI& base, int flags) // --------------------------------------------------------------------------- //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('/')) { @@ -918,6 +952,7 @@ void wxURI::UpTree(const wxChar* uristart, const wxChar*& uri) ++uri; //!!!// } +// end of FIXME-UTF8 // --------------------------------------------------------------------------- // Normalize