Fabian Homborg
720982a3cb
string: Quit early if --quiet is satisfied
...
E.g. if we do `string match -q`, and we find a match, nothing about
the input can change anything, so we quit early.
This is mainly useful for performance, but it also allows `string`
with `-q` to be used with infinite input (e.g. `yes`).
Alternative to #7495 .
2020-12-01 18:55:01 +01:00
Mahmoud Al-Qudsi
aa0bfa0eb8
Minor cleanup
...
clangd needs to respect clang-format files when inserting headers up
top.
[ci skip]
2020-11-28 01:00:27 -06:00
Mahmoud Al-Qudsi
5ddafb3b79
Add support for importing named regex matches
...
The new commandline switch `string match --regex --import` will import
as fish variables any named capture groups with the matched captures as
the value(s).
2020-11-26 14:41:00 -06:00
Mahmoud Al-Qudsi
282fb14dcf
Get rid of magic numbers in report_match() result
...
Replace with a class-local `enum class` instance.
2020-11-26 14:38:04 -06:00
Johannes Altmanninger
f758d39535
string pad: handle padding characters of width > 1
...
If the padding is not divisible by the char's width without remainder,
we pad the remainder with spaces, so the total width of the output is correct.
Also add completions, changelog entry, adjust documentation, add examples
with emoji and some tests. Apply some minor style nitpicks and avoid extra
allocations of the input strings.
2020-09-27 21:59:15 +02:00
Johannes Altmanninger
5ae03414d7
Sort string subcommands, and use binary search for lookup
...
I have no idea if this is better, and did not attempt to measure it, but we
do the same for electric variables which are even fewer.
2020-09-27 21:59:15 +02:00
Andrew Prokhorenkov
92511b09c4
New command "string pad" to pad text to a given width ( #7340 )
...
Pads text to a given width, or the maximum width of all inputs.
2020-09-27 21:59:15 +02:00
Fabian Homborg
7ec57f2c50
string: Handle unmatched capturing groups as empty
...
Instead of erroring out.
Fixes #7343 .
2020-09-20 10:36:17 +02:00
ridiculousfish
5c3571d626
Revert accidental merge of #7340
...
This reverts back to commit d8e2cac83e
.
I accidentally did a 'git push' during code review.
2020-09-19 19:31:44 -07:00
Andrew Prokhorenkov
2afa354c14
builtin_string: implement "width" argument for "string pad"
2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
70dfece3ce
builtin_string: remove quiet
2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
7eccec3ce0
builtin_string: order "string_pad" before "string_replace"
2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
52b0d356ff
builtin_string: remove redundant statements
2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
2b9158ddab
builtin_string: add "--max" for "string pad"
2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
886290c123
builtin_string: change npad
2020-09-19 19:25:57 -07:00
Andrew Prokhorenkov
c8e1894c72
builtin_string: add pad command
2020-09-19 19:25:57 -07:00
Soumya
8dd2d4f15d
Change builtins to return maybe_t<int> instead of int
2020-08-05 12:23:49 -07:00
ridiculousfish
bcfc54fdaa
Do not buffer builtin output if avoidable
...
builtins output to stdout and stderr via io_streams_t. Prior to this fix, it
contained an output_stream_t which just wraps a buffer. So all builtin output
went to this buffer (except for eval).
Switch output_stream_t to become a new abstract class which can output to a
buffer, file descriptor, or nowhere. This allows for example `string` to stream
its output as it is produced, instead of buffering it.
2020-07-30 22:45:44 -07:00
Kristofer Rye
3cfe113a60
builtin_string: Remove redundant condition in handle_flag_f
...
The removed comparison ({begin,end,field} == INT_MIN) always evaluates
to false, because at this point in evaluation, `begin <= 0` has already
been evaluated to be false. Since INT_MIN <= 0, the second conditional
in all three of the affected cases is always false. The C++ standard
seems to guarantee left-to-right evaluation of logical operators, but
not necessarily bitwise operators.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
2020-06-07 15:56:51 -07:00
John Zhang
8096d10bf1
remove redundant if conditions
...
All pcre2 resource free functions handle null pointer gracefully.
2020-05-31 17:10:09 -07:00
Fabian Homborg
02baa321ae
Restyle
...
More of that weird reflowing that clang-format loves to do
2020-04-21 21:11:26 +02:00
Jason Nader
6a839519b9
string split: add --allow-empty
flag to be used with --fields
2020-04-20 22:39:48 +02:00
Jason Nader
3bb86d3a61
string split --fields: handle multi-line/arg input
2020-04-20 22:39:48 +02:00
Lior Stern
ca91c201c3
Remove unnecessary string duplication in handle_flag_f.
...
Prevents a memory leak.
2020-04-06 19:13:48 +02:00
Rosen Penev
8d3377e923
[clang-tidy] Use C++ using instead of typedef
...
Found with modernize-use-using
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Rosen Penev
220f0a132d
[clang-tidy] use auto when casting
...
Found with modernize-use-auto
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-05 10:13:13 +02:00
Jason Nader
21bbd2ecb4
Return 1 if non-existent field is given
2020-04-04 15:30:09 +02:00
Jason Nader
1329a40e87
Allow simple ranges to be specified for --fields
2020-04-04 15:30:08 +02:00
Jason Nader
46dfc5ce0d
IWYU keeps falsely flagging this
2020-04-04 15:30:08 +02:00
Jason Nader
7cb1d3a646
Add string split --fields
2020-04-04 15:30:08 +02:00
George Christou
a45ffb7993
string/trim: Add VT to list of default chars
2020-03-23 18:37:08 +01:00
George Christou
a3436110c1
Add string sub --end
( #6765 )
2020-03-22 15:53:09 +01:00
ridiculousfish
87b1c02832
Reformat C++ files
2020-03-14 15:07:54 -07:00
Rosen Penev
fee08a87e9
[cppcheck] add const in several places
...
Found with constParameter, functionConst, constVariable, constArgument
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-14 15:07:54 -07:00
Rosen Penev
39861d54c5
[cppcheck] add some std::move
...
Found with passedByValue
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-14 15:07:54 -07:00
ridiculousfish
98e714f98f
clang-format .cpp and .h files
2020-01-16 15:18:28 -08:00
Johannes Altmanninger
75fa3b6bae
unbreak missing argument error on long option
2020-01-08 17:33:36 +01:00
Johannes Altmanninger
fdf398e435
show missing argument error only for last flag
...
closes #6483
2020-01-08 14:59:26 +01:00
Aaron Gyes
d0b0c9a77e
minor pcre2_matcher_t cleanup
2020-01-03 16:17:41 -08:00
Aaron Gyes
5281aca659
builtin_string.cpp: remove effectively dead variable
2020-01-03 16:17:41 -08:00
Rosen Penev
b1349f44f6
[clang-tidy] Add const to reference
...
Found with performance-unnecessary-copy-initialization
2019-12-26 21:37:15 -08:00
Rosen Penev
5d1ad8de91
[clang-tidy] Use std::move
...
Found with modernize-pass-by-value
2019-12-26 21:36:23 -08:00
Rosen Penev
6f4a9d527c
[clang-tidy] Use C++ using instead of C typedef
...
Found with modernize-use-using
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-29 23:46:51 -08:00
Rosen Penev
586ac3dfa7
[clang-tidy] Convert loops to range based
...
Found with modernize-loop-convert
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:50:40 -08:00
Rosen Penev
1055ff321c
[clang-tidy] Replace NULL with nullptr
...
Found with modernize-use-nullptr
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:23:03 -08:00
Rosen Penev
8d54e928cd
[clang-tidy] C to C++ headers
...
Found with modernize-deprecated-headers
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
Rosen Penev
0dfa7421f3
[clang-tidy] Convert C casts to C++ ones
...
Found with google-readability-casting
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:17:49 -08:00
Rosen Penev
7f62e30731
[clang-tidy] Replace size comparisons with empty
...
Found with readability-container-size-empty
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:13:33 -08:00
Johannes Altmanninger
08eac28bd8
Add individual documentation pages for string's subcommands
...
This adds string-x.rst for each subcommand x of string. The main page
(string.rst) is not changed, except that examples are shown directly after
each subcommand. The subcommand sections in string.rst are created by
textual inclusion of parts of the string-x.rst files.
Subcommand man pages can be viewed with either of:
```
man string collect
man string-collect
string collect <press F1 or Alt-h>
string collect -h
```
While `string -h ...` still prints the full help.
Closes #5968
2019-11-07 09:54:25 +01:00
Fabian Homborg
d77c465d23
string: Allow -eq
again
...
Instead of forbidding it for both modes, allow it for both and make it
quiet for string.
Fixes #6282
2019-11-04 17:34:37 +01:00