]>
git.saurik.com Git - wxWidgets.git/blob - src/common/uri.cpp
5ddfbc3cbc88806824fbf2ef1b75ba9a814dbee3
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"
28 // ---------------------------------------------------------------------------
30 // ---------------------------------------------------------------------------
32 IMPLEMENT_CLASS(wxURI
, wxObject
)
34 // ===========================================================================
36 // ===========================================================================
38 // ---------------------------------------------------------------------------
40 // ---------------------------------------------------------------------------
42 // ---------------------------------------------------------------------------
46 // ---------------------------------------------------------------------------
48 // ---------------------------------------------------------------------------
50 // ---------------------------------------------------------------------------
52 wxURI::wxURI() : m_hostType(wxURI_REGNAME
), m_fields(0)
56 wxURI::wxURI(const wxString
& uri
) : m_hostType(wxURI_REGNAME
), m_fields(0)
61 wxURI::wxURI(const wxURI
& uri
) : wxObject(), m_hostType(wxURI_REGNAME
), m_fields(0)
66 // ---------------------------------------------------------------------------
67 // Destructor and cleanup
68 // ---------------------------------------------------------------------------
77 m_scheme
= m_userinfo
= m_server
= m_port
= m_path
=
78 m_query
= m_fragment
= wxEmptyString
;
80 m_hostType
= wxURI_REGNAME
;
85 // ---------------------------------------------------------------------------
88 // This creates the URI - all we do here is call the main parsing method
89 // ---------------------------------------------------------------------------
91 const wxChar
* wxURI::Create(const wxString
& uri
)
96 // FIXME-UTF8: rewrite ParseXXX() methods using iterators
97 // NB: using wxWxCharBuffer instead of just c_str() avoids keeping
98 // converted string in memory for longer than needed
99 return Parse(wxWxCharBuffer(uri
.c_str()));
102 // ---------------------------------------------------------------------------
105 // TranslateEscape unencodes a 3 character URL escape sequence
107 // Escape encodes an invalid URI character into a 3 character sequence
109 // IsEscape determines if the input string contains an escape sequence,
110 // if it does, then it moves the input string past the escape sequence
112 // Unescape unencodes all 3 character URL escape sequences in a wxString
113 // ---------------------------------------------------------------------------
115 wxUniChar
wxURI::TranslateEscape(const wxString::const_iterator
& s
)
120 wxASSERT_MSG( IsHex(c1
) && IsHex(c2
), wxT("Invalid escape sequence!"));
122 return wx_truncate_cast(wxChar
, (CharToHex(c1
) << 4 ) | CharToHex(c2
));
125 wxString
wxURI::Unescape(const wxString
& uri
)
129 for (wxString::const_iterator i
= uri
.begin(); i
!= uri
.end(); ++i
)
131 if ( *i
== wxT('%') )
133 new_uri
+= wxURI::TranslateEscape(i
+ 1);
143 void wxURI::Escape(wxString
& s
, const wxChar
& c
)
145 const wxChar
* hdig
= wxT("0123456789abcdef");
147 s
+= hdig
[(c
>> 4) & 15];
151 bool wxURI::IsEscape(const wxChar
*& uri
)
153 // pct-encoded = "%" HEXDIG HEXDIG
154 if(*uri
== wxT('%') && IsHex(*(uri
+1)) && IsHex(*(uri
+2)))
160 // ---------------------------------------------------------------------------
164 // Gets the username and password via the old URL method.
165 // ---------------------------------------------------------------------------
166 wxString
wxURI::GetUser() const
168 size_t dwPasswordPos
= m_userinfo
.find(':');
170 if (dwPasswordPos
== wxString::npos
)
173 return m_userinfo(0, dwPasswordPos
);
176 wxString
wxURI::GetPassword() const
178 size_t dwPasswordPos
= m_userinfo
.find(':');
180 if (dwPasswordPos
== wxString::npos
)
183 return m_userinfo(dwPasswordPos
+1, m_userinfo
.length() + 1);
186 // ---------------------------------------------------------------------------
189 // BuildURI() builds the entire URI into a useable
190 // representation, including proper identification characters such as slashes
192 // BuildUnescapedURI() does the same thing as BuildURI(), only it unescapes
193 // the components that accept escape sequences
194 // ---------------------------------------------------------------------------
196 wxString
wxURI::BuildURI() const
201 ret
= ret
+ m_scheme
+ wxT(":");
208 ret
= ret
+ m_userinfo
+ wxT("@");
213 ret
= ret
+ wxT(":") + m_port
;
219 ret
= ret
+ wxT("?") + m_query
;
222 ret
= ret
+ wxT("#") + m_fragment
;
227 wxString
wxURI::BuildUnescapedURI() const
232 ret
= ret
+ m_scheme
+ wxT(":");
239 ret
= ret
+ wxURI::Unescape(m_userinfo
) + wxT("@");
241 if (m_hostType
== wxURI_REGNAME
)
242 ret
+= wxURI::Unescape(m_server
);
247 ret
= ret
+ wxT(":") + m_port
;
250 ret
+= wxURI::Unescape(m_path
);
253 ret
= ret
+ wxT("?") + wxURI::Unescape(m_query
);
256 ret
= ret
+ wxT("#") + wxURI::Unescape(m_fragment
);
261 // ---------------------------------------------------------------------------
263 // ---------------------------------------------------------------------------
265 wxURI
& wxURI::Assign(const wxURI
& uri
)
268 m_fields
= uri
.m_fields
;
270 //ref over components
271 m_scheme
= uri
.m_scheme
;
272 m_userinfo
= uri
.m_userinfo
;
273 m_server
= uri
.m_server
;
274 m_hostType
= uri
.m_hostType
;
277 m_query
= uri
.m_query
;
278 m_fragment
= uri
.m_fragment
;
283 wxURI
& wxURI::operator = (const wxURI
& uri
)
288 wxURI
& wxURI::operator = (const wxString
& string
)
294 // ---------------------------------------------------------------------------
296 // ---------------------------------------------------------------------------
298 bool wxURI::operator == (const wxURI
& uri
) const
302 if(m_scheme
!= uri
.m_scheme
)
305 else if (uri
.HasScheme())
313 if (m_userinfo
!= uri
.m_userinfo
)
316 else if (uri
.HasUserInfo())
319 if (m_server
!= uri
.m_server
||
320 m_hostType
!= uri
.m_hostType
)
325 if(m_port
!= uri
.m_port
)
328 else if (uri
.HasPort())
331 else if (uri
.HasServer())
337 if(m_path
!= uri
.m_path
)
340 else if (uri
.HasPath())
345 if (m_query
!= uri
.m_query
)
348 else if (uri
.HasQuery())
353 if (m_fragment
!= uri
.m_fragment
)
356 else if (uri
.HasFragment())
362 // ---------------------------------------------------------------------------
365 // if there is no authority or scheme, it is a reference
366 // ---------------------------------------------------------------------------
368 bool wxURI::IsReference() const
369 { return !HasScheme() || !HasServer(); }
371 // ---------------------------------------------------------------------------
374 // Master URI parsing method. Just calls the individual parsing methods
376 // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
377 // URI-reference = URI / relative
378 // ---------------------------------------------------------------------------
380 const wxChar
* wxURI::Parse(const wxChar
*uri
)
382 uri
= ParseScheme(uri
);
383 uri
= ParseAuthority(uri
);
384 uri
= ParsePath(uri
);
385 uri
= ParseQuery(uri
);
386 return ParseFragment(uri
);
389 // ---------------------------------------------------------------------------
392 // Individual parsers for each URI component
393 // ---------------------------------------------------------------------------
395 const wxChar
* wxURI::ParseScheme(const wxChar
*uri
)
397 wxASSERT(uri
!= NULL
);
399 //copy of the uri - used for figuring out
400 //length of each component
401 const wxChar
* uricopy
= uri
;
403 //Does the uri have a scheme (first character alpha)?
408 //scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
409 while (IsAlpha(*uri
) || IsDigit(*uri
) ||
418 if (*uri
== wxT(':'))
420 //mark the scheme as valid
421 m_fields
|= wxURI_SCHEME
;
423 //move reference point up to input buffer
427 //relative uri with relative path reference
428 m_scheme
= wxEmptyString
;
431 //relative uri with _possible_ relative path reference
436 const wxChar
* wxURI::ParseAuthority(const wxChar
* uri
)
438 // authority = [ userinfo "@" ] host [ ":" port ]
439 if (*uri
== wxT('/') && *(uri
+1) == wxT('/'))
441 //skip past the two slashes
444 // ############# DEVIATION FROM RFC #########################
445 // Don't parse the server component for file URIs
446 if(m_scheme
!= wxT("file"))
449 uri
= ParseUserInfo(uri
);
450 uri
= ParseServer(uri
);
451 return ParsePort(uri
);
458 const wxChar
* wxURI::ParseUserInfo(const wxChar
* uri
)
460 wxASSERT(uri
!= NULL
);
462 //copy of the uri - used for figuring out
463 //length of each component
464 const wxChar
* uricopy
= uri
;
466 // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
467 while(*uri
&& *uri
!= wxT('@') && *uri
!= wxT('/') && *uri
!= wxT('#') && *uri
!= wxT('?'))
469 if(IsUnreserved(*uri
) ||
470 IsSubDelim(*uri
) || *uri
== wxT(':'))
471 m_userinfo
+= *uri
++;
472 else if (IsEscape(uri
))
474 m_userinfo
+= *uri
++;
475 m_userinfo
+= *uri
++;
476 m_userinfo
+= *uri
++;
479 Escape(m_userinfo
, *uri
++);
485 m_fields
|= wxURI_USERINFO
;
490 m_userinfo
= wxEmptyString
;
495 const wxChar
* wxURI::ParseServer(const wxChar
* uri
)
497 wxASSERT(uri
!= NULL
);
499 //copy of the uri - used for figuring out
500 //length of each component
501 const wxChar
* uricopy
= uri
;
503 // host = IP-literal / IPv4address / reg-name
504 // IP-literal = "[" ( IPv6address / IPvFuture ) "]"
505 if (*uri
== wxT('['))
507 ++uri
; //some compilers don't support *&ing a ++*
508 if (ParseIPv6address(uri
) && *uri
== wxT(']'))
511 m_hostType
= wxURI_IPV6ADDRESS
;
513 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
514 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
515 theBuffer
.SetLength(uri
-uricopy
);
521 ++uri
; //some compilers don't support *&ing a ++*
522 if (ParseIPvFuture(uri
) && *uri
== wxT(']'))
525 m_hostType
= wxURI_IPVFUTURE
;
527 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
528 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
529 theBuffer
.SetLength(uri
-uricopy
);
537 if (ParseIPv4address(uri
))
539 m_hostType
= wxURI_IPV4ADDRESS
;
541 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
542 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
543 theBuffer
.SetLength(uri
-uricopy
);
549 if(m_hostType
== wxURI_REGNAME
)
552 // reg-name = *( unreserved / pct-encoded / sub-delims )
553 while(*uri
&& *uri
!= wxT('/') && *uri
!= wxT(':') && *uri
!= wxT('#') && *uri
!= wxT('?'))
555 if(IsUnreserved(*uri
) || IsSubDelim(*uri
))
557 else if (IsEscape(uri
))
564 Escape(m_server
, *uri
++);
568 //mark the server as valid
569 m_fields
|= wxURI_SERVER
;
575 const wxChar
* wxURI::ParsePort(const wxChar
* uri
)
577 wxASSERT(uri
!= NULL
);
588 //mark the port as valid
589 m_fields
|= wxURI_PORT
;
595 const wxChar
* wxURI::ParsePath(const wxChar
* uri
, bool bReference
, bool bNormalize
)
597 wxASSERT(uri
!= NULL
);
599 //copy of the uri - used for figuring out
600 //length of each component
601 const wxChar
* uricopy
= uri
;
603 /// hier-part = "//" authority path-abempty
608 /// relative-part = "//" authority path-abempty
613 /// path-abempty = *( "/" segment )
614 /// path-absolute = "/" [ segment-nz *( "/" segment ) ]
615 /// path-noscheme = segment-nz-nc *( "/" segment )
616 /// path-rootless = segment-nz *( "/" segment )
617 /// path-empty = 0<pchar>
620 /// segment-nz = 1*pchar
621 /// segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
622 /// ; non-zero-length segment without any colon ":"
624 /// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
625 if (*uri
== wxT('/'))
629 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
631 if( IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
632 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
634 else if (IsEscape(uri
))
641 Escape(m_path
, *uri
++);
646 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
647 #if wxUSE_STL || wxUSE_UNICODE_UTF8
648 // FIXME-UTF8: have some wxReadWriteStringBuffer instead?
649 wxTmemcpy(theBuffer
, m_path
.c_str(), 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'); }