2 // RelaxngDefaultDatatypes.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (c) 2004 Novell Inc.
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 namespace Commons.Xml.Relaxng
36 public class RelaxngString : RelaxngDatatype
38 static RelaxngString instance;
39 static RelaxngString ()
41 instance = new RelaxngString ();
44 internal static RelaxngString Instance {
45 get { return instance; }
48 public override string Name { get { return "string"; } }
49 public override string NamespaceURI { get { return String.Empty; } }
51 internal override bool IsContextDependent {
55 public override bool IsValid (string text, XmlReader reader)
60 public override object Parse (string text, XmlReader reader)
65 public override bool Compare (object o1, object o2)
67 return (string) o1 == (string) o2;
71 public class RelaxngToken : RelaxngDatatype
73 static RelaxngToken instance;
74 static RelaxngToken ()
76 instance = new RelaxngToken ();
79 internal static RelaxngToken Instance {
80 get { return instance; }
83 public override string Name { get { return "token"; } }
84 public override string NamespaceURI { get { return String.Empty; } }
86 internal override bool IsContextDependent {
90 public override bool IsValid (string text, XmlReader reader)
95 public override object Parse (string text, XmlReader reader)
97 return Util.NormalizeWhitespace (text);
100 int SkipWhitespaces (string s, int i)
102 while (i < s.Length) {
104 case '\n': case '\r': case ' ': case '\t':
113 public override bool Compare (object o1, object o2)
115 string s1 = o1 as string;
116 string s2 = o2 as string;
121 while (i1 < s1.Length && i2 < s2.Length) {
122 i1 = SkipWhitespaces (s1, i1);
123 i2 = SkipWhitespaces (s2, i2);
124 while (i1 < s1.Length && i2 < s2.Length) {
125 if (s1 [i1] != s2 [i2])
129 if (i1 == s1.Length || i2 == s2.Length)
131 if (XmlChar.IsWhitespace (s1 [i1])) {
132 if (!XmlChar.IsWhitespace (s2 [i2]))
137 else if (XmlChar.IsWhitespace (s2 [i2]))
141 i1 = SkipWhitespaces (s1, i1);
142 i2 = SkipWhitespaces (s2, i2);
143 return i1 == s1.Length && i2 == s2.Length;
146 public override bool CompareString (string s1, string s2, XmlReader reader)
148 return Compare (s1, s2);