コード例 #1
0
            private static string Dq(byte[] @in, int inPtr, int inEnd)
            {
                byte[] r    = new byte[inEnd - inPtr];
                int    rPtr = 0;

                while (inPtr < inEnd)
                {
                    byte b = @in[inPtr++];
                    if (b != '\\')
                    {
                        r[rPtr++] = b;
                        continue;
                    }
                    if (inPtr == inEnd)
                    {
                        // Lone trailing backslash. Treat it as a literal.
                        //
                        r[rPtr++] = (byte)('\\');
                        break;
                    }
                    switch (@in[inPtr++])
                    {
                    case (byte)('a'):
                    {
                        r[rPtr++] = unchecked ((int)(0x07));
                        continue;
                        goto case (byte)('b');
                    }

                    case (byte)('b'):
                    {
                        r[rPtr++] = (byte)('\b');
                        continue;
                        goto case (byte)('f');
                    }

                    case (byte)('f'):
                    {
                        r[rPtr++] = (byte)('\f');
                        continue;
                        goto case (byte)('n');
                    }

                    case (byte)('n'):
                    {
                        r[rPtr++] = (byte)('\n');
                        continue;
                        goto case (byte)('r');
                    }

                    case (byte)('r'):
                    {
                        r[rPtr++] = (byte)('\r');
                        continue;
                        goto case (byte)('t');
                    }

                    case (byte)('t'):
                    {
                        r[rPtr++] = (byte)('\t');
                        continue;
                        goto case (byte)('v');
                    }

                    case (byte)('v'):
                    {
                        r[rPtr++] = unchecked ((int)(0x0B));
                        continue;
                        goto case (byte)('\\');
                    }

                    case (byte)('\\'):
                    case (byte)('"'):
                    {
                        r[rPtr++] = @in[inPtr - 1];
                        continue;
                        goto case (byte)('0');
                    }

                    case (byte)('0'):
                    case (byte)('1'):
                    case (byte)('2'):
                    case (byte)('3'):
                    {
                        int cp = @in[inPtr - 1] - '0';
                        for (int n = 1; n < 3 && inPtr < inEnd; n++)
                        {
                            byte c = @in[inPtr];
                            if ('0' <= c && ((sbyte)c) <= '7')
                            {
                                cp <<= 3;
                                cp  |= c - '0';
                                inPtr++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        r[rPtr++] = unchecked ((byte)cp);
                        continue;
                        goto default;
                    }

                    default:
                    {
                        // Any other code is taken literally.
                        //
                        r[rPtr++] = (byte)('\\');
                        r[rPtr++] = @in[inPtr - 1];
                        continue;
                        break;
                    }
                    }
                }
                return(RawParseUtils.Decode(Constants.CHARSET, r, 0, rPtr));
            }
 // pass
 private static int Parse32(string str)
 {
     return(RawParseUtils.ParseHexInt32(Constants.EncodeASCII(str), 0));
 }
        private void AssertPersonIdent(string line, PersonIdent expected)
        {
            PersonIdent actual = RawParseUtils.ParsePersonIdent(line);

            NUnit.Framework.Assert.AreEqual(expected, actual);
        }
コード例 #4
0
 public virtual void TestMatch_TooSmall()
 {
     byte[] src = Constants.EncodeASCII("author ");
     byte[] dst = Constants.EncodeASCII("author autho");
     NUnit.Framework.Assert.IsTrue(RawParseUtils.Match(dst, src.Length + 1, src) < 0);
 }
コード例 #5
0
 public virtual void TestMatch_NotEqual()
 {
     byte[] src = Constants.EncodeASCII(" differ\n");
     byte[] dst = Constants.EncodeASCII("a differ\n");
     NUnit.Framework.Assert.IsTrue(RawParseUtils.Match(dst, 2, src) < 0);
 }
コード例 #6
0
 public virtual void TestMatch_Equal()
 {
     byte[] src = Constants.EncodeASCII(" differ\n");
     byte[] dst = Constants.EncodeASCII("foo differ\n");
     NUnit.Framework.Assert.IsTrue(RawParseUtils.Match(dst, 3, src) == 3 + src.Length);
 }