]>
git.saurik.com Git - wxWidgets.git/blob - src/common/uri.cpp
9b2f5503d33fcc3e242844611d611d2e5ae03162
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Implementation of a uri parser
7 // Copyright: (c) 2004 Ryan Norton
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
32 // ---------------------------------------------------------------------------
34 // ---------------------------------------------------------------------------
36 IMPLEMENT_CLASS(wxURI
, wxObject
)
38 // ===========================================================================
40 // ===========================================================================
42 // ---------------------------------------------------------------------------
44 // ---------------------------------------------------------------------------
46 // ---------------------------------------------------------------------------
50 // ---------------------------------------------------------------------------
52 // ---------------------------------------------------------------------------
54 // ---------------------------------------------------------------------------
56 wxURI::wxURI() : m_hostType(wxURI_REGNAME
), m_fields(0)
60 wxURI::wxURI(const wxString
& uri
) : m_hostType(wxURI_REGNAME
), m_fields(0)
65 wxURI::wxURI(const wxURI
& uri
) : wxObject(), m_hostType(wxURI_REGNAME
), m_fields(0)
70 // ---------------------------------------------------------------------------
71 // Destructor and cleanup
72 // ---------------------------------------------------------------------------
81 m_scheme
= m_userinfo
= m_server
= m_port
= m_path
=
82 m_query
= m_fragment
= wxEmptyString
;
84 m_hostType
= wxURI_REGNAME
;
89 // ---------------------------------------------------------------------------
92 // This creates the URI - all we do here is call the main parsing method
93 // ---------------------------------------------------------------------------
95 const wxChar
* wxURI::Create(const wxString
& uri
)
100 // FIXME-UTF8: rewrite ParseXXX() methods using iterators
101 // NB: using wxWxCharBuffer instead of just c_str() avoids keeping
102 // converted string in memory for longer than needed
103 return Parse(wxWxCharBuffer(uri
.c_str()));
106 // ---------------------------------------------------------------------------
109 // TranslateEscape unencodes a 3 character URL escape sequence
111 // Escape encodes an invalid URI character into a 3 character sequence
113 // IsEscape determines if the input string contains an escape sequence,
114 // if it does, then it moves the input string past the escape sequence
116 // Unescape unencodes all 3 character URL escape sequences in a wxString
117 // ---------------------------------------------------------------------------
119 wxUniChar
wxURI::TranslateEscape(const wxString::const_iterator
& s
)
124 wxASSERT_MSG( IsHex(c1
) && IsHex(c2
), wxT("Invalid escape sequence!"));
126 return wx_truncate_cast(wxChar
, (CharToHex(c1
) << 4 ) | CharToHex(c2
));
129 wxString
wxURI::Unescape(const wxString
& uri
)
133 for (wxString::const_iterator i
= uri
.begin(); i
!= uri
.end(); ++i
)
135 if ( *i
== wxT('%') )
137 new_uri
+= wxURI::TranslateEscape(i
+ 1);
147 void wxURI::Escape(wxString
& s
, const wxChar
& c
)
149 const wxChar
* hdig
= wxT("0123456789abcdef");
151 s
+= hdig
[(c
>> 4) & 15];
155 bool wxURI::IsEscape(const wxChar
*& uri
)
157 // pct-encoded = "%" HEXDIG HEXDIG
158 if(*uri
== wxT('%') && IsHex(*(uri
+1)) && IsHex(*(uri
+2)))
164 // ---------------------------------------------------------------------------
168 // Gets the username and password via the old URL method.
169 // ---------------------------------------------------------------------------
170 wxString
wxURI::GetUser() const
172 size_t dwPasswordPos
= m_userinfo
.find(':');
174 if (dwPasswordPos
== wxString::npos
)
177 return m_userinfo(0, dwPasswordPos
);
180 wxString
wxURI::GetPassword() const
182 size_t dwPasswordPos
= m_userinfo
.find(':');
184 if (dwPasswordPos
== wxString::npos
)
187 return m_userinfo(dwPasswordPos
+1, m_userinfo
.length() + 1);
190 // ---------------------------------------------------------------------------
193 // BuildURI() builds the entire URI into a useable
194 // representation, including proper identification characters such as slashes
196 // BuildUnescapedURI() does the same thing as BuildURI(), only it unescapes
197 // the components that accept escape sequences
198 // ---------------------------------------------------------------------------
200 wxString
wxURI::BuildURI() const
205 ret
= ret
+ m_scheme
+ wxT(":");
212 ret
= ret
+ m_userinfo
+ wxT("@");
217 ret
= ret
+ wxT(":") + m_port
;
223 ret
= ret
+ wxT("?") + m_query
;
226 ret
= ret
+ wxT("#") + m_fragment
;
231 wxString
wxURI::BuildUnescapedURI() const
236 ret
= ret
+ m_scheme
+ wxT(":");
243 ret
= ret
+ wxURI::Unescape(m_userinfo
) + wxT("@");
245 if (m_hostType
== wxURI_REGNAME
)
246 ret
+= wxURI::Unescape(m_server
);
251 ret
= ret
+ wxT(":") + m_port
;
254 ret
+= wxURI::Unescape(m_path
);
257 ret
= ret
+ wxT("?") + wxURI::Unescape(m_query
);
260 ret
= ret
+ wxT("#") + wxURI::Unescape(m_fragment
);
265 // ---------------------------------------------------------------------------
267 // ---------------------------------------------------------------------------
269 wxURI
& wxURI::Assign(const wxURI
& uri
)
272 m_fields
= uri
.m_fields
;
274 //ref over components
275 m_scheme
= uri
.m_scheme
;
276 m_userinfo
= uri
.m_userinfo
;
277 m_server
= uri
.m_server
;
278 m_hostType
= uri
.m_hostType
;
281 m_query
= uri
.m_query
;
282 m_fragment
= uri
.m_fragment
;
287 wxURI
& wxURI::operator = (const wxURI
& uri
)
292 wxURI
& wxURI::operator = (const wxString
& string
)
298 // ---------------------------------------------------------------------------
300 // ---------------------------------------------------------------------------
302 bool wxURI::operator == (const wxURI
& uri
) const
306 if(m_scheme
!= uri
.m_scheme
)
309 else if (uri
.HasScheme())
317 if (m_userinfo
!= uri
.m_userinfo
)
320 else if (uri
.HasUserInfo())
323 if (m_server
!= uri
.m_server
||
324 m_hostType
!= uri
.m_hostType
)
329 if(m_port
!= uri
.m_port
)
332 else if (uri
.HasPort())
335 else if (uri
.HasServer())
341 if(m_path
!= uri
.m_path
)
344 else if (uri
.HasPath())
349 if (m_query
!= uri
.m_query
)
352 else if (uri
.HasQuery())
357 if (m_fragment
!= uri
.m_fragment
)
360 else if (uri
.HasFragment())
366 // ---------------------------------------------------------------------------
369 // if there is no authority or scheme, it is a reference
370 // ---------------------------------------------------------------------------
372 bool wxURI::IsReference() const
373 { return !HasScheme() || !HasServer(); }
375 // ---------------------------------------------------------------------------
378 // Master URI parsing method. Just calls the individual parsing methods
380 // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
381 // URI-reference = URI / relative
382 // ---------------------------------------------------------------------------
384 const wxChar
* wxURI::Parse(const wxChar
*uri
)
386 uri
= ParseScheme(uri
);
387 uri
= ParseAuthority(uri
);
388 uri
= ParsePath(uri
);
389 uri
= ParseQuery(uri
);
390 return ParseFragment(uri
);
393 // ---------------------------------------------------------------------------
396 // Individual parsers for each URI component
397 // ---------------------------------------------------------------------------
399 const wxChar
* wxURI::ParseScheme(const wxChar
*uri
)
401 wxASSERT(uri
!= NULL
);
403 //copy of the uri - used for figuring out
404 //length of each component
405 const wxChar
* uricopy
= uri
;
407 //Does the uri have a scheme (first character alpha)?
412 //scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
413 while (IsAlpha(*uri
) || IsDigit(*uri
) ||
422 if (*uri
== wxT(':'))
424 //mark the scheme as valid
425 m_fields
|= wxURI_SCHEME
;
427 //move reference point up to input buffer
431 //relative uri with relative path reference
432 m_scheme
= wxEmptyString
;
435 //relative uri with _possible_ relative path reference
440 const wxChar
* wxURI::ParseAuthority(const wxChar
* uri
)
442 // authority = [ userinfo "@" ] host [ ":" port ]
443 if (*uri
== wxT('/') && *(uri
+1) == wxT('/'))
445 //skip past the two slashes
448 // ############# DEVIATION FROM RFC #########################
449 // Don't parse the server component for file URIs
450 if(m_scheme
!= wxT("file"))
453 uri
= ParseUserInfo(uri
);
454 uri
= ParseServer(uri
);
455 return ParsePort(uri
);
462 const wxChar
* wxURI::ParseUserInfo(const wxChar
* uri
)
464 wxASSERT(uri
!= NULL
);
466 //copy of the uri - used for figuring out
467 //length of each component
468 const wxChar
* uricopy
= uri
;
470 // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
471 while(*uri
&& *uri
!= wxT('@') && *uri
!= wxT('/') && *uri
!= wxT('#') && *uri
!= wxT('?'))
473 if(IsUnreserved(*uri
) ||
474 IsSubDelim(*uri
) || *uri
== wxT(':'))
475 m_userinfo
+= *uri
++;
476 else if (IsEscape(uri
))
478 m_userinfo
+= *uri
++;
479 m_userinfo
+= *uri
++;
480 m_userinfo
+= *uri
++;
483 Escape(m_userinfo
, *uri
++);
489 m_fields
|= wxURI_USERINFO
;
494 m_userinfo
= wxEmptyString
;
499 const wxChar
* wxURI::ParseServer(const wxChar
* uri
)
501 wxASSERT(uri
!= NULL
);
503 //copy of the uri - used for figuring out
504 //length of each component
505 const wxChar
* uricopy
= uri
;
507 // host = IP-literal / IPv4address / reg-name
508 // IP-literal = "[" ( IPv6address / IPvFuture ) "]"
509 if (*uri
== wxT('['))
511 ++uri
; //some compilers don't support *&ing a ++*
512 if (ParseIPv6address(uri
) && *uri
== wxT(']'))
515 m_hostType
= wxURI_IPV6ADDRESS
;
517 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
518 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
519 theBuffer
.SetLength(uri
-uricopy
);
525 ++uri
; //some compilers don't support *&ing a ++*
526 if (ParseIPvFuture(uri
) && *uri
== wxT(']'))
529 m_hostType
= wxURI_IPVFUTURE
;
531 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
532 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
533 theBuffer
.SetLength(uri
-uricopy
);
541 if (ParseIPv4address(uri
))
543 m_hostType
= wxURI_IPV4ADDRESS
;
545 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
546 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
547 theBuffer
.SetLength(uri
-uricopy
);
553 if(m_hostType
== wxURI_REGNAME
)
556 // reg-name = *( unreserved / pct-encoded / sub-delims )
557 while(*uri
&& *uri
!= wxT('/') && *uri
!= wxT(':') && *uri
!= wxT('#') && *uri
!= wxT('?'))
559 if(IsUnreserved(*uri
) || IsSubDelim(*uri
))
561 else if (IsEscape(uri
))
568 Escape(m_server
, *uri
++);
572 //mark the server as valid
573 m_fields
|= wxURI_SERVER
;
579 const wxChar
* wxURI::ParsePort(const wxChar
* uri
)
581 wxASSERT(uri
!= NULL
);
592 //mark the port as valid
593 m_fields
|= wxURI_PORT
;
599 const wxChar
* wxURI::ParsePath(const wxChar
* uri
, bool bReference
, bool bNormalize
)
601 wxASSERT(uri
!= NULL
);
603 //copy of the uri - used for figuring out
604 //length of each component
605 const wxChar
* uricopy
= uri
;
607 /// hier-part = "//" authority path-abempty
612 /// relative-part = "//" authority path-abempty
617 /// path-abempty = *( "/" segment )
618 /// path-absolute = "/" [ segment-nz *( "/" segment ) ]
619 /// path-noscheme = segment-nz-nc *( "/" segment )
620 /// path-rootless = segment-nz *( "/" segment )
621 /// path-empty = 0<pchar>
624 /// segment-nz = 1*pchar
625 /// segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
626 /// ; non-zero-length segment without any colon ":"
628 /// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
629 if (*uri
== wxT('/'))
633 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
635 if( IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
636 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
638 else if (IsEscape(uri
))
645 Escape(m_path
, *uri
++);
650 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
651 Normalize(theBuffer
, true);
652 theBuffer
.SetLength(wxStrlen(theBuffer
));
654 //mark the path as valid
655 m_fields
|= wxURI_PATH
;
657 else if(*uri
) //Relative path
662 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
664 if(IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
665 *uri
== wxT('@') || *uri
== wxT('/'))
667 else if (IsEscape(uri
))
674 Escape(m_path
, *uri
++);
679 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
681 if(IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
682 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
684 else if (IsEscape(uri
))
691 Escape(m_path
, *uri
++);
699 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
700 #if wxUSE_STL || wxUSE_UNICODE_UTF8
701 // FIXME-UTF8: have some wxReadWriteStringBuffer instead?
702 wxTmemcpy(theBuffer
, m_path
.c_str(), m_path
.length()+1);
704 Normalize(theBuffer
);
705 theBuffer
.SetLength(wxStrlen(theBuffer
));
708 //mark the path as valid
709 m_fields
|= wxURI_PATH
;
717 const wxChar
* wxURI::ParseQuery(const wxChar
* uri
)
719 wxASSERT(uri
!= NULL
);
721 // query = *( pchar / "/" / "?" )
722 if (*uri
== wxT('?'))
725 while(*uri
&& *uri
!= wxT('#'))
727 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
728 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
730 else if (IsEscape(uri
))
737 Escape(m_query
, *uri
++);
740 //mark the server as valid
741 m_fields
|= wxURI_QUERY
;
748 const wxChar
* wxURI::ParseFragment(const wxChar
* uri
)
750 wxASSERT(uri
!= NULL
);
752 // fragment = *( pchar / "/" / "?" )
753 if (*uri
== wxT('#'))
758 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
759 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
760 m_fragment
+= *uri
++;
761 else if (IsEscape(uri
))
763 m_fragment
+= *uri
++;
764 m_fragment
+= *uri
++;
765 m_fragment
+= *uri
++;
768 Escape(m_fragment
, *uri
++);
771 //mark the server as valid
772 m_fields
|= wxURI_FRAGMENT
;
778 // ---------------------------------------------------------------------------
781 // Builds missing components of this uri from a base uri
783 // A version of the algorithm outlined in the RFC is used here
784 // (it is shown in comments)
786 // Note that an empty URI inherits all components
787 // ---------------------------------------------------------------------------
789 void wxURI::Resolve(const wxURI
& base
, int flags
)
791 wxASSERT_MSG(!base
.IsReference(),
792 wxT("wxURI to inherit from must not be a reference!"));
794 // If we arn't being strict, enable the older (pre-RFC2396)
795 // loophole that allows this uri to inherit other
796 // properties from the base uri - even if the scheme
798 if ( !(flags
& wxURI_STRICT
) &&
799 HasScheme() && base
.HasScheme() &&
800 m_scheme
== base
.m_scheme
)
802 m_fields
-= wxURI_SCHEME
;
806 // Do nothing if this is an absolute wxURI
807 // if defined(R.scheme) then
808 // T.scheme = R.scheme;
809 // T.authority = R.authority;
810 // T.path = remove_dot_segments(R.path);
811 // T.query = R.query;
817 //No scheme - inherit
818 m_scheme
= base
.m_scheme
;
819 m_fields
|= wxURI_SCHEME
;
821 // All we need to do for relative URIs with an
822 // authority component is just inherit the scheme
823 // if defined(R.authority) then
824 // T.authority = R.authority;
825 // T.path = remove_dot_segments(R.path);
826 // T.query = R.query;
832 //No authority - inherit
833 if (base
.HasUserInfo())
835 m_userinfo
= base
.m_userinfo
;
836 m_fields
|= wxURI_USERINFO
;
839 m_server
= base
.m_server
;
840 m_hostType
= base
.m_hostType
;
841 m_fields
|= wxURI_SERVER
;
845 m_port
= base
.m_port
;
846 m_fields
|= wxURI_PORT
;
850 // Simple path inheritance from base
853 // T.path = Base.path;
854 m_path
= base
.m_path
;
855 m_fields
|= wxURI_PATH
;
858 // if defined(R.query) then
859 // T.query = R.query;
861 // T.query = Base.query;
865 m_query
= base
.m_query
;
866 m_fields
|= wxURI_QUERY
;
871 // if (R.path starts-with "/") then
872 // T.path = remove_dot_segments(R.path);
874 // T.path = merge(Base.path, R.path);
875 // T.path = remove_dot_segments(T.path);
877 // T.query = R.query;
878 if (m_path
[0u] != wxT('/'))
881 wxString::const_iterator op
= m_path
.begin();
882 wxString::const_iterator bp
= base
.m_path
.begin() + base
.m_path
.length();
884 //not a ending directory? move up
885 if (base
.m_path
[0] && *(bp
-1) != wxT('/'))
886 UpTree(base
.m_path
.begin(), bp
);
888 //normalize directories
889 while(*op
== wxT('.') && *(op
+1) == wxT('.') &&
890 (*(op
+2) == '\0' || *(op
+2) == wxT('/')) )
892 UpTree(base
.m_path
.begin(), bp
);
900 m_path
= base
.m_path
.substr(0, bp
- base
.m_path
.begin()) +
901 m_path
.substr((op
- m_path
.begin()), m_path
.length());
905 //T.fragment = R.fragment;
908 // ---------------------------------------------------------------------------
911 // Moves a URI path up a directory
912 // ---------------------------------------------------------------------------
915 void wxURI::UpTree(wxString::const_iterator uristart
,
916 wxString::const_iterator
& uri
)
918 if (uri
!= uristart
&& *(uri
-1) == wxT('/'))
923 for(;uri
!= uristart
; --uri
)
925 if (*uri
== wxT('/'))
933 if (uri
== uristart
&& *uri
== wxT('/'))
938 // FIXME-UTF8: fix Normalize() to use iterators instead of having this method!
939 /*static*/ void wxURI::UpTree(const wxChar
* uristart
, const wxChar
*& uri
)
941 if (uri
!= uristart
&& *(uri
-1) == wxT('/'))
946 for(;uri
!= uristart
; --uri
)
948 if (*uri
== wxT('/'))
956 if (uri
== uristart
&& *uri
== wxT('/'))
962 // ---------------------------------------------------------------------------
965 // Normalizes directories in-place
967 // I.E. ./ and . are ignored
969 // ../ and .. are removed if a directory is before it, along
970 // with that directory (leading .. and ../ are kept)
971 // ---------------------------------------------------------------------------
974 void wxURI::Normalize(wxChar
* s
, bool bIgnoreLeads
)
984 if (*cp
== wxT('.') && (*(cp
+1) == wxT('/') || *(cp
+1) == '\0')
985 && (bp
== cp
|| *(cp
-1) == wxT('/')))
993 else if (*cp
== wxT('.') && *(cp
+1) == wxT('.') &&
994 (*(cp
+2) == wxT('/') || *(cp
+2) == '\0')
995 && (bp
== cp
|| *(cp
-1) == wxT('/')))
997 //.. _or_ ../ - go up the tree
1000 UpTree((const wxChar
*)bp
, (const wxChar
*&)s
);
1002 if (*(cp
+2) == '\0')
1007 else if (!bIgnoreLeads
)
1019 if (*(cp
+2) == '\0')
1032 // ---------------------------------------------------------------------------
1035 // Parses 1 to 4 hex values. Returns true if the first character of the input
1036 // string is a valid hex character. It is the caller's responsability to move
1037 // the input string back to its original position on failure.
1038 // ---------------------------------------------------------------------------
1040 bool wxURI::ParseH16(const wxChar
*& uri
)
1046 if(IsHex(*++uri
) && IsHex(*++uri
) && IsHex(*++uri
))
1052 // ---------------------------------------------------------------------------
1055 // Parses a certain version of an IP address and moves the input string past
1056 // it. Returns true if the input string contains the proper version of an ip
1057 // address. It is the caller's responsability to move the input string back
1058 // to its original position on failure.
1059 // ---------------------------------------------------------------------------
1061 bool wxURI::ParseIPv4address(const wxChar
*& uri
)
1063 //IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
1065 //dec-octet = DIGIT ; 0-9
1066 // / %x31-39 DIGIT ; 10-99
1067 // / "1" 2DIGIT ; 100-199
1068 // / "2" %x30-34 DIGIT ; 200-249
1069 // / "25" %x30-35 ; 250-255
1076 //each ip part must be between 0-255 (dupe of version in for loop)
1077 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
1078 //100 or less (note !)
1079 !( (*(uri
-2) < wxT('2')) ||
1081 (*(uri
-2) == wxT('2') &&
1082 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
1090 if(IsDigit(*uri
))++uri
;
1092 //compilers should unroll this loop
1093 for(; iIPv4
< 4; ++iIPv4
)
1095 if (*uri
!= wxT('.') || !IsDigit(*++uri
))
1098 //each ip part must be between 0-255
1099 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
1100 //100 or less (note !)
1101 !( (*(uri
-2) < wxT('2')) ||
1103 (*(uri
-2) == wxT('2') &&
1104 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
1111 if(IsDigit(*uri
))++uri
;
1117 bool wxURI::ParseIPv6address(const wxChar
*& uri
)
1119 // IPv6address = 6( h16 ":" ) ls32
1120 // / "::" 5( h16 ":" ) ls32
1121 // / [ h16 ] "::" 4( h16 ":" ) ls32
1122 // / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1123 // / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1124 // / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1125 // / [ *4( h16 ":" ) h16 ] "::" ls32
1126 // / [ *5( h16 ":" ) h16 ] "::" h16
1127 // / [ *6( h16 ":" ) h16 ] "::"
1129 size_t numPrefix
= 0,
1132 bool bEndHex
= false;
1134 for( ; numPrefix
< 6; ++numPrefix
)
1143 if(*uri
!= wxT(':'))
1149 if(!bEndHex
&& !ParseH16(uri
))
1156 if (*uri
== wxT(':'))
1158 if (*++uri
!= wxT(':'))
1168 if (*uri
!= wxT(':') || *(uri
+1) != wxT(':'))
1173 while (*--uri
!= wxT(':')) {}
1176 const wxChar
* uristart
= uri
;
1178 // ls32 = ( h16 ":" h16 ) / IPv4address
1179 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1184 if (ParseIPv4address(uri
))
1196 maxPostfix
= 4 - numPrefix
;
1200 bool bAllowAltEnding
= maxPostfix
== 0;
1202 for(; maxPostfix
!= 0; --maxPostfix
)
1204 if(!ParseH16(uri
) || *uri
!= wxT(':'))
1210 const wxChar
* uristart
= uri
;
1212 // ls32 = ( h16 ":" h16 ) / IPv4address
1213 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1218 if (ParseIPv4address(uri
))
1223 if (!bAllowAltEnding
)
1227 if(numPrefix
<= 5 && ParseH16(uri
))
1233 bool wxURI::ParseIPvFuture(const wxChar
*& uri
)
1235 // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1236 if (*++uri
!= wxT('v') || !IsHex(*++uri
))
1239 while (IsHex(*++uri
)) {}
1241 if (*uri
!= wxT('.') || !(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')))
1244 while(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')) {}
1250 // ---------------------------------------------------------------------------
1253 // Converts a character into a numeric hexidecimal value, or 0 if the
1254 // passed in character is not a valid hex character
1255 // ---------------------------------------------------------------------------
1258 wxChar
wxURI::CharToHex(const wxChar
& c
)
1260 if ((c
>= wxT('A')) && (c
<= wxT('Z'))) return wxChar(c
- wxT('A') + 0x0A);
1261 if ((c
>= wxT('a')) && (c
<= wxT('z'))) return wxChar(c
- wxT('a') + 0x0a);
1262 if ((c
>= wxT('0')) && (c
<= wxT('9'))) return wxChar(c
- wxT('0') + 0x00);
1267 // ---------------------------------------------------------------------------
1270 // Returns true if the passed in character meets the criteria of the method
1271 // ---------------------------------------------------------------------------
1273 //! unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1274 bool wxURI::IsUnreserved (const wxChar
& c
)
1275 { return IsAlpha(c
) || IsDigit(c
) ||
1279 c
== wxT('~') //tilde
1283 bool wxURI::IsReserved (const wxChar
& c
)
1285 return IsGenDelim(c
) || IsSubDelim(c
);
1288 //! gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
1289 bool wxURI::IsGenDelim (const wxChar
& c
)
1291 return c
== wxT(':') ||
1300 //! sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1301 //! / "*" / "+" / "," / ";" / "="
1302 bool wxURI::IsSubDelim (const wxChar
& c
)
1304 return c
== wxT('!') ||
1318 bool wxURI::IsHex(const wxChar
& c
)
1319 { return IsDigit(c
) || (c
>= wxT('a') && c
<= wxT('f')) || (c
>= wxT('A') && c
<= wxT('F')); }
1321 bool wxURI::IsAlpha(const wxChar
& c
)
1322 { return (c
>= wxT('a') && c
<= wxT('z')) || (c
>= wxT('A') && c
<= wxT('Z')); }
1324 bool wxURI::IsDigit(const wxChar
& c
)
1325 { return c
>= wxT('0') && c
<= wxT('9'); }