using System; using System.Diagnostics; using System.Globalization; public class Babel { /* ::= ( | )* ::= [{Lu}{Ll}{Lt}{Lm}{Lo}{Nl}] ::= [{Mn}{Mc}{Nd}{Pc}{Cf}] ref. http://www.unicode.org/unicode/reports/tr15/tr15-18.html */ private bool IsLegalIdentifierStart(char c) { UnicodeCategory cat = char.GetUnicodeCategory(c); return ((cat == UnicodeCategory.UppercaseLetter) || (cat == UnicodeCategory.LowercaseLetter) || (cat == UnicodeCategory.TitlecaseLetter) || (cat == UnicodeCategory.ModifierLetter) || (cat == UnicodeCategory.OtherLetter) || (cat == UnicodeCategory.LetterNumber)); } private bool IsLegalIdentifierExtend(char c) { UnicodeCategory cat = char.GetUnicodeCategory(c); return (IsLegalIdentifierStart(c) || (cat == UnicodeCategory.NonSpacingMark) || (cat == UnicodeCategory.SpacingCombiningMark) || (cat == UnicodeCategory.DecimalDigitNumber) || (cat == UnicodeCategory.ConnectorPunctuation) || (cat == UnicodeCategory.Format)); } private bool IsLegalIdentifier(string name) { if ((name == null) || (name.Length == 0)) return false; if (!IsLegalIdentifierStart(name[0])) return false; for (int i=1; i