X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=ws.c;h=7a7ff130a34942506e6068105ac5946c9404bf18;hb=af9a01e1c2f6a8814b817eb7f3d78814389a3212;hp=522f646ed7f492a91ea288d03aabfcf5db69c196;hpb=e38f892d1832977511c4e7c82204c7f94c3a3232;p=git.git diff --git a/ws.c b/ws.c index 522f646ed..7a7ff130a 100644 --- a/ws.c +++ b/ws.c @@ -117,9 +117,9 @@ char *whitespace_error_string(unsigned ws) } /* If stream is non-NULL, emits the line after checking. */ -unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, - FILE *stream, const char *set, - const char *reset, const char *ws) +static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule, + FILE *stream, const char *set, + const char *reset, const char *ws) { unsigned result = 0; int written = 0; @@ -213,6 +213,33 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule, return result; } +void ws_check_emit(const char *line, int len, unsigned ws_rule, + FILE *stream, const char *set, + const char *reset, const char *ws) +{ + (void)ws_check_emit_1(line, len, ws_rule, stream, set, reset, ws); +} + +unsigned ws_check(const char *line, int len, unsigned ws_rule) +{ + return ws_check_emit_1(line, len, ws_rule, NULL, NULL, NULL, NULL); +} + +int ws_blank_line(const char *line, int len, unsigned ws_rule) +{ + /* + * We _might_ want to treat CR differently from other + * whitespace characters when ws_rule has WS_CR_AT_EOL, but + * for now we just use this stupid definition. + */ + while (len-- > 0) { + if (!isspace(*line)) + return 0; + line++; + } + return 1; +} + /* Copy the line to the buffer while fixing whitespaces */ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *error_count) { @@ -234,7 +261,7 @@ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *erro * Strip trailing whitespace */ if ((ws_rule & WS_TRAILING_SPACE) && - (2 < len && isspace(src[len-2]))) { + (2 <= len && isspace(src[len-2]))) { if (src[len - 1] == '\n') { add_nl_to_tail = 1; len--;