stub out things to get the beatles xbox site up and running
[moon.git] / class / System.Windows / System.Windows.Markup / XmlLanguage.cs
blobe0b49b11c3b6dd57a0c89d46abaff86fdfcff837
1 //
2 // System.Windows.Markup.XmlLanguage.cs
3 //
4 // Contact:
5 // Moonlight List (moonlight-list@lists.ximian.com)
6 //
7 // Copyright (C) 2008, 2009 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using Mono;
30 using System;
31 using System.Globalization;
32 using System.Windows;
33 using System.Windows.Media;
35 namespace System.Windows.Markup {
36 public sealed class XmlLanguage {
37 string lang;
39 internal XmlLanguage (string ietfLanguageTag)
41 lang = ietfLanguageTag.ToLower (CultureInfo.InvariantCulture);
44 public static XmlLanguage GetLanguage (string ietfLanguageTag)
46 char c;
47 int i;
49 if (ietfLanguageTag == null)
50 throw new NullReferenceException ("ietfLanguageTag");
52 // verify language code is all us-ascii alphabetic
53 for (i = 0; i < ietfLanguageTag.Length; i++) {
54 if (ietfLanguageTag[i] == '-')
55 break;
57 c = Char.ToLower (ietfLanguageTag[i]);
59 if (c < 'a' || c > 'z')
60 throw new ArgumentException ("ietfLanguageTag");
63 // language code needs at least 2 characters (if non-empty)
64 if (i > 0 && i < 2)
65 throw new ArgumentException ("ietfLanguageTag");
67 if (i < ietfLanguageTag.Length) {
68 i++;
70 // country code needs at least 2 characters
71 if ((ietfLanguageTag.Length - i) < 2)
72 throw new ArgumentException ("ietfLanguageTag");
74 // verify country code is all us-ascii alpha-numeric
75 for ( ; i < ietfLanguageTag.Length; i++) {
76 c = Char.ToLower (ietfLanguageTag[i]);
78 if (!(c >= 'a' && c <= 'z') && !(c >= '0' && c <= '9'))
79 throw new ArgumentException ("ietfLanguageTag");
83 return new XmlLanguage (ietfLanguageTag);
86 public string IetfLanguageTag {
87 get { return lang; }
90 public override bool Equals (object obj)
92 XmlLanguage lang = obj as XmlLanguage;
94 if (lang == null)
95 return false;
97 return IetfLanguageTag.Equals (lang.IetfLanguageTag);
100 public override int GetHashCode ()
102 return IetfLanguageTag.GetHashCode ();
105 public static bool operator ==(XmlLanguage xmlLanguage1, XmlLanguage xmlLanguage2)
107 if ( object.ReferenceEquals(xmlLanguage1, null)
108 || object.ReferenceEquals(xmlLanguage2, null) )
109 return false;
111 return xmlLanguage1.IetfLanguageTag == xmlLanguage2.IetfLanguageTag;
114 public static bool operator !=(XmlLanguage xmlLanguage1, XmlLanguage xmlLanguage2)
116 return !(xmlLanguage1 == xmlLanguage2);