1 // PackUriParser.cs created with MonoDevelop
2 // User: alan at 14:50 31/10/2008
4 // To change standard headers go to Edit->Preferences->Coding->Standard Headers
8 using System
.Collections
.Generic
;
11 namespace System
.IO
.Packaging
13 class PackUriParser
: System
.GenericUriParser
15 const string SchemaName
= "pack";
17 StringBuilder builder
= new StringBuilder();
19 public PackUriParser ()
20 : base (GenericUriParserOptions
.Default
)
24 protected override string GetComponents(Uri uri
, UriComponents components
, UriFormat format
)
26 string s
= uri
.OriginalString
;
27 builder
.Remove(0, builder
.Length
);
29 if ((components
& UriComponents
.Scheme
) == UriComponents
.Scheme
)
32 int end
= s
.IndexOf(':');
33 builder
.Append(s
, start
, end
- start
);
36 if ((components
& UriComponents
.Host
) == UriComponents
.Host
)
40 int end
= s
.IndexOf('/', start
);
44 if (builder
.Length
> 0)
45 builder
.Append("://");
47 builder
.Append(s
, start
, end
- start
);
50 // Port is always -1, so i think i can ignore both Port and StrongPort
51 // Normally they'd get parsed here
53 if ((components
& UriComponents
.Path
) == UriComponents
.Path
)
56 int start
= s
.IndexOf('/', 7);
57 int end
= s
.IndexOf('?');
63 if ((components
& UriComponents
.KeepDelimiter
) != UriComponents
.KeepDelimiter
&&
67 builder
.Append(s
, start
, end
- start
);
70 if ((components
& UriComponents
.Query
) == UriComponents
.Query
)
72 int index
= s
.IndexOf('?');
76 if ((components
& UriComponents
.KeepDelimiter
) != UriComponents
.KeepDelimiter
&&
80 int fragIndex
= s
.IndexOf('#');
81 int end
= fragIndex
== -1 ? s
.Length
: fragIndex
;
82 builder
.Append(s
, index
, end
- index
);
85 if ((components
& UriComponents
.Fragment
) == UriComponents
.Fragment
)
87 int index
= s
.IndexOf('#');
91 if ((components
& UriComponents
.KeepDelimiter
) != UriComponents
.KeepDelimiter
&&
95 builder
.Append(s
, index
, s
.Length
- index
);
98 return builder
.ToString();
101 protected override void InitializeAndValidate(Uri uri
, out UriFormatException parsingError
)
106 protected override UriParser
OnNewUri()
108 return new PackUriParser();