private static void Add_S(MatchState ms, StringBuilder b, int s, int e) { string news = ms.Lua.ToString(3); for (int i = 0; i < news.Length; i++) { if (news[i] != L_ESC) { b.Append(news[i]); } else { i++; /* skip ESC */ if (!Char.IsDigit((news[i]))) { b.Append(news[i]); } else if (news[i] == '0') { b.Append(ms.Src.Substring(s, (e - s))); } else { PushOneCapture(ms, news[i] - '1', s, e); b.Append(ms.Lua.ToString(-1)); /* add capture to accumulated result */ } } } }
private static void AddQuoted(ILuaState lua, StringBuilder sb, int arg) { var s = lua.L_CheckString(arg); sb.Append('"'); for (var i = 0; i < s.Length; ++i) { var c = s[i]; if (c == '"' || c == '\\' || c == '\n') { sb.Append('\\').Append(c); } else if (c == '\0' || Char.IsControl(c)) { if (i + 1 >= s.Length || !Char.IsDigit(s[i + 1])) { sb.AppendFormat("\\{0:D}", (int)c); } else { sb.AppendFormat("\\{0:D3}", (int)c); } } else { sb.Append(c); } } sb.Append('"'); }
private static bool MatchClass(char c, char cl) { bool res; switch (cl) { case 'a': res = Char.IsLetter(c); break; case 'c': res = Char.IsControl(c); break; case 'd': res = Char.IsDigit(c); break; case 'g': throw new System.NotImplementedException(); case 'l': res = Char.IsLower(c); break; case 'p': res = Char.IsPunctuation(c); break; case 's': res = Char.IsWhiteSpace(c); break; case 'u': res = Char.IsUpper(c); break; case 'w': res = Char.IsLetterOrDigit(c); break; case 'x': res = IsXDigit(c); break; case 'z': res = (c == '\0'); break; /* deprecated option */ default: return(cl == c); } return(res); }
private static int ScanFormat(ILuaState lua, string format, int s, out string form) { int p = s; // skip flags while (p < format.Length && format[p] != '\0' && FLAGS.IndexOf(format[p]) != -1) { p++; } if (p - s > FLAGS.Length) { lua.L_Error("invalid format (repeat flags)"); } if (Char.IsDigit(format[p])) { p++; // skip width } if (Char.IsDigit(format[p])) { p++; // (2 digits at most) } if (format[p] == '.') { p++; if (Char.IsDigit(format[p])) { p++; // skip precision } if (Char.IsDigit(format[p])) { p++; // (2 digits at most) } } if (Char.IsDigit(format[p])) { lua.L_Error("invalid format (width of precision too long)"); } form = "%" + format.Substring(s, (p - s + 1)); return(p); }
public static int B_ToNumber(ILuaState lua) { LuaType t = lua.Type(2); if (t == LuaType.LUA_TNONE || t == LuaType.LUA_TNIL) // standard conversion { bool isnum; double n = lua.ToNumberX(1, out isnum); if (isnum) { lua.PushNumber(n); return(1); } // else not a number; must be something lua.L_CheckAny(1); } else { string s = lua.L_CheckString(1); int numBase = lua.L_CheckInteger(2); bool negative = false; lua.L_ArgCheck((2 <= numBase && numBase <= 36), 2, "base out of range"); s = s.Trim(' ', '\f', '\n', '\r', '\t', '\v'); s = s + '\0'; // guard int pos = 0; if (s[pos] == '-') { pos++; negative = true; } else if (s[pos] == '+') { pos++; } if (Char.IsLetterOrDigit(s, pos)) { double n = 0.0; do { int digit; if (Char.IsDigit(s, pos)) { digit = Int32.Parse(s[pos].ToString()); } else { digit = Char.ToUpper(s[pos]) - 'A' + 10; } if (digit >= numBase) { break; // invalid numeral; force a fail } n = n * (double)numBase + (double)digit; pos++; } while(Char.IsLetterOrDigit(s, pos)); if (pos == s.Length - 1) // except guard, no invalid trailing characters? { lua.PushNumber(negative ? -n : n); return(1); } // else not a number } // else not a number } lua.PushNil(); // not a number return(1); }
public bool Execute(char current) { return(!(Ctype.IsLetter(current) || Ctype.IsDigit(current) || current == '_')); }