mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 21:44:16 +00:00
Switch string sub to wcstring
This commit is contained in:
parent
583d771b10
commit
4cc0c3bfa7
1 changed files with 5 additions and 6 deletions
|
@ -1256,20 +1256,19 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
|
||||||
|
|
||||||
int nsub = 0;
|
int nsub = 0;
|
||||||
arg_iterator_t aiter(argv, optind, streams);
|
arg_iterator_t aiter(argv, optind, streams);
|
||||||
while (const wchar_t *arg = aiter.next()) {
|
while (auto s = aiter.nextstr()) {
|
||||||
typedef wcstring::size_type size_type;
|
typedef wcstring::size_type size_type;
|
||||||
size_type pos = 0;
|
size_type pos = 0;
|
||||||
size_type count = wcstring::npos;
|
size_type count = wcstring::npos;
|
||||||
wcstring s(arg);
|
|
||||||
if (opts.start > 0) {
|
if (opts.start > 0) {
|
||||||
pos = static_cast<size_type>(opts.start - 1);
|
pos = static_cast<size_type>(opts.start - 1);
|
||||||
} else if (opts.start < 0) {
|
} else if (opts.start < 0) {
|
||||||
assert(opts.start != LONG_MIN); // checked above
|
assert(opts.start != LONG_MIN); // checked above
|
||||||
size_type n = static_cast<size_type>(-opts.start);
|
size_type n = static_cast<size_type>(-opts.start);
|
||||||
pos = n > s.length() ? 0 : s.length() - n;
|
pos = n > s->length() ? 0 : s->length() - n;
|
||||||
}
|
}
|
||||||
if (pos > s.length()) {
|
if (pos > s->length()) {
|
||||||
pos = s.length();
|
pos = s->length();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.length >= 0) {
|
if (opts.length >= 0) {
|
||||||
|
@ -1278,7 +1277,7 @@ static int string_sub(parser_t &parser, io_streams_t &streams, int argc, wchar_t
|
||||||
|
|
||||||
// Note that std::string permits count to extend past end of string.
|
// Note that std::string permits count to extend past end of string.
|
||||||
if (!opts.quiet) {
|
if (!opts.quiet) {
|
||||||
streams.out.append(s.substr(pos, count));
|
streams.out.append(s->substr(pos, count));
|
||||||
streams.out.append(L'\n');
|
streams.out.append(L'\n');
|
||||||
}
|
}
|
||||||
nsub++;
|
nsub++;
|
||||||
|
|
Loading…
Reference in a new issue