]>
git.saurik.com Git - wxWidgets.git/blob - src/common/uri.cpp
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 Normalize(theBuffer
);
701 theBuffer
.SetLength(wxStrlen(theBuffer
));
704 //mark the path as valid
705 m_fields
|= wxURI_PATH
;
713 const wxChar
* wxURI::ParseQuery(const wxChar
* uri
)
715 wxASSERT(uri
!= NULL
);
717 // query = *( pchar / "/" / "?" )
718 if (*uri
== wxT('?'))
721 while(*uri
&& *uri
!= wxT('#'))
723 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
724 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
726 else if (IsEscape(uri
))
733 Escape(m_query
, *uri
++);
736 //mark the server as valid
737 m_fields
|= wxURI_QUERY
;
744 const wxChar
* wxURI::ParseFragment(const wxChar
* uri
)
746 wxASSERT(uri
!= NULL
);
748 // fragment = *( pchar / "/" / "?" )
749 if (*uri
== wxT('#'))
754 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
755 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
756 m_fragment
+= *uri
++;
757 else if (IsEscape(uri
))
759 m_fragment
+= *uri
++;
760 m_fragment
+= *uri
++;
761 m_fragment
+= *uri
++;
764 Escape(m_fragment
, *uri
++);
767 //mark the server as valid
768 m_fields
|= wxURI_FRAGMENT
;
774 // ---------------------------------------------------------------------------
777 // Builds missing components of this uri from a base uri
779 // A version of the algorithm outlined in the RFC is used here
780 // (it is shown in comments)
782 // Note that an empty URI inherits all components
783 // ---------------------------------------------------------------------------
785 void wxURI::Resolve(const wxURI
& base
, int flags
)
787 wxASSERT_MSG(!base
.IsReference(),
788 wxT("wxURI to inherit from must not be a reference!"));
790 // If we arn't being strict, enable the older (pre-RFC2396)
791 // loophole that allows this uri to inherit other
792 // properties from the base uri - even if the scheme
794 if ( !(flags
& wxURI_STRICT
) &&
795 HasScheme() && base
.HasScheme() &&
796 m_scheme
== base
.m_scheme
)
798 m_fields
-= wxURI_SCHEME
;
802 // Do nothing if this is an absolute wxURI
803 // if defined(R.scheme) then
804 // T.scheme = R.scheme;
805 // T.authority = R.authority;
806 // T.path = remove_dot_segments(R.path);
807 // T.query = R.query;
813 //No scheme - inherit
814 m_scheme
= base
.m_scheme
;
815 m_fields
|= wxURI_SCHEME
;
817 // All we need to do for relative URIs with an
818 // authority component is just inherit the scheme
819 // if defined(R.authority) then
820 // T.authority = R.authority;
821 // T.path = remove_dot_segments(R.path);
822 // T.query = R.query;
828 //No authority - inherit
829 if (base
.HasUserInfo())
831 m_userinfo
= base
.m_userinfo
;
832 m_fields
|= wxURI_USERINFO
;
835 m_server
= base
.m_server
;
836 m_hostType
= base
.m_hostType
;
837 m_fields
|= wxURI_SERVER
;
841 m_port
= base
.m_port
;
842 m_fields
|= wxURI_PORT
;
846 // Simple path inheritance from base
849 // T.path = Base.path;
850 m_path
= base
.m_path
;
851 m_fields
|= wxURI_PATH
;
854 // if defined(R.query) then
855 // T.query = R.query;
857 // T.query = Base.query;
861 m_query
= base
.m_query
;
862 m_fields
|= wxURI_QUERY
;
867 // if (R.path starts-with "/") then
868 // T.path = remove_dot_segments(R.path);
870 // T.path = merge(Base.path, R.path);
871 // T.path = remove_dot_segments(T.path);
873 // T.query = R.query;
874 if (m_path
[0u] != wxT('/'))
877 wxString::const_iterator op
= m_path
.begin();
878 wxString::const_iterator bp
= base
.m_path
.begin() + base
.m_path
.length();
880 //not a ending directory? move up
881 if (base
.m_path
[0] && *(bp
-1) != wxT('/'))
882 UpTree(base
.m_path
.begin(), bp
);
884 //normalize directories
885 while(*op
== wxT('.') && *(op
+1) == wxT('.') &&
886 (*(op
+2) == '\0' || *(op
+2) == wxT('/')) )
888 UpTree(base
.m_path
.begin(), bp
);
896 m_path
= base
.m_path
.substr(0, bp
- base
.m_path
.begin()) +
897 m_path
.substr((op
- m_path
.begin()), m_path
.length());
901 //T.fragment = R.fragment;
904 // ---------------------------------------------------------------------------
907 // Moves a URI path up a directory
908 // ---------------------------------------------------------------------------
911 void wxURI::UpTree(wxString::const_iterator uristart
,
912 wxString::const_iterator
& uri
)
914 if (uri
!= uristart
&& *(uri
-1) == wxT('/'))
919 for(;uri
!= uristart
; --uri
)
921 if (*uri
== wxT('/'))
929 if (uri
== uristart
&& *uri
== wxT('/'))
934 // FIXME-UTF8: fix Normalize() to use iterators instead of having this method!
935 /*static*/ void wxURI::UpTree(const wxChar
* uristart
, const wxChar
*& uri
)
937 if (uri
!= uristart
&& *(uri
-1) == wxT('/'))
942 for(;uri
!= uristart
; --uri
)
944 if (*uri
== wxT('/'))
952 if (uri
== uristart
&& *uri
== wxT('/'))
958 // ---------------------------------------------------------------------------
961 // Normalizes directories in-place
963 // I.E. ./ and . are ignored
965 // ../ and .. are removed if a directory is before it, along
966 // with that directory (leading .. and ../ are kept)
967 // ---------------------------------------------------------------------------
970 void wxURI::Normalize(wxChar
* s
, bool bIgnoreLeads
)
980 if (*cp
== wxT('.') && (*(cp
+1) == wxT('/') || *(cp
+1) == '\0')
981 && (bp
== cp
|| *(cp
-1) == wxT('/')))
989 else if (*cp
== wxT('.') && *(cp
+1) == wxT('.') &&
990 (*(cp
+2) == wxT('/') || *(cp
+2) == '\0')
991 && (bp
== cp
|| *(cp
-1) == wxT('/')))
993 //.. _or_ ../ - go up the tree
996 UpTree((const wxChar
*)bp
, (const wxChar
*&)s
);
1003 else if (!bIgnoreLeads
)
1015 if (*(cp
+2) == '\0')
1028 // ---------------------------------------------------------------------------
1031 // Parses 1 to 4 hex values. Returns true if the first character of the input
1032 // string is a valid hex character. It is the caller's responsability to move
1033 // the input string back to its original position on failure.
1034 // ---------------------------------------------------------------------------
1036 bool wxURI::ParseH16(const wxChar
*& uri
)
1042 if(IsHex(*++uri
) && IsHex(*++uri
) && IsHex(*++uri
))
1048 // ---------------------------------------------------------------------------
1051 // Parses a certain version of an IP address and moves the input string past
1052 // it. Returns true if the input string contains the proper version of an ip
1053 // address. It is the caller's responsability to move the input string back
1054 // to its original position on failure.
1055 // ---------------------------------------------------------------------------
1057 bool wxURI::ParseIPv4address(const wxChar
*& uri
)
1059 //IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
1061 //dec-octet = DIGIT ; 0-9
1062 // / %x31-39 DIGIT ; 10-99
1063 // / "1" 2DIGIT ; 100-199
1064 // / "2" %x30-34 DIGIT ; 200-249
1065 // / "25" %x30-35 ; 250-255
1072 //each ip part must be between 0-255 (dupe of version in for loop)
1073 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
1074 //100 or less (note !)
1075 !( (*(uri
-2) < wxT('2')) ||
1077 (*(uri
-2) == wxT('2') &&
1078 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
1086 if(IsDigit(*uri
))++uri
;
1088 //compilers should unroll this loop
1089 for(; iIPv4
< 4; ++iIPv4
)
1091 if (*uri
!= wxT('.') || !IsDigit(*++uri
))
1094 //each ip part must be between 0-255
1095 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
1096 //100 or less (note !)
1097 !( (*(uri
-2) < wxT('2')) ||
1099 (*(uri
-2) == wxT('2') &&
1100 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
1107 if(IsDigit(*uri
))++uri
;
1113 bool wxURI::ParseIPv6address(const wxChar
*& uri
)
1115 // IPv6address = 6( h16 ":" ) ls32
1116 // / "::" 5( h16 ":" ) ls32
1117 // / [ h16 ] "::" 4( h16 ":" ) ls32
1118 // / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1119 // / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1120 // / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1121 // / [ *4( h16 ":" ) h16 ] "::" ls32
1122 // / [ *5( h16 ":" ) h16 ] "::" h16
1123 // / [ *6( h16 ":" ) h16 ] "::"
1125 size_t numPrefix
= 0,
1128 bool bEndHex
= false;
1130 for( ; numPrefix
< 6; ++numPrefix
)
1139 if(*uri
!= wxT(':'))
1145 if(!bEndHex
&& !ParseH16(uri
))
1152 if (*uri
== wxT(':'))
1154 if (*++uri
!= wxT(':'))
1164 if (*uri
!= wxT(':') || *(uri
+1) != wxT(':'))
1169 while (*--uri
!= wxT(':')) {}
1172 const wxChar
* uristart
= uri
;
1174 // ls32 = ( h16 ":" h16 ) / IPv4address
1175 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1180 if (ParseIPv4address(uri
))
1192 maxPostfix
= 4 - numPrefix
;
1196 bool bAllowAltEnding
= maxPostfix
== 0;
1198 for(; maxPostfix
!= 0; --maxPostfix
)
1200 if(!ParseH16(uri
) || *uri
!= wxT(':'))
1206 const wxChar
* uristart
= uri
;
1208 // ls32 = ( h16 ":" h16 ) / IPv4address
1209 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1214 if (ParseIPv4address(uri
))
1219 if (!bAllowAltEnding
)
1223 if(numPrefix
<= 5 && ParseH16(uri
))
1229 bool wxURI::ParseIPvFuture(const wxChar
*& uri
)
1231 // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1232 if (*++uri
!= wxT('v') || !IsHex(*++uri
))
1235 while (IsHex(*++uri
)) {}
1237 if (*uri
!= wxT('.') || !(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')))
1240 while(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')) {}
1246 // ---------------------------------------------------------------------------
1249 // Converts a character into a numeric hexidecimal value, or 0 if the
1250 // passed in character is not a valid hex character
1251 // ---------------------------------------------------------------------------
1254 wxChar
wxURI::CharToHex(const wxChar
& c
)
1256 if ((c
>= wxT('A')) && (c
<= wxT('Z'))) return wxChar(c
- wxT('A') + 0x0A);
1257 if ((c
>= wxT('a')) && (c
<= wxT('z'))) return wxChar(c
- wxT('a') + 0x0a);
1258 if ((c
>= wxT('0')) && (c
<= wxT('9'))) return wxChar(c
- wxT('0') + 0x00);
1263 // ---------------------------------------------------------------------------
1266 // Returns true if the passed in character meets the criteria of the method
1267 // ---------------------------------------------------------------------------
1269 //! unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1270 bool wxURI::IsUnreserved (const wxChar
& c
)
1271 { return IsAlpha(c
) || IsDigit(c
) ||
1275 c
== wxT('~') //tilde
1279 bool wxURI::IsReserved (const wxChar
& c
)
1281 return IsGenDelim(c
) || IsSubDelim(c
);
1284 //! gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
1285 bool wxURI::IsGenDelim (const wxChar
& c
)
1287 return c
== wxT(':') ||
1296 //! sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1297 //! / "*" / "+" / "," / ";" / "="
1298 bool wxURI::IsSubDelim (const wxChar
& c
)
1300 return c
== wxT('!') ||
1314 bool wxURI::IsHex(const wxChar
& c
)
1315 { return IsDigit(c
) || (c
>= wxT('a') && c
<= wxT('f')) || (c
>= wxT('A') && c
<= wxT('F')); }
1317 bool wxURI::IsAlpha(const wxChar
& c
)
1318 { return (c
>= wxT('a') && c
<= wxT('z')) || (c
>= wxT('A') && c
<= wxT('Z')); }
1320 bool wxURI::IsDigit(const wxChar
& c
)
1321 { return c
>= wxT('0') && c
<= wxT('9'); }