]>
git.saurik.com Git - wxWidgets.git/blob - src/common/uri.cpp
584eaf37e1c9bdf581ce6219498268010dee548e
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 ( 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 if (ParseIPv6address(++uri
) && *uri
== wxT(']'))
473 m_hostType
= wxURI_IPV6ADDRESS
;
475 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
476 wxMemcpy(theBuffer
, uricopy
, uri
-uricopy
);
477 theBuffer
.SetLength(uri
-uricopy
);
483 if (ParseIPvFuture(++uri
) && *uri
== wxT(']'))
486 m_hostType
= wxURI_IPVFUTURE
;
488 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
489 wxMemcpy(theBuffer
, uricopy
, uri
-uricopy
);
490 theBuffer
.SetLength(uri
-uricopy
);
498 if (ParseIPv4address(uri
))
500 m_hostType
= wxURI_IPV4ADDRESS
;
502 wxStringBufferLength
theBuffer(m_server
, uri
- uricopy
);
503 wxMemcpy(theBuffer
, uricopy
, uri
-uricopy
);
504 theBuffer
.SetLength(uri
-uricopy
);
510 if(m_hostType
== wxURI_REGNAME
)
513 // reg-name = *( unreserved / pct-encoded / sub-delims )
514 while(*uri
&& *uri
!= wxT('/') && *uri
!= wxT(':') && *uri
!= wxT('#') && *uri
!= wxT('?'))
516 if(IsUnreserved(*uri
) || IsEscape(uri
) || IsSubDelim(*uri
))
519 Escape(m_server
, *uri
++);
523 //mark the server as valid
524 m_fields
|= wxURI_SERVER
;
530 const wxChar
* wxURI::ParsePort(const wxChar
* uri
)
532 wxASSERT(uri
!= NULL
);
543 //mark the port as valid
544 m_fields
|= wxURI_PORT
;
550 const wxChar
* wxURI::ParsePath(const wxChar
* uri
, bool bReference
, bool bNormalize
)
552 wxASSERT(uri
!= NULL
);
554 //copy of the uri - used for figuring out
555 //length of each component
556 const wxChar
* uricopy
= uri
;
558 /// hier-part = "//" authority path-abempty
563 /// relative-part = "//" authority path-abempty
568 /// path-abempty = *( "/" segment )
569 /// path-absolute = "/" [ segment-nz *( "/" segment ) ]
570 /// path-noscheme = segment-nz-nc *( "/" segment )
571 /// path-rootless = segment-nz *( "/" segment )
572 /// path-empty = 0<pchar>
575 /// segment-nz = 1*pchar
576 /// segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
577 /// ; non-zero-length segment without any colon ":"
579 /// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
580 if (*uri
== wxT('/'))
584 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
586 if( IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
587 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
590 Escape(m_path
, *uri
++);
595 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
597 wxMemcpy(theBuffer
, m_path
.c_str(), m_path
.length()+1);
599 Normalize(theBuffer
, true);
600 theBuffer
.SetLength(wxStrlen(theBuffer
));
602 //mark the path as valid
603 m_fields
|= wxURI_PATH
;
605 else if(*uri
) //Relative path
610 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
612 if(IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
613 *uri
== wxT('@') || *uri
== wxT('/'))
616 Escape(m_path
, *uri
++);
621 while(*uri
&& *uri
!= wxT('#') && *uri
!= wxT('?'))
623 if(IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
624 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/'))
627 Escape(m_path
, *uri
++);
635 wxStringBufferLength
theBuffer(m_path
, m_path
.length() + 1);
637 wxMemcpy(theBuffer
, m_path
.c_str(), m_path
.length()+1);
639 Normalize(theBuffer
);
640 theBuffer
.SetLength(wxStrlen(theBuffer
));
643 //mark the path as valid
644 m_fields
|= wxURI_PATH
;
652 const wxChar
* wxURI::ParseQuery(const wxChar
* uri
)
654 wxASSERT(uri
!= NULL
);
656 // query = *( pchar / "/" / "?" )
657 if (*uri
== wxT('?'))
660 while(*uri
&& *uri
!= wxT('#'))
662 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
663 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
666 Escape(m_query
, *uri
++);
669 //mark the server as valid
670 m_fields
|= wxURI_QUERY
;
677 const wxChar
* wxURI::ParseFragment(const wxChar
* uri
)
679 wxASSERT(uri
!= NULL
);
681 // fragment = *( pchar / "/" / "?" )
682 if (*uri
== wxT('#'))
687 if (IsUnreserved(*uri
) || IsSubDelim(*uri
) || IsEscape(uri
) ||
688 *uri
== wxT(':') || *uri
== wxT('@') || *uri
== wxT('/') || *uri
== wxT('?'))
689 m_fragment
+= *uri
++;
691 Escape(m_fragment
, *uri
++);
694 //mark the server as valid
695 m_fields
|= wxURI_FRAGMENT
;
701 // ---------------------------------------------------------------------------
704 // Builds missing components of this uri from a base uri
706 // A version of the algorithm outlined in the RFC is used here
707 // (it is shown in comments)
709 // Note that an empty URI inherits all components
710 // ---------------------------------------------------------------------------
712 void wxURI::Resolve(const wxURI
& base
, int flags
)
714 wxASSERT_MSG(!base
.IsReference(),
715 wxT("wxURI to inherit from must not be a reference!"));
717 // If we arn't being strict, enable the older (pre-RFC2396)
718 // loophole that allows this uri to inherit other
719 // properties from the base uri - even if the scheme
721 if ( !(flags
& wxURI_STRICT
) &&
722 HasScheme() && base
.HasScheme() &&
723 m_scheme
== base
.m_scheme
)
725 m_fields
-= wxURI_SCHEME
;
729 // Do nothing if this is an absolute wxURI
730 // if defined(R.scheme) then
731 // T.scheme = R.scheme;
732 // T.authority = R.authority;
733 // T.path = remove_dot_segments(R.path);
734 // T.query = R.query;
741 m_scheme
= base
.m_scheme
;
742 m_fields
|= wxURI_SCHEME
;
744 // All we need to do for relative URIs with an
745 // authority component is just inherit the scheme
746 // if defined(R.authority) then
747 // T.authority = R.authority;
748 // T.path = remove_dot_segments(R.path);
749 // T.query = R.query;
755 //No authority - inherit
758 m_user
= base
.m_user
;
759 m_fields
|= wxURI_USER
;
762 m_server
= base
.m_server
;
763 m_hostType
= base
.m_hostType
;
764 m_fields
|= wxURI_SERVER
;
768 m_port
= base
.m_port
;
769 m_fields
|= wxURI_PORT
;
773 // Simple path inheritance from base
776 // T.path = Base.path;
777 m_path
= base
.m_path
;
778 m_fields
|= wxURI_PATH
;
781 // if defined(R.query) then
782 // T.query = R.query;
784 // T.query = Base.query;
788 m_query
= base
.m_query
;
789 m_fields
|= wxURI_QUERY
;
794 // if (R.path starts-with "/") then
795 // T.path = remove_dot_segments(R.path);
797 // T.path = merge(Base.path, R.path);
798 // T.path = remove_dot_segments(T.path);
800 // T.query = R.query;
801 if (m_path
[0u] != wxT('/'))
804 const wxChar
* op
= m_path
.c_str();
805 const wxChar
* bp
= base
.m_path
.c_str() + base
.m_path
.Length();
807 //not a ending directory? move up
808 if (base
.m_path
[0] && *(bp
-1) != wxT('/'))
809 UpTree(base
.m_path
, bp
);
811 //normalize directories
812 while(*op
== wxT('.') && *(op
+1) == wxT('.') &&
813 (*(op
+2) == '\0' || *(op
+2) == wxT('/')) )
815 UpTree(base
.m_path
, bp
);
823 m_path
= base
.m_path
.substr(0, bp
- base
.m_path
.c_str()) +
824 m_path
.substr((op
- m_path
.c_str()), m_path
.Length());
828 //T.fragment = R.fragment;
831 // ---------------------------------------------------------------------------
834 // Moves a URI path up a directory
835 // ---------------------------------------------------------------------------
838 void wxURI::UpTree(const wxChar
* uristart
, const wxChar
*& uri
)
840 if (uri
!= uristart
&& *(uri
-1) == wxT('/'))
845 for(;uri
!= uristart
; --uri
)
847 if (*uri
== wxT('/'))
855 if (uri
== uristart
&& *uri
== wxT('/'))
860 // ---------------------------------------------------------------------------
863 // Normalizes directories in-place
865 // I.E. ./ and . are ignored
867 // ../ and .. are removed if a directory is before it, along
868 // with that directory (leading .. and ../ are kept)
869 // ---------------------------------------------------------------------------
872 void wxURI::Normalize(wxChar
* s
, bool bIgnoreLeads
)
882 if (*cp
== wxT('.') && (*(cp
+1) == wxT('/') || *(cp
+1) == '\0')
883 && (bp
== cp
|| *(cp
-1) == wxT('/')))
891 else if (*cp
== wxT('.') && *(cp
+1) == wxT('.') &&
892 (*(cp
+2) == wxT('/') || *(cp
+2) == '\0')
893 && (bp
== cp
|| *(cp
-1) == wxT('/')))
895 //.. _or_ ../ - go up the tree
898 UpTree((const wxChar
*)bp
, (const wxChar
*&)s
);
905 else if (!bIgnoreLeads
)
930 // ---------------------------------------------------------------------------
933 // Parses 1 to 4 hex values. Returns true if the first character of the input
934 // string is a valid hex character. It is the caller's responsability to move
935 // the input string back to its original position on failure.
936 // ---------------------------------------------------------------------------
938 bool wxURI::ParseH16(const wxChar
*& uri
)
944 if(IsHex(*++uri
) && IsHex(*++uri
) && IsHex(*++uri
))
950 // ---------------------------------------------------------------------------
953 // Parses a certain version of an IP address and moves the input string past
954 // it. Returns true if the input string contains the proper version of an ip
955 // address. It is the caller's responsability to move the input string back
956 // to its original position on failure.
957 // ---------------------------------------------------------------------------
959 bool wxURI::ParseIPv4address(const wxChar
*& uri
)
961 //IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
963 //dec-octet = DIGIT ; 0-9
964 // / %x31-39 DIGIT ; 10-99
965 // / "1" 2DIGIT ; 100-199
966 // / "2" %x30-34 DIGIT ; 200-249
967 // / "25" %x30-35 ; 250-255
974 //each ip part must be between 0-255 (dupe of version in for loop)
975 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
976 //100 or less (note !)
977 !( (*(uri
-2) < wxT('2')) ||
979 (*(uri
-2) == wxT('2') &&
980 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
988 if(IsDigit(*uri
))++uri
;
990 //compilers should unroll this loop
991 for(; iIPv4
< 4; ++iIPv4
)
993 if (*uri
!= wxT('.') || !IsDigit(*++uri
))
996 //each ip part must be between 0-255
997 if( IsDigit(*++uri
) && IsDigit(*++uri
) &&
998 //100 or less (note !)
999 !( (*(uri
-2) < wxT('2')) ||
1001 (*(uri
-2) == wxT('2') &&
1002 (*(uri
-1) < wxT('5') || (*(uri
-1) == wxT('5') && *uri
<= wxT('5')))
1009 if(IsDigit(*uri
))++uri
;
1015 bool wxURI::ParseIPv6address(const wxChar
*& uri
)
1017 // IPv6address = 6( h16 ":" ) ls32
1018 // / "::" 5( h16 ":" ) ls32
1019 // / [ h16 ] "::" 4( h16 ":" ) ls32
1020 // / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
1021 // / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
1022 // / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
1023 // / [ *4( h16 ":" ) h16 ] "::" ls32
1024 // / [ *5( h16 ":" ) h16 ] "::" h16
1025 // / [ *6( h16 ":" ) h16 ] "::"
1027 size_t numPrefix
= 0,
1030 bool bEndHex
= false;
1032 for( ; numPrefix
< 6; ++numPrefix
)
1041 if(*uri
!= wxT(':'))
1047 if(!bEndHex
&& !ParseH16(uri
))
1054 if (*uri
== wxT(':'))
1056 if (*++uri
!= wxT(':'))
1066 if (*uri
!= wxT(':') || *(uri
+1) != wxT(':'))
1071 while (*--uri
!= wxT(':')) {}
1074 const wxChar
* uristart
= uri
;
1076 // ls32 = ( h16 ":" h16 ) / IPv4address
1077 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1082 if (ParseIPv4address(uri
))
1094 maxPostfix
= 4 - numPrefix
;
1098 bool bAllowAltEnding
= maxPostfix
== 0;
1100 for(; maxPostfix
!= 0; --maxPostfix
)
1102 if(!ParseH16(uri
) || *uri
!= wxT(':'))
1108 const wxChar
* uristart
= uri
;
1110 // ls32 = ( h16 ":" h16 ) / IPv4address
1111 if (ParseH16(uri
) && *uri
== wxT(':') && ParseH16(uri
))
1116 if (ParseIPv4address(uri
))
1121 if (!bAllowAltEnding
)
1125 if(numPrefix
<= 5 && ParseH16(uri
))
1131 bool wxURI::ParseIPvFuture(const wxChar
*& uri
)
1133 // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1134 if (*++uri
!= wxT('v') || !IsHex(*++uri
))
1137 while (IsHex(*++uri
)) {}
1139 if (*uri
!= wxT('.') || !(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')))
1142 while(IsUnreserved(*++uri
) || IsSubDelim(*uri
) || *uri
== wxT(':')) {}
1148 // ---------------------------------------------------------------------------
1151 // Converts a character into a numeric hexidecimal value, or 0 if the
1152 // passed in character is not a valid hex character
1153 // ---------------------------------------------------------------------------
1156 wxChar
wxURI::CharToHex(const wxChar
& c
)
1158 if ((c
>= wxT('A')) && (c
<= wxT('Z'))) return wxChar(c
- wxT('A') + 0x0A);
1159 if ((c
>= wxT('a')) && (c
<= wxT('z'))) return wxChar(c
- wxT('a') + 0x0a);
1160 if ((c
>= wxT('0')) && (c
<= wxT('9'))) return wxChar(c
- wxT('0') + 0x00);
1165 // ---------------------------------------------------------------------------
1168 // Returns true if the passed in character meets the criteria of the method
1169 // ---------------------------------------------------------------------------
1171 //! unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
1172 bool wxURI::IsUnreserved (const wxChar
& c
)
1173 { return IsAlpha(c
) || IsDigit(c
) ||
1177 c
== wxT('~') //tilde
1181 bool wxURI::IsReserved (const wxChar
& c
)
1183 return IsGenDelim(c
) || IsSubDelim(c
);
1186 //! gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
1187 bool wxURI::IsGenDelim (const wxChar
& c
)
1189 return c
== wxT(':') ||
1198 //! sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
1199 //! / "*" / "+" / "," / ";" / "="
1200 bool wxURI::IsSubDelim (const wxChar
& c
)
1202 return c
== wxT('!') ||
1216 bool wxURI::IsHex(const wxChar
& c
)
1217 { return IsDigit(c
) || (c
>= wxT('a') && c
<= wxT('f')) || (c
>= wxT('A') && c
<= wxT('F')); }
1219 bool wxURI::IsAlpha(const wxChar
& c
)
1220 { return (c
>= wxT('a') && c
<= wxT('z')) || (c
>= wxT('A') && c
<= wxT('Z')); }
1222 bool wxURI::IsDigit(const wxChar
& c
)
1223 { return c
>= wxT('0') && c
<= wxT('9'); }
1226 // ---------------------------------------------------------------------------
1228 // wxURL Compatability
1230 // ---------------------------------------------------------------------------
1234 #if WXWIN_COMPATIBILITY_2_4
1238 //Note that this old code really doesn't convert to a URI that well and looks
1239 //more like a dirty hack than anything else...
1241 wxString
wxURL::ConvertToValidURI(const wxString
& uri
, const wxChar
* delims
)
1247 for (i
= 0; i
< uri
.Len(); i
++)
1249 wxChar c
= uri
.GetChar(i
);
1253 // GRG, Apr/2000: changed to "%20" instead of '+'
1255 out_str
+= wxT("%20");
1259 // GRG, Apr/2000: modified according to the URI definition (RFC 2396)
1261 // - Alphanumeric characters are never escaped
1262 // - Unreserved marks are never escaped
1263 // - Delimiters must be escaped if they appear within a component
1264 // but not if they are used to separate components. Here we have
1265 // no clear way to distinguish between these two cases, so they
1266 // are escaped unless they are passed in the 'delims' parameter
1267 // (allowed delimiters).
1269 static const wxChar marks
[] = wxT("-_.!~*()'");
1271 if ( !wxIsalnum(c
) && !wxStrchr(marks
, c
) && !wxStrchr(delims
, c
) )
1273 hexa_code
.Printf(wxT("%%%02X"), c
);
1274 out_str
+= hexa_code
;
1286 wxString
wxURL::ConvertFromURI(const wxString
& uri
)
1288 return wxURI::Unescape(uri
);
1291 #endif //WXWIN_COMPATIBILITY_2_4