//\r
// 2003 Atsushi Enomoto "No rights reserved."\r
//\r
+// Copyright (c) 2004 Novell Inc.\r
+// All rights reserved\r
+//\r
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
using System;\r
using System.Collections;\r
using System.IO;\r
\r
namespace Commons.Xml.Relaxng\r
{\r
- public class RngException : Exception\r
+ internal class Util\r
{\r
- string debugXml;\r
-\r
- public RngException () : base () {}\r
- public RngException (string message) : base (message) {}\r
- public RngException (string message, Exception innerException)\r
- : base (message, innerException) {}\r
- public RngException (string message, RdpPattern invalidatedPattern)\r
- : base (message)\r
+ /*\r
+ public static string ResolveUri (string baseUri, string href, XmlResolver resolver)\r
{\r
- debugXml = RdpUtil.DebugRdpPattern (invalidatedPattern, new Hashtable ());\r
+ Uri uri = null;\r
+ if (baseUri != null && baseUri.Length > 0)
+ uri = new Uri (baseUri);
+ Uri result = resolver.ResolveUri (uri, href);
+ if (result.Query.Length > 0 || result.Fragment.Length > 0)
+ throw new RelaxngException ("Invalid URI format: " + href);
+ return result.ToString ();
}\r
- }\r
+ */\r
\r
- public class Util\r
- {\r
- public static string ResolveUri (string baseUri, string href)\r
+ public static string NormalizeWhitespace (string s)\r
{\r
- lock (baseUri) {\r
- lock (href) {\r
- return resolveUri (baseUri, href);\r
+ if (s.Length == 0)\r
+ return s;\r
+\r
+ char [] ca = s.ToCharArray ();\r
+ int j = 0;\r
+ for (int i = 0; i < ca.Length; i++) {\r
+ switch (ca [i]) {\r
+ case ' ':\r
+ case '\r':\r
+ case '\t':\r
+ case '\n':\r
+ if (j == 0)\r
+ break;\r
+ if (ca [j - 1] != ' ')\r
+ ca [j++] = ' ';\r
+ break;\r
+ default:\r
+ ca [j++] = ca [i];\r
+ break;\r
}\r
}\r
+ if (j == 0)\r
+ return String.Empty;\r
+ string r = new string (ca, 0, (ca [j - 1] != ' ') ? j : j - 1);\r
+ return r;\r
}\r
\r
- private static string resolveUri (string baseUri, string href)\r
+ public static bool IsWhitespace (string s)\r
{\r
- // If baseUri does not exist, then it is only the way.\r
- if (baseUri == String.Empty)\r
- return href;\r
-\r
- // If href itself is a uri, then return it directly.\r
- try {\r
- return new Uri (href).AbsoluteUri;\r
- } catch (UriFormatException) {\r
- }\r
-\r
- // If baseUri is a valid uri, then make relative uri.\r
- try {\r
- return new Uri (\r
- new Uri (baseUri), href).AbsoluteUri;\r
- } catch (UriFormatException) {\r
+ for (int i = 0; i < s.Length; i++) {\r
+ switch (s [i]) {\r
+ case ' ':\r
+ case '\t':\r
+ case '\n':\r
+ case '\r':\r
+ continue;\r
+ default:\r
+ return false;\r
+ }\r
}\r
-\r
- // Otherwise, they might be filesystem path.\r
- if (Path.IsPathRooted (href))\r
- return href;\r
-\r
- return Path.Combine (\r
- Path.GetDirectoryName (baseUri), href);\r
+ return true;\r
}\r
}\r
-\r
}\r
\r