Exemple #1
0
        private void Inspect2_Unicode()
        {
            const char sq = '\'';

            // \u{12345} in UTF-8:
            var utf8 = new byte[] { 0xF0, 0x92, 0x8D, 0x85 };
            // \u{12345} in UTF-16: U+d808 U+df45
            var utf16 = Encoding.UTF8.GetString(utf8, 0, utf8.Length);

            string s;

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.Binary), false, sq).ToString();
            Assert(s == @"'\xF0\x92\x8D\x85'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.Binary), true, sq).ToString();
            Assert(s == @"'\xF0\x92\x8D\x85'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.UTF8), false, sq).ToString();
            Assert(s == @"'\u{12345}'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.UTF8), true, sq).ToString();
            Assert(s == @"'\u{12345}'");

            // incomplete character:
            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.Create("\ud808\udf45\ud808", RubyEncoding.UTF8), false, sq).ToString();
            Assert(s == @"'\u{12345}\u{d808}'");
        }
Exemple #2
0
        private void Inspect1()
        {
            const char sq = '\'';

            var sjisEncoding = RubyEncoding.KCodeSJIS.StrictEncoding;
            // あ
            var sjisWide = new byte[] { 0x82, 0xa0 };
            // \u{12345} in UTF-8:
            var utf8 = new byte[] { 0xF0, 0x92, 0x8D, 0x85 };
            // surrogates: U+d808 U+df45
            var utf16 = Encoding.UTF8.GetString(utf8);

            string s;

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.Binary), Context, false, sq).ToString();
            Assert(s == @"'\360\222\215\205'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.Binary), Context, true, sq).ToString();
            Assert(s == @"'\360\222\215\205'");

            Context.KCode = RubyEncoding.KCodeUTF8;
            s             = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.KCodeUTF8), Context, false, sq).ToString();
            Assert(s == "'" + utf16 + "'");

            // incomplete character:
            Context.KCode = RubyEncoding.KCodeUTF8;
            s             = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(new byte[] { 0xF0, 0x92 }, RubyEncoding.KCodeUTF8), Context, false, sq).ToString();
            Assert(s == @"'\360\222'");

            Context.KCode = RubyEncoding.KCodeUTF8;
            s             = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.KCodeSJIS), Context, false, sq).ToString();
            Assert(s == "'" + utf16 + "'");

            Context.KCode = RubyEncoding.KCodeUTF8;
            s             = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.KCodeUTF8), Context, true, sq).ToString();
            Assert(s == @"'\360\222\215\205'");

            Context.KCode = RubyEncoding.KCodeSJIS;
            s             = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, RubyEncoding.KCodeSJIS), Context, false, sq).ToString();
            Assert(s == @"'あ'");

            Context.KCode = RubyEncoding.KCodeSJIS;
            s             = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, RubyEncoding.Binary), Context, false, sq).ToString();
            Assert(s == @"'あ'");

            Context.KCode = RubyEncoding.KCodeSJIS;
            s             = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, RubyEncoding.KCodeUTF8), Context, true, sq).ToString();
            Assert(s == @"'\202\240'");
        }
Exemple #3
0
        private void Inspect2_SJIS()
        {
            const char sq = '\'';

            // あ
            var sjisWide     = new byte[] { 0x82, 0xa0 };
            var sjisEncoding = RubyEncoding.SJIS;

            string s;

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, sjisEncoding), false, sq).ToString();
            Assert(s == @"'\x82\xA0'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, sjisEncoding), true, sq).ToString();
            Assert(s == @"'\x82\xA0'");
        }
Exemple #4
0
        private void Inspect2()
        {
            const char sq = '\'';

            var sjisEncoding = RubyEncoding.KCodeSJIS.RealEncoding;
            // あ
            var sjisWide = new byte[] { 0x82, 0xa0 };
            // \u{12345} in UTF-8:
            var utf8 = new byte[] { 0xF0, 0x92, 0x8D, 0x85 };
            // \u{12345} in UTF-16: U+d808 U+df45
            var utf16 = Encoding.UTF8.GetString(utf8);

            string s;

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.Binary), Context, false, sq).ToString();
            Assert(s == @"'\xF0\x92\x8D\x85'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.Binary), Context, true, sq).ToString();
            Assert(s == @"'\xF0\x92\x8D\x85'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.UTF8), Context, false, sq).ToString();
            Assert(s == "'" + utf16 + "'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.UTF8), Context, true, sq).ToString();
            Assert(s == @"'\u{12345}'");

            // incomplete character:
            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.Create("\ud808\udf45\ud808", RubyEncoding.UTF8), Context, false, sq).ToString();
            Assert(s == @"'" + utf16 + @"\u{d808}'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, sjisEncoding), Context, false, sq).ToString();
            Assert(s == @"'あ'");

            s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, sjisEncoding), Context, true, sq).ToString();
            Assert(s == @"'\x82\xA0'");
        }