static bool CheckUnderscore(string id, UnderscoreHandling handling) { for (int i = 1; i < id.Length; i++) { char ch = id[i]; if (ch == '_' && !HandleUnderscore(handling, id, ref i)) { return(false); } } return(true); }
static bool HandleUnderscore(UnderscoreHandling handling, string id, ref int i) { switch (handling) { case UnderscoreHandling.Forbid: if (i + 1 < id.Length) { char ch = id[i + 1]; if (char.IsDigit(ch)) { i++; return(true); } } return(false); case UnderscoreHandling.Allow: return(true); case UnderscoreHandling.AllowWithLowerStartingLetter: if (i + 1 < id.Length) { char ch = id[i + 1]; if (char.IsLetter(ch) && !char.IsLower(ch) || ch == '_') { return(false); } i++; } return(true); case UnderscoreHandling.AllowWithUpperStartingLetter: if (i + 1 < id.Length) { char ch = id[i + 1]; if (char.IsLetter(ch) && !char.IsUpper(ch) || ch == '_') { return(false); } i++; } return(true); default: throw new ArgumentOutOfRangeException(); } }
static bool HandleUnderscore(UnderscoreHandling handling, string id, ref int i) { switch (handling) { case UnderscoreHandling.Forbid: if (i + 1 < id.Length) { char ch = id [i + 1]; if (char.IsDigit(ch)) { i++; return true; } } return false; case UnderscoreHandling.Allow: return true; case UnderscoreHandling.AllowWithLowerStartingLetter: if (i + 1 < id.Length) { char ch = id [i + 1]; if (char.IsLetter(ch) && !char.IsLower(ch) || ch =='_') return false; i++; } return true; case UnderscoreHandling.AllowWithUpperStartingLetter: if (i + 1 < id.Length) { char ch = id [i + 1]; if (char.IsLetter(ch) && !char.IsUpper(ch) || ch =='_') return false; i++; } return true; default: throw new ArgumentOutOfRangeException(); } }
static bool CheckUnderscore(string id, UnderscoreHandling handling) { for (int i = 1; i < id.Length; i++) { char ch = id [i]; if (ch == '_' && !HandleUnderscore(handling, id, ref i)) return false; } return true; }