Skip to content

Commit

Permalink
fmt/pl.c fix pl_trim, pl_ltrim, and pl_rtrim
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianfridrich committed Dec 5, 2024
1 parent db21fea commit 8601004
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/fmt/pl.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,13 +787,14 @@ int pl_ltrim(struct pl *pl)
if (!pl_isset(pl))
return EINVAL;

while (!re_regex(pl->p, 1, "[ \t\r\n]")) {
++pl->p;
--pl->l;
if (!pl->l)
return EINVAL;
size_t i = 0;
while (i <= pl->l && isspace((unsigned char)pl->p[i])) {
++i;
}

pl->p += i;
pl->l -= i;

return 0;
}

Expand All @@ -810,10 +811,8 @@ int pl_rtrim(struct pl *pl)
if (!pl_isset(pl))
return EINVAL;

while (!re_regex(pl->p + pl->l - 1, 1, "[ \t\r\n]")) {
while (pl->l > 0 && isspace((unsigned char)pl->p[pl->l - 1])) {
--pl->l;
if (!pl->l)
return EINVAL;
}

return 0;
Expand All @@ -832,7 +831,8 @@ int pl_trim(struct pl *pl)
int err;

err = pl_ltrim(pl);
err |= pl_rtrim(pl);
if (pl_isset(pl))
err |= pl_rtrim(pl);

return err;
}

0 comments on commit 8601004

Please sign in to comment.