public static string LexCsharpUnicodeVariableLenCharEscape(LexReader reader) { string sequence = reader.ConsumeStringWhile(IsHexadecimalDigit, 4); if (sequence.Length == 0) { throw new LexException(reader.GetPosition(), "Unicode escape sequence is too short (requires at least one hex digit)."); } return(((char)int.Parse(sequence, NumberStyles.HexNumber)).ToString()); }
public static string Lex0xHexInteger(LexReader reader) { if (!reader.ContinuesWith("0x") && !reader.ContinuesWith("0X")) return null; reader.Consume(2); string result = reader.ConsumeStringWhile(IsHexadecimalDigit); if (result.Length == 0) throw new LexException(reader.GetPosition(-2), "Hexadecimal integers starting with the \"0x\" prefix must have at least one hex digit."); return (result.Length == 0) ? null : result; }
public static string Lex0xHexInteger(LexReader reader) { if (!reader.ContinuesWith("0x") && !reader.ContinuesWith("0X")) { return(null); } reader.Consume(2); string result = reader.ConsumeStringWhile(IsHexadecimalDigit); if (result.Length == 0) { throw new LexException(reader.GetPosition(-2), "Hexadecimal integers starting with the \"0x\" prefix must have at least one hex digit."); } return((result.Length == 0) ? null : result); }
public static string LexCsharpUnicodeFixedLenCharEscape(LexReader reader, bool islong) { string numberOfChars = islong ? "eight" : "four"; int numChars = islong ? 8 : 4; string sequence = reader.ConsumeStringWhile(IsHexadecimalDigit, numChars); if (sequence.Length < numChars) { throw new LexException(reader.GetPosition(), "Unicode escape sequence is too short (requires {0} hex digits).".Fmt(numberOfChars)); } if (islong) { return(char.ConvertFromUtf32(int.Parse(sequence, NumberStyles.HexNumber))); } else { return(new string((char)int.Parse(sequence, NumberStyles.HexNumber), 1)); } }
public static string LexDecimalInteger(LexReader reader) { string result = reader.ConsumeStringWhile(IsDecimalDigit); return((result.Length == 0) ? null : result); }
public static string LexDecimalInteger(LexReader reader) { string result = reader.ConsumeStringWhile(IsDecimalDigit); return (result.Length == 0) ? null : result; }
public static string LexCsharpUnicodeVariableLenCharEscape(LexReader reader) { string sequence = reader.ConsumeStringWhile(IsHexadecimalDigit, 4); if (sequence.Length == 0) throw new LexException(reader.GetPosition(), "Unicode escape sequence is too short (requires at least one hex digit)."); return ((char) int.Parse(sequence, NumberStyles.HexNumber)).ToString(); }
public static string LexCsharpUnicodeFixedLenCharEscape(LexReader reader, bool islong) { string numberOfChars = islong ? "eight" : "four"; int numChars = islong ? 8 : 4; string sequence = reader.ConsumeStringWhile(IsHexadecimalDigit, numChars); if (sequence.Length < numChars) throw new LexException(reader.GetPosition(), "Unicode escape sequence is too short (requires {0} hex digits).".Fmt(numberOfChars)); if (islong) return char.ConvertFromUtf32(int.Parse(sequence, NumberStyles.HexNumber)); else return new string((char) int.Parse(sequence, NumberStyles.HexNumber), 1); }