another bunch of implementation.
[mono.git] / mcs / class / System.Xaml / System.Xaml / XamlLanguage.cs
index 3f80a184593c6e31cd971b449e6f5f975a6f55b0..535f582fa77b36ec6a96ef7b2a2af9904c74a2d0 100644 (file)
@@ -23,6 +23,7 @@
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.Globalization;
 using System.Reflection;
 using System.Xaml;
 using System.Windows.Markup;
@@ -181,5 +182,38 @@ namespace System.Xaml.Schema
                public static IList<string> XmlNamespaces {
                        get { throw new NotImplementedException (); }
                }
+
+               internal static bool IsValidXamlName (string name)
+               {
+                       if (string.IsNullOrEmpty (name))
+                               return false;
+                       if (!IsValidXamlName (name [0], true))
+                               return false;
+                       foreach (char c in name)
+                               if (!IsValidXamlName (c, false))
+                                       return false;
+                       return true;
+               }
+
+               static bool IsValidXamlName (char c, bool first)
+               {
+                       if (c == '_')
+                               return true;
+                       switch (char.GetUnicodeCategory (c)) {
+                       case UnicodeCategory.LowercaseLetter:
+                       case UnicodeCategory.UppercaseLetter:
+                       case UnicodeCategory.TitlecaseLetter:
+                       case UnicodeCategory.OtherLetter:
+                       case UnicodeCategory.LetterNumber:
+                               return true;
+                       case UnicodeCategory.NonSpacingMark:
+                       case UnicodeCategory.DecimalDigitNumber:
+                       case UnicodeCategory.SpacingCombiningMark:
+                       case UnicodeCategory.ModifierLetter:
+                               return !first;
+                       default:
+                               return false;
+                       }
+               }
        }
 }