Commit graph

26 commits

Author SHA1 Message Date
Lily Ballard
181e44d331 Invert the flag for string collect
Instead of requiring a flag to enable newline trimming, invert it so the
flag (now `--no-trim-newlines`) disables newline trimming. This way our
default behavior matches that of sh's `"$(cmd)"`.

Also change newline trimming to trim all newlines instead of just one,
again to match sh's behavior.
2019-06-16 16:40:14 -07:00
Lily Ballard
b41e5cbbb7 Add string collect
The `string collect` subcommand behaves quite similarly in practice to
`string split0 -m 0` in that it doesn't split its output, but it also
takes an optional `--trim-newline` flag to trim a single trailing
newline off of the output.

See issue #159.
2019-06-16 15:51:57 -07:00
David Adam
78d015bd61 string: add tests for empty capture groups
As seen in #5201.
2019-05-29 23:14:19 +08:00
Fabian Homborg
47ff060b89 string: Fix split0 return status
It turns out that `string split0` didn't actually ever do any
splitting. The arg_iterator_t already split stdin on NUL, and split0 just
performed an additional search that could never succeed (since
arguments from argv already can't contain NUL).

Let the arg_iterator_t not perform any splitting if asked, and then
let split0 split in 0.

One slight wart is that split0 ignores a trailing NUL, which normal
split doesn't.

Fixes #5701.
2019-02-26 20:03:40 +01:00
Mahmoud Al-Qudsi
31d17f4559 Rename string escape --style=pcre2 to string escape --style=regex 2018-11-16 20:22:06 -06:00
Mahmoud Al-Qudsi
e160cde606 Implement PCRE2 escaping
Closes #5309.
2018-11-15 12:00:56 -06:00
Fabian Homborg
460bc00698 Fix string escape var and url styles
Turns out I broke these in my zeal to remove wcs2string.

This reverts commit 583d771b10.

Fixes #5322.
2018-11-07 12:48:11 +01:00
Fabian Homborg
3ba74b3195 [string] Match everything with an empty pattern and -e
I.e. `string match --entire "" -- banana` used to match nothing, now
it matches everything.

Fixes #4971.
2018-09-16 13:03:15 +02:00
ridiculousfish
73c747d162 Add string join0
string join0 joins its arguments using NUL byte, which complements
string split0. For example it allows piping a variable through sort -z.
2018-07-01 15:56:34 -07:00
ridiculousfish
d34a300818 Add string split0
This adds a new string command split0, which splits on zero bytes.
split0 has superpowers because its output is not further split on
newlines when used in command substitutions.
2018-07-01 15:56:33 -07:00
Fabian Homborg
ca897807eb Add some tests for string and NUL 2018-05-28 12:10:40 +02:00
ridiculousfish
6e56637cf0 Remove support for the ? wildcard
Fixes #4520
2018-03-31 16:54:50 -07:00
Kurtis Rader
a4ed0837a1 use new logmsg and set --show in tests 2017-08-04 12:51:48 -07:00
Kurtis Rader
63d601610d implement -nnn style flags in argparse
This implements support for numeric flags without an associated short or
long flag name. This pattern is used by many commands. For example `head
-3 /a/file` to emit the first three lines of the file.

Fixes #4214
2017-07-13 20:36:59 -07:00
Kurtis Rader
f3cb625802 implement string unescape
Fixes #3543
2017-06-23 22:23:01 -07:00
Kurtis Rader
60bca14b37 implement string escape --style=xxx
We need a way to encode arbitrary strings into valid fish variable
names. It would also be nice if we could convert strings to valid URLs
without using the slow and hard to understand `__fish_urlencode` function.
In particular, eliminating the need to manipulate the locale.

Fixes #4150
2017-06-23 22:23:01 -07:00
Kurtis Rader
f6c9bfc0e8 implement string lower and string upper
Fixes #4080
2017-06-10 17:35:25 -07:00
Kurtis Rader
fb54d34788 change string match --filter to --entire
Per discussion in PR#3998 to review adding a `--filter` flag to `string
replace` rename the same flag in the `string match` subcommand to avoid
confusion about the meaning of the flag.
2017-05-01 22:19:58 -07:00
Kurtis Rader
16816a1202 add string replace --filter flag
Fixes #3348
2017-05-01 22:07:30 -07:00
Kurtis Rader
5b6814d6ad add string match --filter flag
Fixes #3957
2017-04-24 21:45:06 -07:00
Kurtis Rader
f0469d829a string repeat of an empty string is an error
Fixes #3898
2017-03-15 13:55:53 -07:00
Greynad
98f4e49669 Add string 'repeat' subcommand
This feature add the ability to repeat a string a given number of times.
For example: string repeat -n 3 foo
2017-03-12 20:30:36 -07:00
Fabian Homborg
8d6735cb41 Make string match -rnv work
Fixes #3098.
2016-05-31 23:24:08 +02:00
Aaron Gyes
790c7f80c7 Implement an --invert/-v for string match, like grep -v.
Only lines that do not match the pattern are shown.
2016-04-08 10:49:29 +08:00
Michael Steed
5b0996fd80 make fish compatible with pcre2 10.21
pcre2_substitute() now sets the output buffer length to PCRE2_UNSET (~0)
if the output buffer is determined to be too small. This change keeps
track of the buffer size separately where pcre2 can't touch it.

A better fix would be to let pcre2 tell fish what size buffer it needs.
This can be done with PCRE2_SUBSTITUTE_OVERFLOW_LENGTH, but this
requires pcre2 10.21 or later (released January 12), which may be too
new to introduce as a dependency at this point.

Fixes #2743
2016-02-21 19:32:08 -08:00
David Adam
0b3406bdc0 tests/string.in: add tests for string builtin 2015-10-09 11:27:18 +08:00