quote :: T.Text -> Builder
quote q = case T.uncons t of
    Nothing -> fromText h
    Just (c, t') -> fromText h <> escape c <> quote t'
    where
        (h, t) = T.break isEscape q
        isEscape c = c == '\"' || c == '\\' || c < '\x20'
        escape '\"' = "\\\""
        escape '\\' = "\\\\"
        escape '\n' = "\\n"
        escape '\r' = "\\r"
        escape '\t' = "\\t"
        escape c = singleton c
quote :: T.Text -> Builder
quote q = case T.uncons t of
    Nothing -> fromText h
    Just (c, t') -> fromText h <> escape c <> quote t'
    where
        (h, t) = T.break isEscape q
        isEscape c = c == '\"' || c == '\\' || c < '\x20'
        escape '\"' = "\\\""
        escape '\\' = "\\\\"
        escape '\n' = "\\n"
        escape '\r' = "\\r"
        escape '\t' = "\\t"
        escape c = singleton c
quote q = case T.uncons t of
    Nothing -> fromText h
    Just (c, t') -> fromText h <> escape c <> quote t'
    where
        (h, t) = T.break isEscape q
        isEscape c = c == '\"' || c == '\\' || c < '\x20'
        escape '\"' = "\\\""
        escape '\\' = "\\\\"
        escape '\n' = "\\n"
        escape '\r' = "\\r"
        escape '\t' = "\\t"
        escape c = singleton c