コード例 #1
0
        private void WriteByteLiteral(Syntax.Bytes literal)
        {
            writer.Write("new");
            writer.Write(" ");
            writer.Write("byte[]");
            writer.Write(" { ");
            var s   = literal.s;
            var sep = "";

            for (int i = 0; i < s.Length; ++i)
            {
                writer.Write(sep);
                sep = ", ";
                if (s[i] == '\\')
                {
                    if (s[i + 1] == 'x')
                    {
                        writer.Write("0x{0}{1}", s[i + 2], s[i + 3]);
                        i += 3;
                    }
                    else if (s[i + 1] == '0')
                    {
                        writer.Write("\\0");
                        i += 1;
                    }
                    else if (s[i + 1] == '\\')
                    {
                        writer.Write("(byte)'\\\\'");
                        i += 1;
                    }
                    else if (s[i + 1] == 'n')
                    {
                        writer.Write("\\n");
                        i += 1;
                    }
                    else if (s[i + 1] == 't')
                    {
                        writer.Write("\\t");
                        i += 1;
                    }
                    else
                    {
                        writer.Write("\\{0}", s[i]);
                        i += 1;
                    }
                }
                else if (' ' <= s[i] && s[i] <= '~')
                {
                    writer.Write("(byte)'{0}'", s[i]);
                }
                else
                {
                    writer.Write("0x{0:X2}", (int)s[i]);
                }
            }
            writer.Write(" }");
        }
コード例 #2
0
        private void WriteByteLiteral(Syntax.Bytes literal)
        {
            writer.Write("new");
            writer.Write(" ");
            writer.Write("byte[]");
            writer.Write(" { ");
            var s   = literal.s;
            var sep = "";

            for (int i = 0; i < s.Length; ++i)
            {
                writer.Write(sep);
                sep = ", ";
                if (s[i] == '\\')
                {
                    if (s[i + 1] == 'x')
                    {
                        writer.Write("0x{0}{1}", s[i + 2], s[i + 3]);
                        i += 3;
                    }
                    else if (s[i + 1] == '0')
                    {
                        writer.Write("\\0");
                        i += 1;
                    }
                    else if (s[i + 1] == '\\')
                    {
                        writer.Write("(byte)'\\\\'");
                        i += 1;
                    }
                    else
                    {
                        throw new NotImplementedException(string.Format("Not implemented {0}{1}", s[i], s[i + 1]));
                    }
                }
                else if (' ' <= s[i] && s[i] <= '~')
                {
                    writer.Write("(byte)'{0}'", s[i]);
                }
                else
                {
                    writer.Write("0x{0:X2}", (int)s[i]);
                }
            }
            writer.Write(" }");
        }