[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System Uri.cs,1.34,1.35
From: |
Gopal.V <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System Uri.cs,1.34,1.35 |
Date: |
Sat, 24 May 2003 00:26:55 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System
In directory subversions:/tmp/cvs-serv32725/System
Modified Files:
Uri.cs
Log Message:
System.Uri Canonicalize() update
Index: Uri.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System/Uri.cs,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -r1.34 -r1.35
*** Uri.cs 23 May 2003 12:01:15 -0000 1.34
--- Uri.cs 24 May 2003 04:26:53 -0000 1.35
***************
*** 64,68 ****
/* State specific fields */
- private String absoluteUri = null;
private bool userEscaped = false
;
private UriHostNameType hostNameType =
UriHostNameType.Unknown;
--- 64,67 ----
***************
*** 72,75 ****
--- 71,75 ----
private String host = null;
private int port
= -1;
+ private String portString = null;
private String path = null;
private String query = null;
***************
*** 174,222 ****
{
userEscaped = dontEscape;
! this.absoluteUri = uriString;
! ParseString(uriString);
Escape();
Canonicalize();
}
! public Uri(Uri baseUri, String relativeUri) :
! this(baseUri, relativeUri, false)
{
}
! public Uri(Uri baseUri, String relativeUri, bool dontEscape)
{
}
! /* This method is to be re-written */
! protected virtual void Canonicalize()
{
! // TODO: Implement completely to remove default ports
! this.path = this.path.Replace('\\', '/');
! while (this.path.IndexOf("//") >= 0) // double-slashes to strip
{
! this.path = this.path.Replace("//", "/");
}
! // find out if .. dirs are present
! if (path.IndexOf("/../") > -1 || path.EndsWith("/..")
! || path.IndexOf("/./") > -1 || path.EndsWith("/."))
{
! path = StripMetaDirectories(path);
}
! // remove the slash at the end, unless it's alone
! int psize = path.Length; // efficiency
! if (psize > 1)
{
! if (path[psize-1] == '/')
! path = path.Substring(0, psize-1);
}
- else
- path = "/";
}
! /* This method is to be re-written */
! private static String StripMetaDirectories(String oldpath)
{
int toBeRemoved = 0;
--- 174,257 ----
{
userEscaped = dontEscape;
! ParseString(uriString,true);
Escape();
Canonicalize();
}
! private Uri()
{
+ /* Be warned , using this is kinda ugly in the end */
}
! public Uri(Uri baseUri, String relativeUri) :
! this(baseUri, relativeUri, false)
{
}
! public Uri(Uri baseUri, String relativeUri, bool dontEscape)
{
!
! if(relativeUri == null)
{
! throw new ArgumentNullException("relativeUri");
! }
!
! userEscaped = dontEscape;
! this.scheme = baseUri.scheme;
! this.delim = baseUri.delim;
! this.host = baseUri.host;
! this.port = baseUri.port;
! this.userinfo = baseUri.userinfo;
!
! if(relativeUri == String.Empty)
! {
! this.path = baseUri.path;
! this.query = baseUri.query;
! this.fragment = baseUri.fragment;
! return;
}
+
+ Uri uri=new Uri();
! uri.ParseString(relativeUri,false);
!
! if(uri.scheme == null)
{
! this.path = this.path + uri.path;
! this.query = uri.query;
! this.fragment = uri.fragment;
! }
! else if(uri.scheme == this.scheme && uri.delim == ":")
! {
! this.path = this.path + uri.Authority + uri.path;
! this.query = uri.query;
! this.fragment = uri.fragment;
! }
! else if(uri.scheme == this.scheme && uri.delim == "://")
! {
! ParseString(relativeUri,true);
! }
! else if(uri.scheme != this.scheme)
! {
! ParseString(relativeUri,true);
}
+ Escape();
+ Canonicalize();
+ }
! protected virtual void Canonicalize()
! {
! if(this.path!=null)
{
! this.path = this.path.Replace('\\', '/');
! while (this.path.IndexOf("//") >= 0) // double-slashes
to strip
! {
! this.path = this.path.Replace("//", "/");
! }
! path = StripMetaDirectories(path);
}
}
! private String StripMetaDirectories(String oldpath)
{
int toBeRemoved = 0;
***************
*** 228,240 ****
if (dirs[curDir] == "..")
{
! ++toBeRemoved;
! // removed w/o affecting toBeRemoved
dirs[curDir] = null;
}
else if (dirs[curDir] == ".")
! dirs[curDir] = null; // doesn't affect anything
else if (toBeRemoved > 0) // remove this one
{
! --toBeRemoved;
dirs[curDir] = null;
}
--- 263,276 ----
if (dirs[curDir] == "..")
{
! toBeRemoved++;
dirs[curDir] = null;
}
else if (dirs[curDir] == ".")
! {
! dirs[curDir] = null;
! }
else if (toBeRemoved > 0) // remove this one
{
! toBeRemoved--;
dirs[curDir] = null;
}
***************
*** 260,269 ****
// we always must have at least a slash
! // special case: if the last one is "invisible", add
! // a slash, because it is the directory mark of the
! // previous item
! if (newpath.Length == 0 || dirs[dirs.Length-1].Length == 0)
{
! newpath.Append('/');
}
return newpath.ToString();
--- 296,307 ----
// we always must have at least a slash
! // general assumption that path based systems use "://" instead
! // of the ":" only delimiter
! if (delim=="://")
{
! if(newpath.Length == 0)
! {
! newpath.Append('/');
! }
}
return newpath.ToString();
***************
*** 277,281 ****
for(int i=1; i< tok.Length ; i++)
{
! if(!Char.IsLetterOrDigit(tok[i]) && tok[i]!='-')
{
return false;
--- 315,319 ----
for(int i=1; i< tok.Length ; i++)
{
! if(!Char.IsLetterOrDigit(tok[i]) && tok[i]!='-'
&& tok[i]!='_')
{
return false;
***************
*** 355,362 ****
}
- [TODO]
public override bool Equals(Object comparand)
{
! throw new NotImplementedException("Equals");
}
--- 393,422 ----
}
public override bool Equals(Object comparand)
{
! if(comparand == null)
! {
! return false;
! }
! Uri uri = (comparand as Uri);
! if(uri == null)
! {
! String s = (comparand as String);
!
! if(s==null) return false;
! try
! {
! uri = new Uri(s);
! }
! catch
! {
! return false;
! }
! }
! return
! ((this.Authority == uri.Authority) &&
! (this.path == uri.path) &&
! (this.scheme == uri.scheme) &&
! (this.delim == uri.delim));
}
***************
*** 365,369 ****
if(!userEscaped)
{
! if(this.host==null)
{
this.host = EscapeStringInternal(this.host,
true, false);
--- 425,429 ----
if(!userEscaped)
{
! if(this.host!=null)
{
this.host = EscapeStringInternal(this.host,
true, false);
***************
*** 548,552 ****
}
! protected void ParseString(String uriString)
{
if(hasFastRegex)
--- 608,612 ----
}
! protected void ParseString(String uriString,bool reportErrors)
{
if(hasFastRegex)
***************
*** 558,561 ****
--- 618,657 ----
SlowParse(uriString);
}
+ if(reportErrors)
+ {
+ CheckParsed();
+ }
+ }
+
+ private void CheckParsed()
+ {
+ if(hostNameType==UriHostNameType.Unknown)
+ {
+ throw new UriFormatException(S._("Arg_UriHostName"));
+ }
+ if(!CheckSchemeName(this.scheme))
+ {
+ throw new UriFormatException(S._("Arg_InvalidScheme"));
+ }
+ if(portString!= null)
+ {
+ try
+ {
+ int value=Int32.Parse(portString);
+ port = value;
+ }
+ catch(FormatException)
+ {
+ this.port = -1;
+ }
+ catch(OverflowException)
+ {
+ throw new UriFormatException
(S._("Arg_UriPort"));
+ }
+ }
+ else
+ {
+ this.port = DefaultPortForScheme(this.scheme);
+ }
}
***************
*** 591,627 ****
13 --> fragment */
this.scheme = MatchToString(uriString, matches,2);
- if(!CheckSchemeName(this.scheme))
- {
- throw new UriFormatException(S._("Arg_InvalidScheme"));
- }
this.delim = ":"+MatchToString(uriString, matches, 4);
this.userinfo = MatchToString(uriString, matches, 6);
this.host = MatchToString(uriString, matches,7);
this.hostNameType = CheckHostName(this.host);
! if(hostNameType==UriHostNameType.Unknown)
! {
! throw new UriFormatException(S._("Arg_UriHostName"));
! }
! tmp = MatchToString(uriString, matches,9);
! if(tmp!= null)
! {
! try
! {
! int value=Int32.Parse(tmp);
! port = value;
! }
! catch(FormatException)
! {
! this.port = -1;
! }
! catch(OverflowException)
! {
! throw new UriFormatException
(S._("Arg_UriPort"));
! }
! }
! else
! {
! this.port = -1 ;
! }
this.path = MatchToString(uriString, matches, 10);
this.query = MatchToString(uriString, matches, 11);
--- 687,695 ----
13 --> fragment */
this.scheme = MatchToString(uriString, matches,2);
this.delim = ":"+MatchToString(uriString, matches, 4);
this.userinfo = MatchToString(uriString, matches, 6);
this.host = MatchToString(uriString, matches,7);
this.hostNameType = CheckHostName(this.host);
! this.portString = MatchToString(uriString, matches,9);
this.path = MatchToString(uriString, matches, 10);
this.query = MatchToString(uriString, matches, 11);
***************
*** 631,639 ****
private void SlowParse(String uriString)
{
}
public override String ToString()
{
! StringBuilder sb = new StringBuilder(absoluteUri.Length);
sb.Append(this.scheme);
--- 699,708 ----
private void SlowParse(String uriString)
{
+ throw new NotImplementedException("SlowParse");
}
public override String ToString()
{
! StringBuilder sb = new StringBuilder();
sb.Append(this.scheme);
***************
*** 675,679 ****
get
{
! return absoluteUri;
}
}
--- 744,748 ----
get
{
! return this.ToString();
}
}
***************
*** 693,697 ****
sb.Append(this.host);
}
! if(this.port!=-1)
{
sb.Append(':');
--- 762,766 ----
sb.Append(this.host);
}
! if(this.port!=-1 &&
this.port!=DefaultPortForScheme(this.scheme))
{
sb.Append(':');
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System Uri.cs,1.34,1.35,
Gopal.V <address@hidden> <=