1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2026-01-14 09:11:02 +00:00
Commit graph

7911 commits

Author SHA1 Message Date
karlmcdowall
e6ff6d5c69
cat: Formatting performance improvement (#7642)
* cat: Formatting performance improvement

Use memchr library in `cat` to improve performance when detecting
newlines.
Significantly improves performance when running with -n, -s, -E, -b
flags.


Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2025-04-04 23:47:28 +02:00
Sylvestre Ledru
88cf66174f
Merge pull request #7648 from drinkcat/parse_time-ebd
timeout: Use common parser to parse time duration
2025-04-04 23:46:48 +02:00
Sylvestre Ledru
295628a2e9
Merge pull request #7631 from drinkcat/format-hex-default
uucore: format: Fix hexadecimal default format print
2025-04-04 23:44:35 +02:00
Dorian Peron
273a0500d8 uucore: remove clap dev dependency as it is already mentionned in regular dependencies 2025-04-04 18:53:35 +02:00
Dorian Peron
a3f770fbe8 uucore: make glob dependence optional under the parser feature 2025-04-04 18:53:35 +02:00
Dorian Peron
9dd8d8ab0d uucore: make chrono, chrono-tz, iana-time-zone deps optional under the custom-tz-fmt feature 2025-04-04 18:53:35 +02:00
Nicolas Boichat
3fc9c40c51 uucore: parser: parse_time: Use ExtendedBigDecimal parser
Gives a little bit more flexibility in terms of allowed input
for durations (e.g. in `timeout`), e.g. hex floating point
numbers are now allowed.

Fixes another part of #7475.
2025-04-04 18:23:17 +02:00
Nicolas Boichat
1d7e0eccc8 uucore: parser: num_parser: Do not Underflow/Overflow when parsing 0
Values like 0e18172487393827593258 and 0e-18172487393827593258 should
just be parsed as 0, and do not need to return an error.
2025-04-04 18:12:11 +02:00
Nicolas Boichat
94a26e170e uucore: parser: parse_time: Handle infinity and nan
There were some missing corner cases when handling infinity and
nan:
 - inf/infinity can be capitalized
 - nan must always be rejected, even if a suffix is provided

Also, return Duration::MAX with infinite values, just for consistency
(num.fract() returns 0 for infinity so technically we were just
short of that).

Add unit tests too.

Fixes some of #7475.
2025-04-04 18:12:11 +02:00
Nicolas Boichat
e0a6482759 seq: Trim whitespaces, then try to remove +
Otherwise, `seq` crashes with ` 0xee.` as input.

Also update one of the tests to catch that.
2025-04-04 17:09:33 +02:00
Nicolas Boichat
6243dd5494 uucore: Move parser to a feature
This will eventually be needed as we'll want parse_time to
call into num_parser, which was previously contained in format
feature.
2025-04-04 15:25:06 +02:00
Nicolas Boichat
a937aa5117 uucore: Move extendedbigdecimal to its own feature
This will be needed later on so that we can split format and
parse features.
2025-04-04 14:12:51 +02:00
Nicolas Boichat
ae3756b434 seq: Do not allow -w and -f to be specified at the same time
Fixes #7466.
2025-04-04 10:17:17 +02:00
Nicolas Boichat
04a12820bb seq: Simplify leading + handling
Address review comment.
2025-04-03 17:26:38 +02:00
Nicolas Boichat
27efb9eff4 seq: Parse integral and fractional number of digits in the same function
A lot of the code can be shared, and parsing is quite straightforward
as we know that the digit is somewhat valid.
2025-04-03 17:26:38 +02:00
Nicolas Boichat
77d66bab47 seq: Refactor to actually use PreciseNumber::num_fractional_digits
The field was unused, and actually redundant with the precision
computed separatedly.

This simplifies the code, reintroduces testing.
2025-04-03 17:26:38 +02:00
Nicolas Boichat
84e5ee4b86 seq: Accept underflow in parameters
Also, add a test to check that a very, very, small number is
treated as 0. That's probably undefined behaviour, but it does
make some sense.
2025-04-03 17:26:38 +02:00
Nicolas Boichat
686f1c7841 seq: Remove custom number parsing
Just use the format provided function.
2025-04-03 17:26:38 +02:00
Daniel Hofstetter
293554e358 yes: fix error from manual_repeat_n lint 2025-04-03 15:38:06 +02:00
Karl McDowall
a4b621ad8a cat: bugfix when running with -T option
Fixes an crash seen when running with -T option if no newline
is found in a buffer.
Added unit test to validate.
2025-04-02 18:59:27 -06:00
Chandra Kiran G
3a0b43bdf7
df: add thiserror (#7545)
* refactor: Add thiserror to df

* fix: Try fixing tests

* refactor(df): Move `df` to `thiserror`

* chore(df): Add back comment

* chore: Refactor column.rs correctly
2025-04-02 10:19:19 +02:00
Daniel Hofstetter
60ebace7f2 uucore/format: remove TODOs related to bigdecimal 2025-04-01 17:29:28 +02:00
Daniel Hofstetter
636e4a777b uucore/format: remove Display impl
of ExtendedBigDecimal
2025-04-01 17:08:04 +02:00
Nicolas Boichat
8cf4da0b19 uucore: format: Fix hexadecimal default format print
The default hex format, on x86(-64) prints 15 digits after the
decimal point, _but_ also trims trailing zeros, so it's not just
a simple default precision and a little bit of extra handling is
required.

Also add a bunch of tests.

Fixes #7364.
2025-04-01 15:04:47 +02:00
Nicolas Boichat
3f24796c8d uucore: format: Use Option for Float precision
The default precision for float actually depends on the format.
It's _usually_ 6, but it's architecture-specific for hexadecimal
floats.

Set the precision as an Option, so that:
 - We don't need to sprinkle `6` in callers
 - We can actually handle unspecified precision correctly in
   float printing (next change).
2025-04-01 15:04:47 +02:00
Nicolas Boichat
3ab68bad10 uucore: format: Fix hexadecimal uppercase print (again)
When '%A' format is specified, we also need to capitalize the
`0x`, i.e. `0XEP-3`, not `0xEP-3`.
2025-04-01 15:04:47 +02:00
Dorian Péron
17d81bb9a1
Merge pull request #7623 from drinkcat/parse-bigdecimal-smallfixes
uucore: format: Collection of small parser fixes
2025-04-01 12:36:28 +02:00
Dorian Péron
fb165850a4
Merge pull request #7567 from MoSal/faster_sort_n
sort: immediately compare whole lines if they parse as numbers
2025-04-01 12:14:29 +02:00
Nicolas Boichat
bdc8cd12a1 uucore: format: Remove TODO
Not much more that can be easily simplified now.
2025-04-01 11:20:17 +02:00
Nicolas Boichat
a46da8d0b9 uucore: format: num_parser: Allow uppercase exponent
1E3 and 0x1P3 are acceptable numbers.

Sprinkle uppercase values in the tests.
2025-04-01 11:20:17 +02:00
Nicolas Boichat
16131b8d7b uucore: format: num_parser: underflow/overflow check
When parsing floating point numbers, return errors if we end up
overflowing/underflowing BigDecimal (e.g. with large/small exponents).
2025-04-01 11:20:17 +02:00
Nicolas Boichat
1e104b7ef9 uucore: format: num_parser: Add value to Overflow error
When parsing integers, we should still return the min/max value
of the type (depending on the type), and wrap that in the error.

We need to refactor the map function to handle this case better,
and add an extract function to get the value out of an error
(if any).

This fixes the integer part of #7508.
2025-04-01 11:20:17 +02:00
Nicolas Boichat
9872263a96 uucore: format: Fix i64::MIN printing
-i64::MIN overflows i64, so cast to i128 first.
2025-04-01 11:20:17 +02:00
Nicolas Boichat
5bea6ff013 uucore: format: num_parser: Carve out part of parse function
We'll need more logic in there.
2025-04-01 11:20:17 +02:00
Nicolas Boichat
0cb37c83b9 uucore: format: num_parser: "infinity" string parsing
Not just "inf" is allowed, also "infinity".
2025-04-01 11:20:17 +02:00
Nicolas Boichat
5c06dd580b uucore: format: extendedbigdecimal: Implement Neg trait
This is useful and will simplify some of the parsing logic later.
2025-04-01 11:20:17 +02:00
Dorian Péron
ace92dcca1
Merge pull request #7556 from drinkcat/parse-bigdecimal
uucore: format: num_parser: Use ExtendedBigDecimal
2025-04-01 10:52:50 +02:00
GTimothy
09a9dc72b9 checksum/cksum: fix: filename that include separator should parse + add tests
fixes this non-regex implementation's flaw with file_names containing
the separator's pattern:
 - replaces left-to-right greedy separator match with right-to-left one.
 - added bugfix tests
fixes secondary bug: positive match on hybrid posix-openssl format
adds secondary bugfix tests

Co-authored-by: Dorian Péron
<72708393+RenjiSann@users.noreply.github.com>
2025-03-31 17:18:18 +02:00
GTimothy
04ad55510b checksum/cksum: update tests to test new parsers not regex 2025-03-31 17:18:18 +02:00
GTimothy
621f2b5c7a checksum/cksum: rewrite lineformat parsing without regex
removes dependency on the regex crate for LineFormat detection and
parsing, resulting in a faster and lighter cksum binary.
2025-03-31 17:18:18 +02:00
Nicolas Boichat
30c89af9ac uucore: format: num_parser: Make it clear that scale can only be positive
After scratching my head a bit about why the hexadecimal code works,
seems better to do make scale an u64 to clarify.

Note that this may u64 may exceed i64 capacity, but that can only
happen if the number of digits provided > 2**63 (impossible).
2025-03-31 10:04:08 +02:00
Nicolas Boichat
bd68eb8beb uucore: format: num_parser: Parse exponent part of floating point numbers
Parse numbers like 123.15e15 and 0xfp-2, and add some tests
for that.

`parse` is becoming more and more of a monster: we should consider
splitting it into multiple parts.

Fixes #7474.
2025-03-31 10:04:08 +02:00
Nicolas Boichat
55773e9d35 uucore: format: num_parser: Fix large hexadecimal float parsing
Large numbers can overflow u64 when doing 16u64.pow(scale):
do the operation on BigInt/BigDecimal instead.

Also, add a test. Wolfram Alpha can help confirm the decimal number
is correct (16-16**-21).
2025-03-31 10:04:08 +02:00
Nicolas Boichat
b5a658528b uucore: format: Use ExtendedBigDecimal in argument code
Provides arbitrary precision for float parsing in printf.

Also add a printf test for that.
2025-03-31 10:04:08 +02:00
Nicolas Boichat
71a285468b uucore: format: num_parser: Add parser for ExtendedBigDecimal
Very simple as the f64 parser actually uses that as intermediary
value.

Add a few tests too.
2025-03-31 10:04:08 +02:00
Nicolas Boichat
d7502e4b2e uucore: format: num_parser: Disallow binary number parsing for floats
Fixes #7487.

Also, add more tests for leading zeros not getting parsed as octal
when dealing with floats.
2025-03-31 10:04:08 +02:00
Nicolas Boichat
97e333c6d9 uucore: format: num_parser: allow leading + sign when parsing
Leading plus signs are allowed for all formats.

Add tests (including some tests for negative i64 values, and mixed
case special values that springed to mind).

Fixes #7473.
2025-03-31 10:04:08 +02:00
Nicolas Boichat
40a7c65980 uucore: format: num_parser: Turn parser into a trait
We call the function extended_parse, so that we do not clash
with other parsing functions in other traits.

- Also implement parser for ExtendedBigDecimal (straightforward).
- Base doesn't need to be public anymore.
- Rename the error to ExtendedParserError.
2025-03-31 10:04:08 +02:00
Nicolas Boichat
8bbec16115 uucore: format: num_parser: Fold special value parsing in main parsing function 2025-03-31 10:04:08 +02:00
Nicolas Boichat
20add88afc uucore: format: num_parser: Use ExtendedBigDecimal for internal representation
ExtendedBigDecimal already provides everything we need, use that
instead of a custom representation.
2025-03-31 10:04:08 +02:00