2 // Commons.Xml.Relaxng.General.cs
\r
5 // Atsushi Enomoto <ginga@kit.hi-ho.ne.jp>
\r
7 // 2003 Atsushi Enomoto "No rights reserved."
\r
10 using System.Collections;
\r
13 using Commons.Xml.Relaxng.Derivative;
\r
15 namespace Commons.Xml.Relaxng
\r
19 public static string ResolveUri (string baseUri, string href)
\r
23 if (baseUri != null && baseUri.Length > 0)
24 uri = new Uri (baseUri);
25 Uri result = new XmlUrlResolver ().ResolveUri (uri, href);
26 if (result.Query.Length > 0 || result.Fragment.Length > 0)
27 throw new RelaxngException ("Invalid URI format: " + href);
28 return result.ToString ();
30 // If baseUri does not exist, then it is only the way.
\r
31 if (baseUri == String.Empty)
\r
34 // If href itself is a uri, then return it directly.
\r
36 return new Uri (href).ToString ();
\r
37 } catch (UriFormatException) {
\r
40 // If baseUri is a valid uri, then make relative uri.
\r
43 new Uri (baseUri), href).ToString ();
\r
44 } catch (UriFormatException) {
\r
47 // Otherwise, they might be filesystem path.
\r
48 if (Path.IsPathRooted (href))
\r
51 return Path.Combine (
\r
52 Path.GetDirectoryName (baseUri), href);
\r
56 public static string NormalizeWhitespace (string s)
\r
61 char [] ca = s.ToCharArray ();
\r
63 for (int i = 0; i < ca.Length; i++) {
\r
71 if (ca [j - 1] != ' ')
\r
80 return String.Empty;
\r
81 string r = new string (ca, 0, (ca [j - 1] != ' ') ? j : j - 1);
\r
85 public static bool IsWhitespace (string s)
\r
87 for (int i = 0; i < s.Length; i++) {
\r