]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma implementation "uri.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #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
) : m_hostType(wxURI_REGNAME
), m_fields(0)
70 // ---------------------------------------------------------------------------
71 // Destructor and cleanup
72 // ---------------------------------------------------------------------------
81 m_scheme
= m_user
= m_server
= m_port
= m_path
=
82 m_query
= m_fragment
= wxT("");
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
)
103 // ---------------------------------------------------------------------------
106 // TranslateEscape unencodes a 3 character URL escape sequence
108 // Escape encodes an invalid URI character into a 3 character sequence
110 // IsEscape determines if the input string contains an escape sequence,
111 // if it does, then it moves the input string past the escape sequence
113 // Unescape unencodes all 3 character URL escape sequences in a wxString
114 // ---------------------------------------------------------------------------
116 wxChar
wxURI::TranslateEscape(const wxChar
* s
)
118 wxASSERT_MSG(IsHex(*s
) && IsHex(*(s
+1)), wxT("Invalid escape!"));
121 return (wxChar
)( CharToHex(*s
) << 4 ) | CharToHex(*++s
);
124 wxString
wxURI::Unescape(const wxString
& uri
)
128 for(size_t i
= 0; i
< uri
.length(); ++i
)
130 if (uri
[i
] == wxT('%'))
132 new_uri
+= wxURI::TranslateEscape( &(uri
.c_str()[i
+1]) );
142 void wxURI::Escape(wxString
& s
, const wxChar
& c
)
144 const wxChar
* hdig
= wxT("0123456789abcdef");
146 s
+= hdig
[(c
>> 4) & 15];
150 bool wxURI::IsEscape(const wxChar
*& uri
)
152 // pct-encoded = "%" HEXDIG HEXDIG
153 if(*uri
== wxT('%') && IsHex(*(uri
+1)) && IsHex(*(uri
+2)))
162 // ---------------------------------------------------------------------------
165 // BuildURI() builds the entire URI into a useable
166 // representation, including proper identification characters such as slashes
168 // BuildUnescapedURI() does the same thing as BuildURI(), only it unescapes
169 // the components that accept escape sequences
170 // ---------------------------------------------------------------------------
172 wxString
wxURI::BuildURI() const
177 ret
= ret
+ m_scheme
+ wxT(":");
184 ret
= ret
+ m_user
+ wxT("@");
189 ret
= ret
+ wxT(":") + m_port
;
195 ret
= ret
+ wxT("?") + m_query
;
198 ret
= ret
+ wxT("#") + m_fragment
;
203 wxString
wxURI::BuildUnescapedURI() const
208 ret
= ret
+ m_scheme
+ wxT(":");
215 ret
= ret
+ wxURI::Unescape(m_user
) + wxT("@");
217 if (m_hostType
== wxURI_REGNAME
)
218 ret
+= wxURI::Unescape(m_server
);
223 ret
= ret
+ wxT(":") + m_port
;
226 ret
+= wxURI::Unescape(m_path
);
229 ret
= ret
+ wxT("?") + wxURI::Unescape(m_query
);
232 ret
= ret
+ wxT("#") + wxURI::Unescape(m_fragment
);
237 // ---------------------------------------------------------------------------
239 // ---------------------------------------------------------------------------
241 wxURI
& wxURI::Assign(const wxURI
& uri
)
244 m_fields
= uri
.m_fields
;
246 //ref over components
247 m_scheme
= uri
.m_scheme
;
249 m_server
= uri
.m_server
;
250 m_hostType
= uri
.m_hostType
;
253 m_query
= uri
.m_query
;
254 m_fragment
= uri
.m_fragment
;
259 wxURI
& wxURI::operator = (const wxURI
& uri
)
264 wxURI
& wxURI::operator = (const wxString
& string
)
270 // ---------------------------------------------------------------------------
272 // ---------------------------------------------------------------------------
274 bool wxURI::operator == (const wxURI
& uri
) const
278 if(m_scheme
!= uri
.m_scheme
)
281 else if (uri
.HasScheme())
289 if (m_user
!= uri
.m_user
)
292 else if (uri
.HasUser())
295 if (m_server
!= uri
.m_server
||
296 m_hostType
!= uri
.m_hostType
)
301 if(m_port
!= uri
.m_port
)
304 else if (uri
.HasPort())
307 else if (uri
.HasServer())
313 if(m_path
!= uri
.m_path
)
316 else if (uri
.HasPath())
321 if (m_query
!= uri
.m_query
)
324 else if (uri
.HasQuery())
329 if (m_fragment
!= uri
.m_fragment
)
332 else if (uri
.HasFragment())
338 // ---------------------------------------------------------------------------
341 // if there is no authority or scheme, it is a reference
342 // ---------------------------------------------------------------------------
344 bool wxURI::IsReference() const
345 { return !HasScheme() || !HasServer(); }
347 // ---------------------------------------------------------------------------
350 // Master URI parsing method. Just calls the individual parsing methods
352 // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
353 // URI-reference = URI / relative-URITestCase
354 // ---------------------------------------------------------------------------
356 const wxChar
* wxURI::Parse(const wxChar
* uri
)
358 uri
= ParseScheme(uri
);
359 uri
= ParseAuthority(uri
);
360 uri
= ParsePath(uri
);
361 uri
= ParseQuery(uri
);
362 return ParseFragment(uri
);
365 // ---------------------------------------------------------------------------
368 // Individual parsers for each URI component
369 // ---------------------------------------------------------------------------
371 const wxChar
* wxURI::ParseScheme(const wxChar
* uri
)
373 wxASSERT(uri
!= NULL
);
375 //copy of the uri - used for figuring out
376 //length of each component
377 const wxChar
* uricopy
= uri
;
379 //Does the uri have a scheme (first character alpha)?
384 //scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
385 while (IsAlpha(*uri
) || IsDigit(*uri
) ||
394 if (*uri
== wxT(':'))
396 //mark the scheme as valid
397 m_fields
|= wxURI_SCHEME
;
399 //move reference point up to input buffer
403 //relative uri with relative path reference
407 //relative uri with _possible_ relative path reference
412 const wxChar
* wxURI::ParseAuthority(const wxChar
* uri
)
414 // authority = [ userinfo "@" ] host [ ":" port ]
415 if (*uri
== wxT('/') && *(uri
+1) == wxT('/'))
419 uri
= ParseUser(uri
);
420 uri
= ParseServer(uri
);
421 return ParsePort(uri
);
427 const wxChar
* wxURI::ParseUser(const wxChar
* uri
)
429 wxASSERT(uri
!= NULL
);
431 //copy of the uri - used for figuring out
432 //length of each component
433 const wxChar
* uricopy
= uri
;
435 // userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
436 while(*uri
&& *uri
!= wxT('@') && *uri
!= wxT('/') && *uri
!= wxT('#') && *uri
!= wxT('?'))
438 if(IsUnreserved(*uri
) || IsEscape(uri
) ||
439 IsSubDelim(*uri
) || *uri
== wxT(':'))
442 Escape(m_user
, *uri
++);
448 m_fields
|= wxURI_USER
;
458 const wxChar
* wxURI::ParseServer(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 // host = IP-literal / IPv4address / reg-name
467 // IP-literal = "[" ( IPv6address / IPvFuture ) "]"
468 if (*uri
== wxT('['))
470 ++uri
; //some compilers don't support *&ing a ++*
471 if (ParseIPv6address(uri
) && *uri
== wxT(']'))
474 m_hostType
= wxURI_IPV6ADDRESS
;
476 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
477 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
478 theBuffer
.SetLength(uri
-uricopy
);
484 ++uri
; //some compilers don't support *&ing a ++*
485 if (ParseIPvFuture(uri
) && *uri
== wxT(']'))
488 m_hostType
= wxURI_IPVFUTURE
;
490 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
491 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
492 theBuffer
.SetLength(uri
-uricopy
);
500 if (ParseIPv4address(uri
))
502 m_hostType
= wxURI_IPV4ADDRESS
;
504 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
505 wxTmemcpy(theBuffer
, uricopy
, uri
-uricopy
);
506 theBuffer
.SetLength(uri
-uricopy
);
512 if(m_hostType
== wxURI_REGNAME
)
515 // reg-name = *( unreserved / pct-encoded / sub-delims )
516 while(*uri
&& *uri
!= wxT('/') && *uri
!= wxT(':') && *uri
!= wxT('#') && *uri
!= wxT('?'))
518 if(IsUnreserved(*uri
) || IsEscape(uri
) || IsSubDelim(*uri
))
521 Escape(m_server
, *uri
++);
525 //mark the server as valid
526 m_fields
|= wxURI_SERVER
;
532 const wxChar
* wxURI::ParsePort(const wxChar
* uri
)
534 wxASSERT(uri
!= NULL
);
545 //mark the port as valid
546 m_fields
|= wxURI_PORT
;
552 const wxChar
* wxURI::ParsePath(const wxChar
* uri
, bool bReference
, bool bNormalize
)
554 wxASSERT(uri
!= NULL
);
556 //copy of the uri - used for figuring out
557 //length of each component
558 const wxChar
* uricopy
= uri
;
560 /// hier-part = "//" authority path-abempty
565 /// relative-part = "//" authority path-abempty
570 /// path-abempty = *( "/" segment )
571 /// path-absolute = "/" [ segment-nz *( "/" segment ) ]
572 /// path-noscheme = segment-nz-nc *( "/" segment )
573 /// path-rootless = segment-nz *( "/" segment )
574 /// path-empty = 0<pchar>
577 /// segment-nz = 1*pchar
578 /// segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
579 /// ; non-zero-length segment without any colon ":"
581 /// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
582 if (*uri
== wxT('/'))
586 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
588 if( IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
589 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
592 Escape(m_path
, *uri
++);
597 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
599 wxTmemcpy(theBuffer
, m_path
.c_str(), m_path
.length()+1);
601 Normalize(theBuffer
, true);
602 theBuffer
.SetLength(wxStrlen(theBuffer
));
604 //mark the path as valid
605 m_fields
|= wxURI_PATH
;
607 else if(*uri
) //Relative path
612 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
614 if(IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
615 *uri
== wxT('@') || *uri
== wxT('/'))
618 Escape(m_path
, *uri
++);
623 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
625 if(IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
626 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
629 Escape(m_path
, *uri
++);
637 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
639 wxTmemcpy(theBuffer
, m_path
.c_str(), m_path
.length()+1);
641 Normalize(theBuffer
);
642 theBuffer
.SetLength(wxStrlen(theBuffer
));
645 //mark the path as valid
646 m_fields
|= wxURI_PATH
;
654 const wxChar
* wxURI::ParseQuery(const wxChar
* uri
)
656 wxASSERT(uri
!= NULL
);
658 // query = *( pchar / "/" / "?" )
659 if (*uri
== wxT('?'))
662 while(*uri
&& *uri
!= wxT('#'))
664 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
665 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
668 Escape(m_query
, *uri
++);
671 //mark the server as valid
672 m_fields
|= wxURI_QUERY
;
679 const wxChar
* wxURI::ParseFragment(const wxChar
* uri
)
681 wxASSERT(uri
!= NULL
);
683 // fragment = *( pchar / "/" / "?" )
684 if (*uri
== wxT('#'))
689 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
690 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
691 m_fragment
+= *uri
++;
693 Escape(m_fragment
, *uri
++);
696 //mark the server as valid
697 m_fields
|= wxURI_FRAGMENT
;
703 // ---------------------------------------------------------------------------
706 // Builds missing components of this uri from a base uri
708 // A version of the algorithm outlined in the RFC is used here
709 // (it is shown in comments)
711 // Note that an empty URI inherits all components
712 // ---------------------------------------------------------------------------
714 void wxURI::Resolve(const wxURI
& base
, int flags
)
716 wxASSERT_MSG(!base
.IsReference(),
717 wxT("wxURI to inherit from must not be a reference!"));
719 // If we arn't being strict, enable the older (pre-RFC2396)
720 // loophole that allows this uri to inherit other
721 // properties from the base uri - even if the scheme
723 if ( !(flags
& wxURI_STRICT
) &&
724 HasScheme() && base
.HasScheme() &&
725 m_scheme
== base
.m_scheme
)
727 m_fields
-= wxURI_SCHEME
;
731 // Do nothing if this is an absolute wxURI
732 // if defined(R.scheme) then
733 // T.scheme = R.scheme;
734 // T.authority = R.authority;
735 // T.path = remove_dot_segments(R.path);
736 // T.query = R.query;
742 //No scheme - inherit
743 m_scheme
= base
.m_scheme
;
744 m_fields
|= wxURI_SCHEME
;
746 // All we need to do for relative URIs with an
747 // authority component is just inherit the scheme
748 // if defined(R.authority) then
749 // T.authority = R.authority;
750 // T.path = remove_dot_segments(R.path);
751 // T.query = R.query;
757 //No authority - inherit
760 m_user
= base
.m_user
;
761 m_fields
|= wxURI_USER
;
764 m_server
= base
.m_server
;
765 m_hostType
= base
.m_hostType
;
766 m_fields
|= wxURI_SERVER
;
770 m_port
= base
.m_port
;
771 m_fields
|= wxURI_PORT
;
775 // Simple path inheritance from base
778 // T.path = Base.path;
779 m_path
= base
.m_path
;
780 m_fields
|= wxURI_PATH
;
783 // if defined(R.query) then
784 // T.query = R.query;
786 // T.query = Base.query;
790 m_query
= base
.m_query
;
791 m_fields
|= wxURI_QUERY
;
796 // if (R.path starts-with "/") then
797 // T.path = remove_dot_segments(R.path);
799 // T.path = merge(Base.path, R.path);
800 // T.path = remove_dot_segments(T.path);
802 // T.query = R.query;
803 if (m_path
[0u] != wxT('/'))
806 const wxChar
* op
= m_path
.c_str();
807 const wxChar
* bp
= base
.m_path
.c_str() + base
.m_path
.Length();
809 //not a ending directory? move up
810 if (base
.m_path
[0] && *(bp
-1) != wxT('/'))
811 UpTree(base
.m_path
, bp
);
813 //normalize directories
814 while(*op
== wxT('.') && *(op
+1) == wxT('.') &&
815 (*(op
+2) == '\0' || *(op
+2) == wxT('/')) )
817 UpTree(base
.m_path
, bp
);
825 m_path
= base
.m_path
.substr(0, bp
- base
.m_path
.c_str()) +
826 m_path
.substr((op
- m_path
.c_str()), m_path
.Length());
830 //T.fragment = R.fragment;
833 // ---------------------------------------------------------------------------
836 // Moves a URI path up a directory
837 // ---------------------------------------------------------------------------
840 void wxURI::UpTree(const wxChar
* uristart
, const wxChar
*& uri
)
842 if (uri
!= uristart
&& *(uri
-1) == wxT('/'))
847 for(;uri
!= uristart
; --uri
)
849 if (*uri
== wxT('/'))
857 if (uri
== uristart
&& *uri
== wxT('/'))
862 // ---------------------------------------------------------------------------
865 // Normalizes directories in-place
867 // I.E. ./ and . are ignored
869 // ../ and .. are removed if a directory is before it, along
870 // with that directory (leading .. and ../ are kept)
871 // ---------------------------------------------------------------------------
874 void wxURI::Normalize(wxChar
* s
, bool bIgnoreLeads
)
884 if (*cp
== wxT('.') && (*(cp
+1) == wxT('/') || *(cp
+1) == '\0')
885 && (bp
== cp
|| *(cp
-1) == wxT('/')))
893 else if (*cp
== wxT('.') && *(cp
+1) == wxT('.') &&
894 (*(cp
+2) == wxT('/') || *(cp
+2) == '\0')
895 && (bp
== cp
|| *(cp
-1) == wxT('/')))
897 //.. _or_ ../ - go up the tree
900 UpTree((const wxChar
*)bp
, (const wxChar
*&)s
);
907 else if (!bIgnoreLeads
)
932 // ---------------------------------------------------------------------------
935 // Parses 1 to 4 hex values. Returns true if the first character of the input
936 // string is a valid hex character. It is the caller's responsability to move
937 // the input string back to its original position on failure.
938 // ---------------------------------------------------------------------------
940 bool wxURI::ParseH16(const wxChar
*& uri
)
946 if(IsHex(*++uri
) && IsHex(*++uri
) && IsHex(*++uri
))
952 // ---------------------------------------------------------------------------
955 // Parses a certain version of an IP address and moves the input string past
956 // it. Returns true if the input string contains the proper version of an ip
957 // address. It is the caller's responsability to move the input string back
958 // to its original position on failure.
959 // ---------------------------------------------------------------------------
961 bool wxURI::ParseIPv4address(const wxChar
*& uri
)
963 //IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
965 //dec-octet = DIGIT ; 0-9
966 // / %x31-39 DIGIT ; 10-99
967 // / "1" 2DIGIT ; 100-199
968 // / "2" %x30-34 DIGIT ; 200-249
969 // / "25" %x30-35 ; 250-255
976 //each ip part must be between 0-255 (dupe of version in for loop)
977 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
978 //100 or less (note !)
979 !( (*(uri
-2) < wxT('2')) ||
981 (*(uri
-2) == wxT('2') &&
982 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
990 if(IsDigit(*uri
))++uri
;
992 //compilers should unroll this loop
993 for(; iIPv4
< 4; ++iIPv4
)
995 if (*uri
!= wxT('.') || !IsDigit(*++uri
))
998 //each ip part must be between 0-255
999 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
1000 //100 or less (note !)
1001 !( (*(uri
-2) < wxT('2')) ||
1003 (*(uri
-2) == wxT('2') &&
1004 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
1011 if(IsDigit(*uri
))++uri
;
1017 bool wxURI::ParseIPv6address(const wxChar
*& uri
)
1019 // IPv6address = 6( h16 ":" ) ls32
1020 // / "::" 5( h16 ":" ) ls32
1021 // / [ h16 ] "::" 4( h16 ":" ) ls32
1022 // / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1023 // / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1024 // / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1025 // / [ *4( h16 ":" ) h16 ] "::" ls32
1026 // / [ *5( h16 ":" ) h16 ] "::" h16
1027 // / [ *6( h16 ":" ) h16 ] "::"
1029 size_t numPrefix
= 0,
1032 bool bEndHex
= false;
1034 for( ; numPrefix
< 6; ++numPrefix
)
1043 if(*uri
!= wxT(':'))
1049 if(!bEndHex
&& !ParseH16(uri
))
1056 if (*uri
== wxT(':'))
1058 if (*++uri
!= wxT(':'))
1068 if (*uri
!= wxT(':') || *(uri
+1) != wxT(':'))
1073 while (*--uri
!= wxT(':')) {}
1076 const wxChar
* uristart
= uri
;
1078 // ls32 = ( h16 ":" h16 ) / IPv4address
1079 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1084 if (ParseIPv4address(uri
))
1096 maxPostfix
= 4 - numPrefix
;
1100 bool bAllowAltEnding
= maxPostfix
== 0;
1102 for(; maxPostfix
!= 0; --maxPostfix
)
1104 if(!ParseH16(uri
) || *uri
!= wxT(':'))
1110 const wxChar
* uristart
= uri
;
1112 // ls32 = ( h16 ":" h16 ) / IPv4address
1113 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1118 if (ParseIPv4address(uri
))
1123 if (!bAllowAltEnding
)
1127 if(numPrefix
<= 5 && ParseH16(uri
))
1133 bool wxURI::ParseIPvFuture(const wxChar
*& uri
)
1135 // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1136 if (*++uri
!= wxT('v') || !IsHex(*++uri
))
1139 while (IsHex(*++uri
)) {}
1141 if (*uri
!= wxT('.') || !(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')))
1144 while(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')) {}
1150 // ---------------------------------------------------------------------------
1153 // Converts a character into a numeric hexidecimal value, or 0 if the
1154 // passed in character is not a valid hex character
1155 // ---------------------------------------------------------------------------
1158 wxChar
wxURI::CharToHex(const wxChar
& c
)
1160 if ((c
>= wxT('A')) && (c
<= wxT('Z'))) return wxChar(c
- wxT('A') + 0x0A);
1161 if ((c
>= wxT('a')) && (c
<= wxT('z'))) return wxChar(c
- wxT('a') + 0x0a);
1162 if ((c
>= wxT('0')) && (c
<= wxT('9'))) return wxChar(c
- wxT('0') + 0x00);
1167 // ---------------------------------------------------------------------------
1170 // Returns true if the passed in character meets the criteria of the method
1171 // ---------------------------------------------------------------------------
1173 //! unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1174 bool wxURI::IsUnreserved (const wxChar
& c
)
1175 { return IsAlpha(c
) || IsDigit(c
) ||
1179 c
== wxT('~') //tilde
1183 bool wxURI::IsReserved (const wxChar
& c
)
1185 return IsGenDelim(c
) || IsSubDelim(c
);
1188 //! gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
1189 bool wxURI::IsGenDelim (const wxChar
& c
)
1191 return c
== wxT(':') ||
1200 //! sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1201 //! / "*" / "+" / "," / ";" / "="
1202 bool wxURI::IsSubDelim (const wxChar
& c
)
1204 return c
== wxT('!') ||
1218 bool wxURI::IsHex(const wxChar
& c
)
1219 { return IsDigit(c
) || (c
>= wxT('a') && c
<= wxT('f')) || (c
>= wxT('A') && c
<= wxT('F')); }
1221 bool wxURI::IsAlpha(const wxChar
& c
)
1222 { return (c
>= wxT('a') && c
<= wxT('z')) || (c
>= wxT('A') && c
<= wxT('Z')); }
1224 bool wxURI::IsDigit(const wxChar
& c
)
1225 { return c
>= wxT('0') && c
<= wxT('9'); }
1228 // ---------------------------------------------------------------------------
1230 // wxURL Compatability
1232 // ---------------------------------------------------------------------------
1236 #if WXWIN_COMPATIBILITY_2_4
1240 wxString
wxURL::GetProtocolName() const
1245 wxString
wxURL::GetHostName() const
1250 wxString
wxURL::GetPath() const
1255 //Note that this old code really doesn't convert to a URI that well and looks
1256 //more like a dirty hack than anything else...
1258 wxString
wxURL::ConvertToValidURI(const wxString
& uri
, const wxChar
* delims
)
1264 for (i
= 0; i
< uri
.Len(); i
++)
1266 wxChar c
= uri
.GetChar(i
);
1270 // GRG, Apr/2000: changed to "%20" instead of '+'
1272 out_str
+= wxT("%20");
1276 // GRG, Apr/2000: modified according to the URI definition (RFC 2396)
1278 // - Alphanumeric characters are never escaped
1279 // - Unreserved marks are never escaped
1280 // - Delimiters must be escaped if they appear within a component
1281 // but not if they are used to separate components. Here we have
1282 // no clear way to distinguish between these two cases, so they
1283 // are escaped unless they are passed in the 'delims' parameter
1284 // (allowed delimiters).
1286 static const wxChar marks
[] = wxT("-_.!~*()'");
1288 if ( !wxIsalnum(c
) && !wxStrchr(marks
, c
) && !wxStrchr(delims
, c
) )
1290 hexa_code
.Printf(wxT("%%%02X"), c
);
1291 out_str
+= hexa_code
;
1303 wxString
wxURL::ConvertFromURI(const wxString
& uri
)
1305 return wxURI::Unescape(uri
);
1308 #endif //WXWIN_COMPATIBILITY_2_4