Ben Wiederhake
a8b9e042e1
tr: properly determine trailing backslash
...
Fixes #6729 .
2024-09-24 02:23:58 +02:00
Andrew Liebenow
08992ec6b3
tr: fix unescaped trailing backslash warning
...
This warning is being emitted whenever the input string ends with a
backslash, even if the backslash is escaped.
2024-09-18 17:29:11 -05:00
Ben Wiederhake
471f047a64
clippy: simplify code according to nightly 'byte_char_slices' lint
...
https://rust-lang.github.io/rust-clippy/master/index.html#/byte_char_slices
2024-07-18 15:59:36 +02:00
Dorian Péron
9ab7fa9806
tr: accept non utf8 arguments for sets
2024-07-18 13:00:32 +02:00
Dorian Péron
128335a24b
tr: Raise error if set2 is too big on complemented class
2024-07-15 17:55:40 +02:00
Christian von Elm
866366a874
tr: correctly detected matched [:upper:]
...
tr detects if a class in set2 is matched by a class at the correct position in set1 after it has expanded everything before the class in both sets:
So
tr 'abcd[:upper:]' 'a-d[:lower:]'
should not fail
2024-06-30 14:24:00 +02:00
Christian von Elm
0ae6d43536
Refuse to translate if set2 contains more than one unique characters and set1 contains a character class ( #6472 )
...
* Refuse to translate if set2 contains > 1 unique characters
2024-06-22 19:30:39 +02:00
Christian von Elm
a46e4fd290
Refuse to translate if set1 is longer than set2 and set2 ends in a character class
...
tr [:lower:]a [:upper:]
fails in GNU tr, so print an error for tr too.
2024-06-15 12:38:19 +02:00
Christian von Elm
7e8aaa8ad4
tr: A [:lower:]/[:upper:] in set2 must be matched in set1
...
If there is a [:lower:] or [:upper:] in set2, then there must be a [:lower:] or [:upper:] at the
same logical position in set1
So
tr -t [:upper:] [:lower:] works
tr -t 1[:upper:] [:lower:] doesnt
2024-06-02 14:22:17 +02:00
Christian von Elm
0d1bde2879
tr: disallow classes besides [:upper:]/[:lower:] in set2 when translating
...
Fixes issue #6342
2024-05-23 22:06:57 +02:00
Jalil David Salamé Messina
ff1a03c284
tr: don't truncate when not translating
...
An additional issue was found while reviewing #6340 , check [this thread][1]. A summary is:
- `tr` ignores the `-t`/`--truncate-set1` flag when not translating
- Not translating is defined as `-d` was passed, or one set was passed.
[1]: https://github.com/uutils/coreutils/pull/6340#discussion_r1590007053
2024-05-04 19:55:49 +02:00
Jalil David Salamé Messina
3c47f27698
tr: calculate complement set early
...
Fixes #6163 and adds a test to verify that a regression is not caused.
Instead of inverting the conditions to check (e.g. delete characters **not** present in set1) invert
set1 when passed the complement flag (`-c`, `-C`, `--complement`). This is done by calculating set1
then "inverting" it by subtracting from the "full" (universe) set (0..=u8::MAX).
This fixes issue 6163 because it was caused by a combination of the `-c` and `-t` flag. `-c` is the
abovementioned complement flag and `-t`/`--truncate-set1` truncates set1 to the length of set2. What
happened in issue 6163 is that `set1={b'Y'}` and `set2={b'Z'}`, when truncated set1 stays the same
and we proceed. The problem is GNU utils does not consider set1 to be `{b'Y'}`, but the complement
of `{b'Y'}`, that is `U \ {b'Y'}={0, 1, ..., b'X', b'Z', ...}`, thus it is truncated to `{0}`.
We can verify this by doing: `printf '\0' | tr -c -t Y Z`, which prints `Z` to stdout as expected.
Additionally, by calculating the complement of set1 we no longer need to consider the complement
flag when doing the translate operation, this allows us to delete a lot of code.
2024-05-04 19:55:49 +02:00
Ben Wiederhake
909c47886a
tr+tests: remove unused spell-checker:disable
2024-04-30 18:28:20 +02:00
Ben Wiederhake
e9045be593
tr: fix order inside class [:blank:]
2024-03-29 00:55:34 +01:00
Ben Wiederhake
76a2f2128b
tr: guard against regressions of class [:space:]
2024-03-29 00:50:33 +01:00
Ben Wiederhake
44310f426c
tr: enable passing -t multiple times
2024-02-24 18:37:45 +01:00
Ben Wiederhake
268af90843
tr: enable passing -s multiple times
2024-02-24 18:37:45 +01:00
Ben Wiederhake
dc664006fe
tr: enable passing -d multiple times
2024-02-23 11:58:22 +01:00
Ben Wiederhake
cad94a69be
tr: prevent passing options in the wrong place
...
Note: This requires using the DEPRECATED item Command::trailing_var_arg
in clap. This is going to be another
[problem with clap](https://github.com/tertsdiepraam/uutils-args/blob/main/docs/design/problems_with_clap.md ).
2024-02-23 11:58:22 +01:00
Ben Wiederhake
d9b6675bbf
tr: enable passing -c multiple times
2024-02-23 11:58:18 +01:00
Ben Wiederhake
617f3a8b6f
tr: when deleting and squeezing, never complement set2
2024-02-23 06:08:37 +01:00
Ben Wiederhake
48c4b57c97
tr: require second string argument when deleting and squeezing
2024-02-23 03:23:07 +01:00
BaherSalama
5603305e75
fix tr with any flag with more than 2 operands ( #5952 )
...
* fix tr
* add tests
* fix clippy
* fix clippy2
* do suggestions
* do suggestions
* remove mut
* tr: move var to block & remove its type
---------
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2024-02-13 15:30:15 +01:00
Daniel Hofstetter
9995c637aa
tr: fix intermittent test caused by pipe_in()
2024-02-08 07:25:09 +01:00
BaherSalama
5c2ae5be4f
fix tr with delete flag if more than 1 operand given ( #5945 )
...
* fix tr
* fix
* adding a test
* tr: rename test function
---------
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2024-02-06 16:42:08 +01:00
Terts Diepraam
bc5b5e013a
tr: operate on bytes instead of chars
2023-12-11 13:35:17 +01:00
Sylvestre Ledru
bfca6bf70f
Add license headers on all files
2023-08-21 10:49:27 +02:00
Daniel Hofstetter
6988eb7ec6
tests: expand wildcard imports
2023-03-20 15:32:35 +01:00
Yang Hau
ec81a23afc
tr: Remove the extra newline in stderr
...
closes #4301
2023-02-15 02:04:43 +08:00
Joining7943
1fadeb43b2
tests/util: Do not trim stderr in CmdResult::stderr_is. Add method stderr_trimmed_is.
...
Fix tests assert whitespace instead of trimming it. Disable some tests in `test_tr` because `tr`
produces too many newlines.
2023-01-22 14:56:19 +01:00
Terts Diepraam
9177cb7b24
all: add tests for usage error exit code
2022-09-10 20:59:42 +02:00
DevSabb
b8a3795d95
tr: fix octal interpretation of repeat count string ( #3178 )
...
* tr: fix octal interpretation of repeat count string
* tr: fix formatting errors
* tr: fix formatting issues 2
* tr: attempt to bypass spell check error
* tr: fix spell check errors attempt 2
* tr: formatting fixes
Co-authored-by: DevSabb <devsabb@local>
2022-02-25 12:11:53 +01:00
Terts Diepraam
9ddd61ab6b
Merge branch 'main' into hbina-tr-reimplement-expansion
2022-01-21 14:42:30 +01:00
Terts Diepraam
9f649ffe9b
tr: fix flaky test
2022-01-19 22:33:54 +01:00
Hanif Ariffin
c86cb91dee
Merge branch 'master' of github.com:uutils/coreutils into hbina-tr-reimplement-expansion
2021-11-26 16:39:27 +08:00
Roy Ivy III
f07a1749a1
fix spell-check errors
2021-11-19 17:55:02 -06:00
Hanif Bin Ariffin
1dc438c9d9
Fix spell check ignore list
...
Use this small script:
```shell
<list> | tr ' ' '\n' | sort | uniq | tr '\n' ' '
```
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-09-19 23:26:49 +08:00
Hanif Bin Ariffin
e0d1bf9bba
Ignore some spell checks
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-09-19 23:15:42 +08:00
Hanif Bin Ariffin
9ab4f3de2f
Merge branch 'master' of github.com:uutils/coreutils into hbina-tr-reimplement-expansion
2021-09-19 23:01:48 +08:00
Sylvestre Ledru
1986d346dc
Silent 'test_more_than_2_sets' on freebsd
2021-09-05 18:54:43 +02:00
Hanif Bin Ariffin
186886cd69
Ignore 1 test that is failing only in Windows
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:07 +08:00
Hanif Bin Ariffin
106ba4b77d
Added one last missing test
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:07 +08:00
Hanif Bin Ariffin
d0b3a15994
Updated test ignore description
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:07 +08:00
Hanif Bin Ariffin
5bf0197da5
Added all GNU tests as rust tests
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:07 +08:00
Hanif Bin Ariffin
36c19293c8
Fixing tests
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:07 +08:00
Hanif Bin Ariffin
bf0f01714c
Splitting out GNU tests
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:07 +08:00
Hanif Bin Ariffin
b7a0ad15a7
Cleaning up tests
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:06 +08:00
Hanif Bin Ariffin
d5dbedb2e4
Added more tests
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:06 +08:00
Hanif Bin Ariffin
55b2eacb4b
Added gnu tests for tr (mostly as comments)
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:06 +08:00
Hanif Bin Ariffin
700ce7d64a
Removed useless tests that were supposed to be filled with tests from GNU tr
...
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-08-14 19:38:06 +08:00