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

Abierto
#15,864 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
74/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
cli

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Rust
Estrellas
24.3k
Forks
2.1k
Merge medio
1 d 20 h
PR fusionados (30 d)
380

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de uutils/coreutils

Todos los issues de uutils/coreutils

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.