mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
nl: Don't output a new line on empty file
This commit is contained in:
parent
bccd12f297
commit
aa8b8ddd57
Notes:
sideshowbarker
2024-07-17 02:37:08 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/aa8b8ddd57 Pull-request: https://github.com/SerenityOS/serenity/pull/19305
1 changed files with 3 additions and 3 deletions
|
@ -68,10 +68,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto file = maybe_file.release_value();
|
||||
|
||||
int line_number = start_number - increment; // so the line number can start at 1 when added below
|
||||
int previous_character = 0;
|
||||
Optional<u8> previous_character;
|
||||
u8 next_character;
|
||||
for (Bytes bytes = TRY(file->read_some({ &next_character, 1 })); bytes.size() != 0; bytes = TRY(file->read_some(bytes))) {
|
||||
if (previous_character == 0 || previous_character == '\n') {
|
||||
if (!previous_character.has_value() || previous_character == '\n') {
|
||||
if (next_character == '\n' && number_style != NumberAllLines) {
|
||||
// Skip printing line count on empty lines.
|
||||
outln();
|
||||
|
@ -86,7 +86,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
previous_character = next_character;
|
||||
}
|
||||
|
||||
if (previous_character != '\n')
|
||||
if (previous_character.has_value() && previous_character != '\n')
|
||||
outln(); // for cases where files have no trailing newline
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue