mirror of
https://github.com/sheumann/hush.git
synced 2024-09-12 00:55:11 +00:00
unexpand: fix "a b"\n" input case
Signed-off-by: Tomas Heinrich <heinrich.tomas@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
1abc07dcca
commit
968951fd0c
@ -81,12 +81,13 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
|
|||||||
|
|
||||||
while (*ptr) {
|
while (*ptr) {
|
||||||
unsigned n;
|
unsigned n;
|
||||||
unsigned len;
|
unsigned len = 0;
|
||||||
|
|
||||||
while (*ptr == ' ') {
|
while (*ptr == ' ') {
|
||||||
column++;
|
|
||||||
ptr++;
|
ptr++;
|
||||||
|
len++;
|
||||||
}
|
}
|
||||||
|
column += len;
|
||||||
if (*ptr == '\t') {
|
if (*ptr == '\t') {
|
||||||
column += tab_size - (column % tab_size);
|
column += tab_size - (column % tab_size);
|
||||||
ptr++;
|
ptr++;
|
||||||
@ -94,16 +95,18 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
n = column / tab_size;
|
n = column / tab_size;
|
||||||
column = column % tab_size;
|
if (n) {
|
||||||
|
len = column = column % tab_size;
|
||||||
while (n--)
|
while (n--)
|
||||||
putchar('\t');
|
putchar('\t');
|
||||||
|
}
|
||||||
|
|
||||||
if ((opt & OPT_INITIAL) && ptr != line) {
|
if ((opt & OPT_INITIAL) && ptr != line) {
|
||||||
printf("%*s%s", column, "", ptr);
|
printf("%*s%s", len, "", ptr);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
n = strcspn(ptr, "\t ");
|
n = strcspn(ptr, "\t ");
|
||||||
printf("%*s%.*s", column, "", n, ptr);
|
printf("%*s%.*s", len, "", n, ptr);
|
||||||
# if ENABLE_FEATURE_ASSUME_UNICODE
|
# if ENABLE_FEATURE_ASSUME_UNICODE
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
@ -27,6 +27,9 @@ testing "unexpand case 6" "unexpand" \
|
|||||||
testing "unexpand case 7" "unexpand" \
|
testing "unexpand case 7" "unexpand" \
|
||||||
"123\t 45678\n" "" "123 \t 45678\n" \
|
"123\t 45678\n" "" "123 \t 45678\n" \
|
||||||
|
|
||||||
|
testing "unexpand case 8" "unexpand" \
|
||||||
|
"a b\n" "" "a b\n" \
|
||||||
|
|
||||||
testing "unexpand with unicode characher 0x394" "unexpand" \
|
testing "unexpand with unicode characher 0x394" "unexpand" \
|
||||||
"1ΔΔΔ5\t99999\n" "" "1ΔΔΔ5 99999\n" \
|
"1ΔΔΔ5\t99999\n" "" "1ΔΔΔ5 99999\n" \
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user