mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-13 23:31:08 +02:00
Changed the name of the "ret" variable in mb_niceformat() to "cnt"
because "ret" is usually used for a variable name to hold the return value of the function. Also, changed the test when checking for a \0 to only check if "cnt" is 0, since we must always change a value of 0 to 1.
This commit is contained in:
parent
cc890edcb5
commit
00465c76fb
1 changed files with 7 additions and 8 deletions
|
@ -275,36 +275,35 @@ stringaszleline(char *instr, int incs, int *outll, int *outsz, int *outcs)
|
||||||
memset(&ps, '\0', sizeof(ps));
|
memset(&ps, '\0', sizeof(ps));
|
||||||
|
|
||||||
while (ll > 0) {
|
while (ll > 0) {
|
||||||
size_t ret = mbrtowc(outptr, inptr, ll, &ps);
|
size_t cnt = mbrtowc(outptr, inptr, ll, &ps);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At this point we don't handle either incomplete (-2) or
|
* At this point we don't handle either incomplete (-2) or
|
||||||
* invalid (-1) multibyte sequences. Use the current length
|
* invalid (-1) multibyte sequences. Use the current length
|
||||||
* and return.
|
* and return.
|
||||||
*/
|
*/
|
||||||
if (ret == (size_t)-1 || ret == (size_t)-2)
|
if (cnt == (size_t)-1 || cnt == (size_t)-2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Careful: converting a wide NUL returns zero, but we
|
* Careful: converting a wide NUL returns zero, but we
|
||||||
* want to treat NULs as regular characters.
|
* want to treat NULs as regular characters.
|
||||||
* The NUL does get converted, however, so test that.
|
|
||||||
* Assume it was represented by a single ASCII NUL;
|
* Assume it was represented by a single ASCII NUL;
|
||||||
* certainly true for Unicode and unlikely to be false
|
* certainly true for Unicode and unlikely to be false
|
||||||
* in any non-pathological multibyte representation.
|
* in any non-pathological multibyte representation.
|
||||||
*/
|
*/
|
||||||
if (*outptr == L'\0' && ret == 0)
|
if (cnt == 0)
|
||||||
ret = 1;
|
cnt = 1;
|
||||||
|
|
||||||
if (outcs) {
|
if (outcs) {
|
||||||
int offs = inptr - instr;
|
int offs = inptr - instr;
|
||||||
if (offs <= incs && incs < offs + (int)ret)
|
if (offs <= incs && incs < offs + (int)cnt)
|
||||||
*outcs = outptr - outstr;
|
*outcs = outptr - outstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inptr += ret;
|
inptr += cnt;
|
||||||
outptr++;
|
outptr++;
|
||||||
ll -= ret;
|
ll -= cnt;
|
||||||
}
|
}
|
||||||
if (outcs && inptr <= instr + incs)
|
if (outcs && inptr <= instr + incs)
|
||||||
*outcs = outptr - outstr;
|
*outcs = outptr - outstr;
|
||||||
|
|
Loading…
Reference in a new issue