Fix mapping a class to a simple set and improve error-reporting
It's standard behaviour to map a whole class of matched objects to the last element of a given simple set2 instead of just passing it through. Also, error out more strictly when the user gives us bogus sets.
This commit is contained in:
parent
0f90528df7
commit
7a644aea7d
12
tr.c
12
tr.c
|
@ -110,7 +110,7 @@ nextbrack:
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
eprintf("Invalid character class\n");
|
||||
eprintf("Invalid character class.\n");
|
||||
}
|
||||
|
||||
/* REPEAT [_*n] (only allowed in set2) */
|
||||
|
@ -192,7 +192,9 @@ main(int argc, char *argv[])
|
|||
if (argc == 2)
|
||||
set2ranges = makeset(argv[1], &set2, &set2check);
|
||||
if (dflag == sflag && !set2ranges && !set2check)
|
||||
eprintf("set2 must be non-empty\n");
|
||||
eprintf("set2 must be non-empty.\n");
|
||||
if (set2check && set2check != iswlower && set2check != iswupper)
|
||||
eprintf("set2 can only be the 'lower' or 'upper' class.\n");
|
||||
read:
|
||||
if (!readrune("<stdin>", stdin, &r))
|
||||
return 0;
|
||||
|
@ -238,8 +240,12 @@ read:
|
|||
}
|
||||
if (set1check == iswupper && set2check == iswlower)
|
||||
r = towlower((wint_t)r);
|
||||
if (set1check == iswlower && set2check == iswupper)
|
||||
else if (set1check == iswlower && set2check == iswupper)
|
||||
r = towupper((wint_t)r);
|
||||
else if (set2ranges > 0)
|
||||
r = set2[set2ranges - 1].end;
|
||||
else
|
||||
eprintf("Misaligned character classes.\n");
|
||||
}
|
||||
if (dflag && cflag)
|
||||
goto read;
|
||||
|
|
Loading…
Reference in New Issue
Block a user