2010-03-05 Rodrigo Kumpera <rkumpera@novell.com>
[mcs.git] / class / WindowsBase / System.IO.Packaging / PackUriParser.cs
blobf60c5294071c35f19bfd45fa97c8634522d80e7d
1 // PackUriParser.cs created with MonoDevelop
2 // User: alan at 14:50 31/10/2008
3 //
4 // To change standard headers go to Edit->Preferences->Coding->Standard Headers
5 //
7 using System;
8 using System.Collections.Generic;
9 using System.Text;
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)
31 int start = 0;
32 int end = s.IndexOf(':');
33 builder.Append(s, start, end - start);
36 if ((components & UriComponents.Host) == UriComponents.Host)
38 // Skip past pack://
39 int start = 7;
40 int end = s.IndexOf('/', start);
41 if (end == -1)
42 end = s.Length;
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)
55 // Skip past pack://
56 int start = s.IndexOf('/', 7);
57 int end = s.IndexOf('?');
58 if (end == -1)
59 end = s.IndexOf('#');
60 if (end == -1)
61 end = s.Length;
63 if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter &&
64 builder.Length == 0)
65 start++;
67 builder.Append(s, start, end - start);
70 if ((components & UriComponents.Query) == UriComponents.Query)
72 int index = s.IndexOf('?');
73 if (index == -1)
74 return null;
76 if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter &&
77 builder.Length == 0)
78 index++;
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('#');
88 if (index == -1)
89 return null;
91 if ((components & UriComponents.KeepDelimiter) != UriComponents.KeepDelimiter &&
92 builder.Length == 0)
93 index++;
95 builder.Append(s, index, s.Length - index);
98 return builder.ToString();
101 protected override void InitializeAndValidate(Uri uri, out UriFormatException parsingError)
103 parsingError = null;
106 protected override UriParser OnNewUri()
108 return new PackUriParser();