const char* wxURI::ParseServer(const char* uri) { const char * const start = uri; // host = IP-literal / IPv4address / reg-name // IP-literal = "[" ( IPv6address / IPvFuture ) "]" if (*uri == '[') { ++uri; if (ParseIPv6address(uri) && *uri == ']') { m_hostType = wxURI_IPV6ADDRESS; m_server.assign(start + 1, uri - start - 1); ++uri; } else { uri = start + 1; // skip the leading '[' again if (ParseIPvFuture(uri) && *uri == ']') { m_hostType = wxURI_IPVFUTURE; m_server.assign(start + 1, uri - start - 1); ++uri; } else // unrecognized IP literal { uri = start; } } } else // IPv4 or a reg-name { if (ParseIPv4address(uri)) { m_hostType = wxURI_IPV4ADDRESS; m_server.assign(start, uri - start); } else { uri = start; } } if ( m_hostType == wxURI_REGNAME ) { uri = start; // reg-name = *( unreserved / pct-encoded / sub-delims ) while ( *uri && *uri != '/' && *uri != ':' && *uri != '#' && *uri != '?' ) { if ( IsUnreserved(*uri) || IsSubDelim(*uri) ) m_server += *uri++; else AppendNextEscaped(m_server, uri); } } m_fields |= wxURI_SERVER; return uri; }
const wxChar* wxURI::ParseServer(const wxChar* uri) { wxASSERT(uri != NULL); //copy of the uri - used for figuring out //length of each component const wxChar* uricopy = uri; // host = IP-literal / IPv4address / reg-name // IP-literal = "[" ( IPv6address / IPvFuture ) "]" if (*uri == wxT('[')) { ++uri; //some compilers don't support *&ing a ++* if (ParseIPv6address(uri) && *uri == wxT(']')) { ++uri; m_hostType = wxURI_IPV6ADDRESS; wxStringBufferLength theBuffer(m_server, uri - uricopy); wxTmemcpy(theBuffer, uricopy, uri-uricopy); theBuffer.SetLength(uri-uricopy); } else { uri = uricopy; ++uri; //some compilers don't support *&ing a ++* if (ParseIPvFuture(uri) && *uri == wxT(']')) { ++uri; m_hostType = wxURI_IPVFUTURE; wxStringBufferLength theBuffer(m_server, uri - uricopy); wxTmemcpy(theBuffer, uricopy, uri-uricopy); theBuffer.SetLength(uri-uricopy); } else uri = uricopy; } } else { if (ParseIPv4address(uri)) { m_hostType = wxURI_IPV4ADDRESS; wxStringBufferLength theBuffer(m_server, uri - uricopy); wxTmemcpy(theBuffer, uricopy, uri-uricopy); theBuffer.SetLength(uri-uricopy); } else uri = uricopy; } if(m_hostType == wxURI_REGNAME) { uri = uricopy; // reg-name = *( unreserved / pct-encoded / sub-delims ) while(*uri && *uri != wxT('/') && *uri != wxT(':') && *uri != wxT('#') && *uri != wxT('?')) { if(IsUnreserved(*uri) || IsSubDelim(*uri)) m_server += *uri++; else if (IsEscape(uri)) { m_server += *uri++; m_server += *uri++; m_server += *uri++; } else Escape(m_server, *uri++); } } //mark the server as valid m_fields |= wxURI_SERVER; return uri; }