mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Switch trim to wcstring
This commit is contained in:
parent
4cc0c3bfa7
commit
191ca21092
1 changed files with 7 additions and 9 deletions
|
@ -1303,25 +1303,23 @@ static int string_trim(parser_t &parser, io_streams_t &streams, int argc, wchar_
|
||||||
|
|
||||||
size_t ntrim = 0;
|
size_t ntrim = 0;
|
||||||
|
|
||||||
wcstring argstr;
|
|
||||||
arg_iterator_t aiter(argv, optind, streams);
|
arg_iterator_t aiter(argv, optind, streams);
|
||||||
while (const wchar_t *arg = aiter.next()) {
|
while (auto arg = aiter.nextstr()) {
|
||||||
argstr = arg;
|
|
||||||
// Begin and end are respectively the first character to keep on the left, and first
|
// Begin and end are respectively the first character to keep on the left, and first
|
||||||
// character to trim on the right. The length is thus end - start.
|
// character to trim on the right. The length is thus end - start.
|
||||||
size_t begin = 0, end = argstr.size();
|
size_t begin = 0, end = arg->size();
|
||||||
if (opts.right) {
|
if (opts.right) {
|
||||||
size_t last_to_keep = argstr.find_last_not_of(opts.chars_to_trim);
|
size_t last_to_keep = arg->find_last_not_of(opts.chars_to_trim);
|
||||||
end = (last_to_keep == wcstring::npos) ? 0 : last_to_keep + 1;
|
end = (last_to_keep == wcstring::npos) ? 0 : last_to_keep + 1;
|
||||||
}
|
}
|
||||||
if (opts.left) {
|
if (opts.left) {
|
||||||
size_t first_to_keep = argstr.find_first_not_of(opts.chars_to_trim);
|
size_t first_to_keep = arg->find_first_not_of(opts.chars_to_trim);
|
||||||
begin = (first_to_keep == wcstring::npos ? end : first_to_keep);
|
begin = (first_to_keep == wcstring::npos ? end : first_to_keep);
|
||||||
}
|
}
|
||||||
assert(begin <= end && end <= argstr.size());
|
assert(begin <= end && end <= arg->size());
|
||||||
ntrim += argstr.size() - (end - begin);
|
ntrim += arg->size() - (end - begin);
|
||||||
if (!opts.quiet) {
|
if (!opts.quiet) {
|
||||||
streams.out.append(wcstring(argstr, begin, end - begin));
|
streams.out.append(wcstring(*arg, begin, end - begin));
|
||||||
streams.out.append(L'\n');
|
streams.out.append(L'\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue