コード例 #1
0
        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());
        }
コード例 #2
0
ファイル: LexUtil.cs プロジェクト: RT-Projects/RT.Util
 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;
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        public static string LexDecimalInteger(LexReader reader)
        {
            string result = reader.ConsumeStringWhile(IsDecimalDigit);

            return((result.Length == 0) ? null : result);
        }
コード例 #6
0
ファイル: LexUtil.cs プロジェクト: RT-Projects/RT.Util
 public static string LexDecimalInteger(LexReader reader)
 {
     string result = reader.ConsumeStringWhile(IsDecimalDigit);
     return (result.Length == 0) ? null : result;
 }
コード例 #7
0
ファイル: LexUtil.cs プロジェクト: RT-Projects/RT.Util
 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();
 }
コード例 #8
0
ファイル: LexUtil.cs プロジェクト: RT-Projects/RT.Util
 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);
 }