def scan_quoted_string(self, length=None):
        self.skip_char(b"\"")
        out = b""
        while length is None or len(out) <= length:
            if not self.char:
                raise ValueError("quoted string is missing closing quote")
            elif self.char == b"\"":
                if length is None or len(out) == length:
                    self.skip_char(b"\"")
                    break
                else:
                    raise ValueError("quoted string ended too early (expected %d)" % length)
            elif self.char == b"\\":
                c = self.advance()
                if c in b"\r\n":
                    continue
                elif c in b"0123":
                    s = c + self.advance() + self.advance()
                    val = int(s, 8)
                    out += chr(val)
                elif c == b"b": out += b"\b"
                elif c == b"f": out += b"\f"
                elif c == b"n": out += b"\n"
                elif c == b"r": out += b"\r"
                elif c == b"t": out += b"\t"
                elif c == b"v": out += b"\v"
                elif c == b"x":
                    s = self.advance() + self.advance()
                    val = int(s, 16)
                    out += chr(val)
                else:
                    raise ValueError("unknown escape character \\%s at %d" % (c, self.pos))
            else:
                out += self.char
            self.advance()
        return out
dataset/ETHPy150Open grawity/hacks/lib/python/nullroute/sexp.py/SexpParser.scan_quoted_string/original