]>
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"
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
)
99 // ---------------------------------------------------------------------------
102 // TranslateEscape unencodes a 3 character URL escape sequence
104 // Escape encodes an invalid URI character into a 3 character sequence
106 // IsEscape determines if the input string contains an escape sequence,
107 // if it does, then it moves the input string past the escape sequence
109 // Unescape unencodes all 3 character URL escape sequences in a wxString
110 // ---------------------------------------------------------------------------
112 wxChar
wxURI::TranslateEscape(const wxChar
* s
)
114 wxASSERT_MSG( IsHex(s
[0]) && IsHex(s
[1]), wxT("Invalid escape sequence!"));
116 return wx_truncate_cast(wxChar
, (CharToHex(s
[0]) << 4 ) | CharToHex(s
[1]));
119 wxString
wxURI::Unescape(const wxString
& uri
)
123 for(size_t i
= 0; i
< uri
.length(); ++i
)
125 if (uri
[i
] == wxT('%'))
127 new_uri
+= wxURI::TranslateEscape( &(uri
.c_str()[i
+1]) );
137 void wxURI::Escape(wxString
& s
, const wxChar
& c
)
139 const wxChar
* hdig
= wxT("0123456789abcdef");
141 s
+= hdig
[(c
>> 4) & 15];
145 bool wxURI::IsEscape(const wxChar
*& uri
)
147 // pct-encoded = "%" HEXDIG HEXDIG
148 if(*uri
== wxT('%') && IsHex(*(uri
+1)) && IsHex(*(uri
+2)))
154 // ---------------------------------------------------------------------------
158 // Gets the username and password via the old URL method.
159 // ---------------------------------------------------------------------------
160 wxString
wxURI::GetUser() const
162 size_t dwPasswordPos
= m_userinfo
.find(':');
164 if (dwPasswordPos
== wxString::npos
)
167 return m_userinfo(0, dwPasswordPos
);
170 wxString
wxURI::GetPassword() const
172 size_t dwPasswordPos
= m_userinfo
.find(':');
174 if (dwPasswordPos
== wxString::npos
)
177 return m_userinfo(dwPasswordPos
+1, m_userinfo
.length() + 1);
180 // ---------------------------------------------------------------------------
183 // BuildURI() builds the entire URI into a useable
184 // representation, including proper identification characters such as slashes
186 // BuildUnescapedURI() does the same thing as BuildURI(), only it unescapes
187 // the components that accept escape sequences
188 // ---------------------------------------------------------------------------
190 wxString
wxURI::BuildURI() const
195 ret
= ret
+ m_scheme
+ wxT(":");
202 ret
= ret
+ m_userinfo
+ wxT("@");
207 ret
= ret
+ wxT(":") + m_port
;
213 ret
= ret
+ wxT("?") + m_query
;
216 ret
= ret
+ wxT("#") + m_fragment
;
221 wxString
wxURI::BuildUnescapedURI() const
226 ret
= ret
+ m_scheme
+ wxT(":");
233 ret
= ret
+ wxURI::Unescape(m_userinfo
) + wxT("@");
235 if (m_hostType
== wxURI_REGNAME
)
236 ret
+= wxURI::Unescape(m_server
);
241 ret
= ret
+ wxT(":") + m_port
;
244 ret
+= wxURI::Unescape(m_path
);
247 ret
= ret
+ wxT("?") + wxURI::Unescape(m_query
);
250 ret
= ret
+ wxT("#") + wxURI::Unescape(m_fragment
);
255 // ---------------------------------------------------------------------------
257 // ---------------------------------------------------------------------------
259 wxURI
& wxURI::Assign(const wxURI
& uri
)
262 m_fields
= uri
.m_fields
;
264 //ref over components
265 m_scheme
= uri
.m_scheme
;
266 m_userinfo
= uri
.m_userinfo
;
267 m_server
= uri
.m_server
;
268 m_hostType
= uri
.m_hostType
;
271 m_query
= uri
.m_query
;
272 m_fragment
= uri
.m_fragment
;
277 wxURI
& wxURI::operator = (const wxURI
& uri
)
282 wxURI
& wxURI::operator = (const wxString
& string
)
288 // ---------------------------------------------------------------------------
290 // ---------------------------------------------------------------------------
292 bool wxURI::operator == (const wxURI
& uri
) const
296 if(m_scheme
!= uri
.m_scheme
)
299 else if (uri
.HasScheme())
307 if (m_userinfo
!= uri
.m_userinfo
)
310 else if (uri
.HasUserInfo())
313 if (m_server
!= uri
.m_server
||
314 m_hostType
!= uri
.m_hostType
)
319 if(m_port
!= uri
.m_port
)
322 else if (uri
.HasPort())
325 else if (uri
.HasServer())
331 if(m_path
!= uri
.m_path
)
334 else if (uri
.HasPath())
339 if (m_query
!= uri
.m_query
)
342 else if (uri
.HasQuery())
347 if (m_fragment
!= uri
.m_fragment
)
350 else if (uri
.HasFragment())
356 // ---------------------------------------------------------------------------
359 // if there is no authority or scheme, it is a reference
360 // ---------------------------------------------------------------------------
362 bool wxURI::IsReference() const
363 { return !HasScheme() || !HasServer(); }
365 // ---------------------------------------------------------------------------
368 // Master URI parsing method. Just calls the individual parsing methods
370 // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
371 // URI-reference = URI / relative
372 // ---------------------------------------------------------------------------
374 const wxChar
* wxURI::Parse(const wxChar
* uri
)
376 uri
= ParseScheme(uri
);
377 uri
= ParseAuthority(uri
);
378 uri
= ParsePath(uri
);
379 uri
= ParseQuery(uri
);
380 return ParseFragment(uri
);
383 // ---------------------------------------------------------------------------
386 // Individual parsers for each URI component
387 // ---------------------------------------------------------------------------
389 const wxChar
* wxURI::ParseScheme(const wxChar
* uri
)
391 wxASSERT(uri
!= NULL
);
393 //copy of the uri - used for figuring out
394 //length of each component
395 const wxChar
* uricopy
= uri
;
397 //Does the uri have a scheme (first character alpha)?
402 //scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
403 while (IsAlpha(*uri
) || IsDigit(*uri
) ||
412 if (*uri
== wxT(':'))
414 //mark the scheme as valid
415 m_fields
|= wxURI_SCHEME
;
417 //move reference point up to input buffer
421 //relative uri with relative path reference
422 m_scheme
= wxEmptyString
;
425 //relative uri with _possible_ relative path reference
430 const wxChar
* wxURI::ParseAuthority(const wxChar
* uri
)
432 // authority = [ userinfo "@" ] host [ ":" port ]
433 if (*uri
== wxT('/') && *(uri
+1) == wxT('/'))
435 //skip past the two slashes
438 // ############# DEVIATION FROM RFC #########################
439 // Don't parse the server component for file URIs
440 if(m_scheme
!= wxT("file"))
443 uri
= ParseUserInfo(uri
);
444 uri
= ParseServer(uri
);
445 return ParsePort(uri
);
452 const wxChar
* wxURI::ParseUserInfo(const wxChar
* uri
)
454 wxASSERT(uri
!= NULL
);
456 //copy of the uri - used for figuring out
457 //length of each component
458 const wxChar
* uricopy
= uri
;
460 // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
461 while(*uri
&& *uri
!= wxT('@') && *uri
!= wxT('/') && *uri
!= wxT('#') && *uri
!= wxT('?'))
463 if(IsUnreserved(*uri
) ||
464 IsSubDelim(*uri
) || *uri
== wxT(':'))
465 m_userinfo
+= *uri
++;
466 else if (IsEscape(uri
))
468 m_userinfo
+= *uri
++;
469 m_userinfo
+= *uri
++;
470 m_userinfo
+= *uri
++;
473 Escape(m_userinfo
, *uri
++);
479 m_fields
|= wxURI_USERINFO
;
484 m_userinfo
= wxEmptyString
;
489 const wxChar
* wxURI::ParseServer(const wxChar
* uri
)
491 wxASSERT(uri
!= NULL
);
493 //copy of the uri - used for figuring out
494 //length of each component
495 const wxChar
* uricopy
= uri
;
497 // host = IP-literal / IPv4address / reg-name
498 // IP-literal = "[" ( IPv6address / IPvFuture ) "]"
499 if (*uri
== wxT('['))
501 ++uri
; //some compilers don't support *&ing a ++*
502 if (ParseIPv6address(uri
) && *uri
== wxT(']'))
505 m_hostType
= wxURI_IPV6ADDRESS
;
507 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
508 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
509 theBuffer
.SetLength(uri
-uricopy
);
515 ++uri
; //some compilers don't support *&ing a ++*
516 if (ParseIPvFuture(uri
) && *uri
== wxT(']'))
519 m_hostType
= wxURI_IPVFUTURE
;
521 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
522 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
523 theBuffer
.SetLength(uri
-uricopy
);
531 if (ParseIPv4address(uri
))
533 m_hostType
= wxURI_IPV4ADDRESS
;
535 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
536 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
537 theBuffer
.SetLength(uri
-uricopy
);
543 if(m_hostType
== wxURI_REGNAME
)
546 // reg-name = *( unreserved / pct-encoded / sub-delims )
547 while(*uri
&& *uri
!= wxT('/') && *uri
!= wxT(':') && *uri
!= wxT('#') && *uri
!= wxT('?'))
549 if(IsUnreserved(*uri
) || IsSubDelim(*uri
))
551 else if (IsEscape(uri
))
558 Escape(m_server
, *uri
++);
562 //mark the server as valid
563 m_fields
|= wxURI_SERVER
;
569 const wxChar
* wxURI::ParsePort(const wxChar
* uri
)
571 wxASSERT(uri
!= NULL
);
582 //mark the port as valid
583 m_fields
|= wxURI_PORT
;
589 const wxChar
* wxURI::ParsePath(const wxChar
* uri
, bool bReference
, bool bNormalize
)
591 wxASSERT(uri
!= NULL
);
593 //copy of the uri - used for figuring out
594 //length of each component
595 const wxChar
* uricopy
= uri
;
597 /// hier-part = "//" authority path-abempty
602 /// relative-part = "//" authority path-abempty
607 /// path-abempty = *( "/" segment )
608 /// path-absolute = "/" [ segment-nz *( "/" segment ) ]
609 /// path-noscheme = segment-nz-nc *( "/" segment )
610 /// path-rootless = segment-nz *( "/" segment )
611 /// path-empty = 0<pchar>
614 /// segment-nz = 1*pchar
615 /// segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
616 /// ; non-zero-length segment without any colon ":"
618 /// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
619 if (*uri
== wxT('/'))
623 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
625 if( IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
626 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
628 else if (IsEscape(uri
))
635 Escape(m_path
, *uri
++);
640 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
642 wxTmemcpy(theBuffer
, m_path
.c_str(), m_path
.length()+1);
644 Normalize(theBuffer
, true);
645 theBuffer
.SetLength(wxStrlen(theBuffer
));
647 //mark the path as valid
648 m_fields
|= wxURI_PATH
;
650 else if(*uri
) //Relative path
655 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
657 if(IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
658 *uri
== wxT('@') || *uri
== wxT('/'))
660 else if (IsEscape(uri
))
667 Escape(m_path
, *uri
++);
672 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
674 if(IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
675 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
677 else if (IsEscape(uri
))
684 Escape(m_path
, *uri
++);
692 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
694 wxTmemcpy(theBuffer
, m_path
.c_str(), m_path
.length()+1);
696 Normalize(theBuffer
);
697 theBuffer
.SetLength(wxStrlen(theBuffer
));
700 //mark the path as valid
701 m_fields
|= wxURI_PATH
;
709 const wxChar
* wxURI::ParseQuery(const wxChar
* uri
)
711 wxASSERT(uri
!= NULL
);
713 // query = *( pchar / "/" / "?" )
714 if (*uri
== wxT('?'))
717 while(*uri
&& *uri
!= wxT('#'))
719 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
720 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
722 else if (IsEscape(uri
))
729 Escape(m_query
, *uri
++);
732 //mark the server as valid
733 m_fields
|= wxURI_QUERY
;
740 const wxChar
* wxURI::ParseFragment(const wxChar
* uri
)
742 wxASSERT(uri
!= NULL
);
744 // fragment = *( pchar / "/" / "?" )
745 if (*uri
== wxT('#'))
750 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) ||
751 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
752 m_fragment
+= *uri
++;
753 else if (IsEscape(uri
))
755 m_fragment
+= *uri
++;
756 m_fragment
+= *uri
++;
757 m_fragment
+= *uri
++;
760 Escape(m_fragment
, *uri
++);
763 //mark the server as valid
764 m_fields
|= wxURI_FRAGMENT
;
770 // ---------------------------------------------------------------------------
773 // Builds missing components of this uri from a base uri
775 // A version of the algorithm outlined in the RFC is used here
776 // (it is shown in comments)
778 // Note that an empty URI inherits all components
779 // ---------------------------------------------------------------------------
781 void wxURI::Resolve(const wxURI
& base
, int flags
)
783 wxASSERT_MSG(!base
.IsReference(),
784 wxT("wxURI to inherit from must not be a reference!"));
786 // If we arn't being strict, enable the older (pre-RFC2396)
787 // loophole that allows this uri to inherit other
788 // properties from the base uri - even if the scheme
790 if ( !(flags
& wxURI_STRICT
) &&
791 HasScheme() && base
.HasScheme() &&
792 m_scheme
== base
.m_scheme
)
794 m_fields
-= wxURI_SCHEME
;
798 // Do nothing if this is an absolute wxURI
799 // if defined(R.scheme) then
800 // T.scheme = R.scheme;
801 // T.authority = R.authority;
802 // T.path = remove_dot_segments(R.path);
803 // T.query = R.query;
809 //No scheme - inherit
810 m_scheme
= base
.m_scheme
;
811 m_fields
|= wxURI_SCHEME
;
813 // All we need to do for relative URIs with an
814 // authority component is just inherit the scheme
815 // if defined(R.authority) then
816 // T.authority = R.authority;
817 // T.path = remove_dot_segments(R.path);
818 // T.query = R.query;
824 //No authority - inherit
825 if (base
.HasUserInfo())
827 m_userinfo
= base
.m_userinfo
;
828 m_fields
|= wxURI_USERINFO
;
831 m_server
= base
.m_server
;
832 m_hostType
= base
.m_hostType
;
833 m_fields
|= wxURI_SERVER
;
837 m_port
= base
.m_port
;
838 m_fields
|= wxURI_PORT
;
842 // Simple path inheritance from base
845 // T.path = Base.path;
846 m_path
= base
.m_path
;
847 m_fields
|= wxURI_PATH
;
850 // if defined(R.query) then
851 // T.query = R.query;
853 // T.query = Base.query;
857 m_query
= base
.m_query
;
858 m_fields
|= wxURI_QUERY
;
863 // if (R.path starts-with "/") then
864 // T.path = remove_dot_segments(R.path);
866 // T.path = merge(Base.path, R.path);
867 // T.path = remove_dot_segments(T.path);
869 // T.query = R.query;
870 if (m_path
[0u] != wxT('/'))
873 const wxChar
* op
= m_path
.c_str();
874 const wxChar
* bp
= base
.m_path
.c_str() + base
.m_path
.Length();
876 //not a ending directory? move up
877 if (base
.m_path
[0] && *(bp
-1) != wxT('/'))
878 UpTree(base
.m_path
, bp
);
880 //normalize directories
881 while(*op
== wxT('.') && *(op
+1) == wxT('.') &&
882 (*(op
+2) == '\0' || *(op
+2) == wxT('/')) )
884 UpTree(base
.m_path
, bp
);
892 m_path
= base
.m_path
.substr(0, bp
- base
.m_path
.c_str()) +
893 m_path
.substr((op
- m_path
.c_str()), m_path
.Length());
897 //T.fragment = R.fragment;
900 // ---------------------------------------------------------------------------
903 // Moves a URI path up a directory
904 // ---------------------------------------------------------------------------
907 void wxURI::UpTree(const wxChar
* uristart
, const wxChar
*& uri
)
909 if (uri
!= uristart
&& *(uri
-1) == wxT('/'))
914 for(;uri
!= uristart
; --uri
)
916 if (*uri
== wxT('/'))
924 if (uri
== uristart
&& *uri
== wxT('/'))
929 // ---------------------------------------------------------------------------
932 // Normalizes directories in-place
934 // I.E. ./ and . are ignored
936 // ../ and .. are removed if a directory is before it, along
937 // with that directory (leading .. and ../ are kept)
938 // ---------------------------------------------------------------------------
941 void wxURI::Normalize(wxChar
* s
, bool bIgnoreLeads
)
951 if (*cp
== wxT('.') && (*(cp
+1) == wxT('/') || *(cp
+1) == '\0')
952 && (bp
== cp
|| *(cp
-1) == wxT('/')))
960 else if (*cp
== wxT('.') && *(cp
+1) == wxT('.') &&
961 (*(cp
+2) == wxT('/') || *(cp
+2) == '\0')
962 && (bp
== cp
|| *(cp
-1) == wxT('/')))
964 //.. _or_ ../ - go up the tree
967 UpTree((const wxChar
*)bp
, (const wxChar
*&)s
);
974 else if (!bIgnoreLeads
)
999 // ---------------------------------------------------------------------------
1002 // Parses 1 to 4 hex values. Returns true if the first character of the input
1003 // string is a valid hex character. It is the caller's responsability to move
1004 // the input string back to its original position on failure.
1005 // ---------------------------------------------------------------------------
1007 bool wxURI::ParseH16(const wxChar
*& uri
)
1013 if(IsHex(*++uri
) && IsHex(*++uri
) && IsHex(*++uri
))
1019 // ---------------------------------------------------------------------------
1022 // Parses a certain version of an IP address and moves the input string past
1023 // it. Returns true if the input string contains the proper version of an ip
1024 // address. It is the caller's responsability to move the input string back
1025 // to its original position on failure.
1026 // ---------------------------------------------------------------------------
1028 bool wxURI::ParseIPv4address(const wxChar
*& uri
)
1030 //IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
1032 //dec-octet = DIGIT ; 0-9
1033 // / %x31-39 DIGIT ; 10-99
1034 // / "1" 2DIGIT ; 100-199
1035 // / "2" %x30-34 DIGIT ; 200-249
1036 // / "25" %x30-35 ; 250-255
1043 //each ip part must be between 0-255 (dupe of version in for loop)
1044 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
1045 //100 or less (note !)
1046 !( (*(uri
-2) < wxT('2')) ||
1048 (*(uri
-2) == wxT('2') &&
1049 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
1057 if(IsDigit(*uri
))++uri
;
1059 //compilers should unroll this loop
1060 for(; iIPv4
< 4; ++iIPv4
)
1062 if (*uri
!= wxT('.') || !IsDigit(*++uri
))
1065 //each ip part must be between 0-255
1066 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
1067 //100 or less (note !)
1068 !( (*(uri
-2) < wxT('2')) ||
1070 (*(uri
-2) == wxT('2') &&
1071 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
1078 if(IsDigit(*uri
))++uri
;
1084 bool wxURI::ParseIPv6address(const wxChar
*& uri
)
1086 // IPv6address = 6( h16 ":" ) ls32
1087 // / "::" 5( h16 ":" ) ls32
1088 // / [ h16 ] "::" 4( h16 ":" ) ls32
1089 // / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1090 // / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1091 // / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1092 // / [ *4( h16 ":" ) h16 ] "::" ls32
1093 // / [ *5( h16 ":" ) h16 ] "::" h16
1094 // / [ *6( h16 ":" ) h16 ] "::"
1096 size_t numPrefix
= 0,
1099 bool bEndHex
= false;
1101 for( ; numPrefix
< 6; ++numPrefix
)
1110 if(*uri
!= wxT(':'))
1116 if(!bEndHex
&& !ParseH16(uri
))
1123 if (*uri
== wxT(':'))
1125 if (*++uri
!= wxT(':'))
1135 if (*uri
!= wxT(':') || *(uri
+1) != wxT(':'))
1140 while (*--uri
!= wxT(':')) {}
1143 const wxChar
* uristart
= uri
;
1145 // ls32 = ( h16 ":" h16 ) / IPv4address
1146 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1151 if (ParseIPv4address(uri
))
1163 maxPostfix
= 4 - numPrefix
;
1167 bool bAllowAltEnding
= maxPostfix
== 0;
1169 for(; maxPostfix
!= 0; --maxPostfix
)
1171 if(!ParseH16(uri
) || *uri
!= wxT(':'))
1177 const wxChar
* uristart
= uri
;
1179 // ls32 = ( h16 ":" h16 ) / IPv4address
1180 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1185 if (ParseIPv4address(uri
))
1190 if (!bAllowAltEnding
)
1194 if(numPrefix
<= 5 && ParseH16(uri
))
1200 bool wxURI::ParseIPvFuture(const wxChar
*& uri
)
1202 // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1203 if (*++uri
!= wxT('v') || !IsHex(*++uri
))
1206 while (IsHex(*++uri
)) {}
1208 if (*uri
!= wxT('.') || !(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')))
1211 while(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')) {}
1217 // ---------------------------------------------------------------------------
1220 // Converts a character into a numeric hexidecimal value, or 0 if the
1221 // passed in character is not a valid hex character
1222 // ---------------------------------------------------------------------------
1225 wxChar
wxURI::CharToHex(const wxChar
& c
)
1227 if ((c
>= wxT('A')) && (c
<= wxT('Z'))) return wxChar(c
- wxT('A') + 0x0A);
1228 if ((c
>= wxT('a')) && (c
<= wxT('z'))) return wxChar(c
- wxT('a') + 0x0a);
1229 if ((c
>= wxT('0')) && (c
<= wxT('9'))) return wxChar(c
- wxT('0') + 0x00);
1234 // ---------------------------------------------------------------------------
1237 // Returns true if the passed in character meets the criteria of the method
1238 // ---------------------------------------------------------------------------
1240 //! unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1241 bool wxURI::IsUnreserved (const wxChar
& c
)
1242 { return IsAlpha(c
) || IsDigit(c
) ||
1246 c
== wxT('~') //tilde
1250 bool wxURI::IsReserved (const wxChar
& c
)
1252 return IsGenDelim(c
) || IsSubDelim(c
);
1255 //! gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
1256 bool wxURI::IsGenDelim (const wxChar
& c
)
1258 return c
== wxT(':') ||
1267 //! sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1268 //! / "*" / "+" / "," / ";" / "="
1269 bool wxURI::IsSubDelim (const wxChar
& c
)
1271 return c
== wxT('!') ||
1285 bool wxURI::IsHex(const wxChar
& c
)
1286 { return IsDigit(c
) || (c
>= wxT('a') && c
<= wxT('f')) || (c
>= wxT('A') && c
<= wxT('F')); }
1288 bool wxURI::IsAlpha(const wxChar
& c
)
1289 { return (c
>= wxT('a') && c
<= wxT('z')) || (c
>= wxT('A') && c
<= wxT('Z')); }
1291 bool wxURI::IsDigit(const wxChar
& c
)
1292 { return c
>= wxT('0') && c
<= wxT('9'); }