Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request implements the
tr
command, which is documented in section 9.1tr
: Translate, squeeze, and/or delete characters.One aspect of this implementation of
tr
that differs from GNU coreutils is how each character is handled. GNU coreutils processes byte-for-byte, not taking into account multibyte codepoints. This implementation, however, processes codepoint-for-codepoint. Here are some examples.echo old | tr old new
: Translating a single-byte codepoint to another single-byte codepoint works the same between this implementation and GNU coreutils' implementation.111 108 100
110 101 119
110 101 119
echo ! | tr ! ❗
: Translating a single-byte codepoint into a multibyte codepoint. The GNU implementation only replaces the first byte (226
), which means programs that expect UTF-8 encoded data might render the replacement codepoint � (U+FFFD) in its place to represent incomplete data33
226 157 151
226
If replacing entire codepoints is undesirable, it's very easy to revert to the byte-for-byte behavior.
As of now, this is what is implemented
tr <arg1> <arg2>
tr -d <arg>
,tr --delete <arg>
tr -t <arg1> <arg2>
,tr --truncate-set1 <arg1> <arg2>
tr -s <arg1> <arg2>
,tr --squeeze-repeats <arg1> <arg2>
tr -c <arg1> <arg2>
,tr --complement <arg1> <arg2>