public override string Dequote(byte[] @in, int inPtr, int inEnd) { if (2 <= inEnd - inPtr && @in[inPtr] == '"' && @in[inEnd - 1] == '"') { return(Dq(@in, inPtr + 1, inEnd - 1)); } return(RawParseUtils.Decode(Constants.CHARSET, @in, inPtr, inEnd)); }
public override string Dequote(byte[] @in, int ip, int ie) { bool inquote = false; byte[] r = new byte[ie - ip]; int rPtr = 0; while (ip < ie) { byte b = @in[ip++]; switch (b) { case (byte)('\''): { inquote = !inquote; continue; goto case (byte)('\\'); } case (byte)('\\'): { if (inquote || ip == ie) { r[rPtr++] = b; } else { // literal within a quote r[rPtr++] = @in[ip++]; } continue; goto default; } default: { r[rPtr++] = b; continue; break; } } } return(RawParseUtils.Decode(Constants.CHARSET, r, 0, rPtr)); }
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)); }