ptx: contexts stop at line ends without -S, and -S drops the sentence end

Aperta
#15,864 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

Start in src/uu/ptx/src/ptx.rs, especially read_lines around line 327 and the -S handling around line 323. Compare default and -S output with the two examples in the issue, then check the ptx tests for coverage. Done means default mode joins contexts across lines as GNU ptx does, while -S preserves the matched sentence end and does not mark the final sentence as truncated.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Without -S, GNU ptx (in its default GNU mode) builds contexts from sentences, not lines: a sentence ends at ., ? or ! (optionally followed by closing quotes or brackets) that is followed by an end of line, a tab or two spaces, and lines in between are joined. uutils ptx uses each line on its own:

$ printf 'one two\nthree four\n' > f
$ ptx f
                               three   four
                                       one two
                                       three four
                                 one   two
$ gnuptx f    # GNU coreutils 9.12
                       one two three   four
                                       one two three four
                             one two   three four
                                 one   two three four

-G output matches, as there a line is the unit for both.

Passing a sentence regexp with -S gets closer, but two more differences show up there: the matched sentence end is dropped from the context, and the last sentence ends with a truncation flag because the final newline becomes a trailing space:

$ printf 'Hello world.  Foo bar\n' > g
$ ptx -S '\.  ' g
                                       Foo bar/
                                       Hello world
                                 Foo   bar/
                               Hello   world
$ gnuptx -S '\.  ' g
                                       Foo bar
                                       Hello world.
                                 Foo   bar
                               Hello   world.

The line split is buffer.lines() in read_lines (src/uu/ptx/src/ptx.rs:327); with -S, re.split(&buffer) throws away the matched text and s.replace('\n', " ") (ptx.rs:323) turns the final newline into the trailing space.

uutils coreutils main 91d4f6ada, GNU coreutils 9.12.

Lingua principale
Rust
Stelle
24.3k
Fork
2.1k
Merge medio
1g 20h
PR unite (30g)
380

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di uutils/coreutils

Tutte le issue di uutils/coreutils

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.