void argcv_quote_copy_n (char *dst, const char *src, size_t size) { const char *end = src + size; for (; src < end; src++) { if (*src == '"') { *dst++ = '\\'; *dst++ = *src; } else if (*src != '\t' && *src != '\\' && isprint(*src)) *dst++ = *src; else { int c = argcv_quote_char (*src); *dst++ = '\\'; if (c != -1) *dst++ = c; else { char tmp[4]; snprintf (tmp, sizeof tmp, "%03o", *(unsigned char*)src); memcpy (dst, tmp, 3); dst += 3; } } } }
size_t argcv_quoted_length_n (const char *str, size_t size, int *quote) { size_t len = 0; const char *end = str + size; *quote = 0; for (; str < end; str++) { if (*str == ' ') { len++; *quote = 1; } else if (*str == '"') { len += 2; *quote = 1; } else if (*str != '\t' && *str != '\\' && isprint (*str)) len++; else if (argcv_quote_char (*str) != -1) len += 2; else len += 4; } return len; }
size_t argcv_quoted_length (const char *str, int *quote) { size_t len = 0; *quote = 0; for (; *str; str++) { if (*str == ' ') { len++; *quote = 1; } else if (*str == '"' || *str == '\'') { len += 2; *quote = 1; } else if (*str != '\t' && *str != '\\' && isprint (*str)) len++; else if (argcv_quote_char (*str) != -1) len += 2; else len += 4; } return len; }
size_t argcv_quoted_length (const char *str, int *quote) { size_t len = 0; if (*str == 0) { *quote = 1; return 0; } *quote = 0; for (; *str; str++) { if (*str == ' ') { len++; *quote = 1; } else if (*str == '"') { len += 2; *quote = 1; } else if (*str != '\t' && *str != '\\' && isprint (*str)) len++; else { switch (argcv_quoting_style) { case argcv_quoting_octal: if (argcv_quote_char (*str) != -1) len += 2; else len += 4; break; case argcv_quoting_hex: len += 3; break; } } } return len; }
void argcv_quote_copy (char *dst, const char *src) { for (; *src; src++) { if (*src == '"') { *dst++ = '\\'; *dst++ = *src; } else if (*src != '\t' && *src != '\\' && isprint(*src)) *dst++ = *src; else { char tmp[4]; switch (argcv_quoting_style) { case argcv_quoting_octal: { int c = argcv_quote_char (*src); *dst++ = '\\'; if (c != -1) *dst++ = c; else { snprintf (tmp, sizeof tmp, "%03o", *(unsigned char*)src); memcpy (dst, tmp, 3); dst += 3; } break; } case argcv_quoting_hex: snprintf (tmp, sizeof tmp, "%%%02X", *(unsigned char*)src); memcpy (dst, tmp, 3); dst += 3; break; } } } }