Example #1
0
        public CodeFormatter VisitString(StringType str)
        {
            var offset = rdr.Offset;
            var s      = rdr.ReadCString(str.ElementType, program.TextEncoding);
            var fmt    = codeFormatter.InnerFormatter;

            //$TODO: appropriate prefix for UTF16-encoded strings.
            fmt.Write('"');
            foreach (var ch in s.ToString())
            {
                if (Char.IsControl(ch))
                {
                    fmt.Write("\\x{0:X2}", (int)ch);
                }
                else
                {
                    if (ch == '\\' || ch == '"')
                    {
                        fmt.Write(ch);
                    }
                    fmt.Write(ch);
                }
            }
            fmt.Write('"');
            if (str.Length > 0)
            {
                rdr.Offset = offset + str.Length * str.ElementType.Size;
            }
            return(codeFormatter);
        }
Example #2
0
        public CodeFormatter VisitString(StringType str)
        {
            var offset = rdr.Offset;
            var s      = rdr.ReadCString(str.ElementType, program.TextEncoding);

            //$TODO: appropriate prefix for UTF16-encoded strings.
            codeFormatter.VisitConstant(s);
            if (str.Length > 0)
            {
                rdr.Offset = offset + str.Length * str.ElementType.Size;
            }
            return(codeFormatter);
        }