#pragma hdrstop
#endif
+#ifndef WX_PRECOMP
+ #include "wx/crt.h"
+#endif
+
#include "wx/uri.h"
// ---------------------------------------------------------------------------
if (m_fields)
Clear();
- return Parse(uri);
+ // FIXME-UTF8: rewrite ParseXXX() methods using iterators
+ // NB: using wxWxCharBuffer instead of just c_str() avoids keeping
+ // converted string in memory for longer than needed
+ return Parse(wxWxCharBuffer(uri.c_str()));
}
// ---------------------------------------------------------------------------
// 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;
// URI-reference = URI / relative
// ---------------------------------------------------------------------------
-const wxChar* wxURI::Parse(const wxChar* uri)
+const wxChar* wxURI::Parse(const wxChar *uri)
{
uri = ParseScheme(uri);
uri = ParseAuthority(uri);
// Individual parsers for each URI component
// ---------------------------------------------------------------------------
-const wxChar* wxURI::ParseScheme(const wxChar* uri)
+const wxChar* wxURI::ParseScheme(const wxChar *uri)
{
wxASSERT(uri != NULL);
// 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 (bNormalize)
{
wxStringBufferLength theBuffer(m_path, m_path.length() + 1);
-#if wxUSE_STL
+#if wxUSE_STL || wxUSE_UNICODE_UTF8
+ // FIXME-UTF8: have some wxReadWriteStringBuffer instead?
wxTmemcpy(theBuffer, m_path.c_str(), m_path.length()+1);
#endif
Normalize(theBuffer, true);
if (bNormalize)
{
wxStringBufferLength theBuffer(m_path, m_path.length() + 1);
-#if wxUSE_STL
+#if wxUSE_STL || wxUSE_UNICODE_UTF8
+ // FIXME-UTF8: have some wxReadWriteStringBuffer instead?
wxTmemcpy(theBuffer, m_path.c_str(), m_path.length()+1);
#endif
Normalize(theBuffer);
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 = (wxString)base.m_path.substr(0, bp - base.m_path.c_str()) +
- (wxString)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