/* Like strpbrk(), but not break if it is right after a backslash (escaped) */ char *strpbrk_esc(char *str, constchar *stopset)
{ char *ptr;
do {
ptr = strpbrk(str, stopset); if (!ptr) { /* stopset not in str. */ break;
} if (ptr == str) { /* stopset character is first in str. */ break;
} if (ptr == str + 1 && str[0] != '\\') { /* stopset chacter is second and wasn't preceded by a '\'. */ break;
}
str = ptr + 1;
} while (ptr[-1] == '\\' && ptr[-2] != '\\');
return ptr;
}
/* Like strpbrk_esc(), but not break if it is quoted with single/double quotes */ char *strpbrk_esq(char *str, constchar *stopset)
{ char *_stopset = NULL; char *ptr; constchar *squote = "'"; constchar *dquote = "\"";
if (asprintf(&_stopset, "%s%c%c", stopset, *squote, *dquote) < 0) return NULL;
do {
ptr = strpbrk_esc(str, _stopset); if (!ptr) break; if (*ptr == *squote)
ptr = strpbrk_esc(ptr + 1, squote); elseif (*ptr == *dquote)
ptr = strpbrk_esc(ptr + 1, dquote); else break;
str = ptr + 1;
} while (ptr);
free(_stopset); return ptr;
}
/* Like strdup, but do not copy a single backslash */ char *strdup_esc(constchar *str)
{ char *s, *d, *p, *ret = strdup(str);
if (!ret) return NULL;
d = strchr(ret, '\\'); if (!d) return ret;
s = d + 1; do { if (*s == '\0') {
*d = '\0'; break;
}
p = strchr(s + 1, '\\'); if (p) {
memmove(d, s, p - s);
d += p - s;
s = p + 1;
} else
memmove(d, s, strlen(s) + 1);
} while (p);
return ret;
}
/* Remove backslash right before quote and return next quote address. */ staticchar *remove_consumed_esc(char *str, int len, int quote)
{ char *ptr = str, *end = str + len;
while (*ptr != quote && ptr < end) { if (*ptr == '\\' && *(ptr + 1) == quote) {
memmove(ptr, ptr + 1, end - (ptr + 1)); /* now *ptr is `quote`. */
end--;
}
ptr++;
}
/* Count occurrences */ while (loc) {
loc = strchr(loc + 1, needle);
num++;
}
/* Allocate enough space for replacements and reset first location */
new_s = malloc(strlen(haystack) + (num * (replace_len - 1) + 1)); if (!new_s) return NULL;
loc = strchr(haystack, needle);
to = new_s;
while (loc) { /* Copy original string up to found char and update positions */
memcpy(to, from, 1 + loc - from);
to += loc - from;
from = loc + 1;
/* Copy replacement string and update positions */
memcpy(to, replace, replace_len);
to += replace_len;
/* needle next occurrence or end of string */
loc = strchr(from, needle);
}
/* Copy any remaining chars + null */
strcpy(to, from);
return new_s;
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.6Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.