Пример #1
0
            public override string dequote(byte[] instr, int offset, int end)
            {
                if (instr == null)
                {
                    throw new ArgumentNullException("instr");
                }
                bool inquote = false;

                byte[] r    = new byte[end - offset];
                int    rPtr = 0;

                while (offset < end)
                {
                    byte b = instr[offset++];
                    switch (b)
                    {
                    case (byte)'\'':
                        inquote = !inquote;
                        continue;

                    case (byte)'\\':
                        if (inquote || offset == end)
                        {
                            r[rPtr++] = b;                         // literal within a quote
                        }
                        else
                        {
                            r[rPtr++] = instr[offset++];
                        }
                        continue;

                    default:
                        r[rPtr++] = b;
                        continue;
                    }
                }
                return(RawParseUtils.decode(Constants.CHARSET, r, 0, rPtr));
            }
Пример #2
0
 private static int HexStringToUInt32(byte[] bs, int offset)
 {
     return(RawParseUtils.parseHexInt32(bs, offset));
 }
Пример #3
0
            private static string dq(byte[] in_str, int inPtr, int inEnd)
            {
                byte[] r    = new byte[inEnd - inPtr];
                int    rPtr = 0;

                while (inPtr < inEnd)
                {
                    byte b = in_str[inPtr++];
                    if (b != '\\')
                    {
                        r[rPtr++] = b;
                        continue;
                    }

                    if (inPtr == inEnd)
                    {
                        // Lone trailing backslash. Treat it as a literal.
                        //
                        r[rPtr++] = (byte)'\\';
                        break;
                    }

                    switch (in_str[inPtr++])
                    {
                    case (byte)'a':
                        r[rPtr++] = 0x07 /* \a = BEL */;
                        continue;

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

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

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

                    case (byte)'r':
                        r[rPtr++] = (byte)'\r';
                        continue;

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

                    case (byte)'v':
                        r[rPtr++] = 0x0B /* \v = VT */;
                        continue;

                    case (byte)'\\':
                    case (byte)'"':
                        r[rPtr++] = in_str[inPtr - 1];
                        continue;

                    case (byte)'0':
                    case (byte)'1':
                    case (byte)'2':
                    case (byte)'3': {
                        int cp = in_str[inPtr - 1] - '0';
                        while (inPtr < inEnd)
                        {
                            byte c = in_str[inPtr];
                            if ('0' <= c && c <= '7')
                            {
                                cp <<= 3;
                                cp  |= c - '0';
                                inPtr++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        r[rPtr++] = (byte)cp;
                        continue;
                    }

                    default:
                        // Any other code is taken literally.
                        //
                        r[rPtr++] = (byte)'\\';
                        r[rPtr++] = in_str[inPtr - 1];
                        continue;
                    }
                }

                return(RawParseUtils.decode(Constants.CHARSET, r, 0, rPtr));
            }