Identify retained-line positions containing bytes below 32 or DEL while leaving Unicode text otherwise uninterpreted. Work only with supplied input; this does not contact external services or modify input.
Before you start
- Save as recipe.rs and compile with Rust 1.99.0 using: rustc --edition=2021 recipe.rs -o recipe
- Run ./recipe without arguments, supplying input through stdin. Help flags and all other arguments are invalid.
- Input must contain at most 65536 bytes, be strict UTF-8, have no leading UTF-8 BOM, and contain no CR bytes.
- Only LF separates lines. Exactly empty segments are discarded; whitespace-only segments are retained. No trimming, normalization, grouping, or deduplication occurs.
- At most 100 nonempty lines are allowed, each containing at most 256 UTF-8 bytes. All input and line limits are validated before classification.
- Successful output is exactly one JSON object followed by a newline, with one-based retained-line positions in ascending order. A position is included if its line contains U+0000 through U+001F or U+007F. LF is a separator, and CR is invalid. Other Unicode characters are not classified as ASCII controls.
- Empty input or input containing only LF separators produces {"positions":[]}.
- Success exits 0 and writes no stderr. Invalid arguments, invalid input, and stdin-read failures exit 2 with no stdout and exactly error: invalid input followed by a newline on stderr, subject to the failure limitations below.
Build and check
- Save the example as recipe.rs.
- Compile with Rust 1.99.0 using rustc --edition=2021 recipe.rs -o recipe.
- Prepare UTF-8 input.txt following the documented operation-specific conventions.
- Run ./recipe < input.txt.
- Inspect the JSON result. Exit 2 with exactly error: invalid input followed by a newline on stderr and no stdout identifies rejected input or stdin-read failure. Output-write failures may also exit nonzero, without that diagnostic and potentially after partial stdout; these are outside the input-error guarantee.
Limits to understand
- The program requests at most 65537 bytes from stdin. Observing byte 65537 immediately rejects oversized input without reading further.
- Stdin can block while awaiting data or EOF. Even exactly 65536 bytes require another read to establish EOF or detect an extra byte.
- Memory use includes a fixed 65537-byte input buffer, metadata for at most 100 borrowed line slices, a small output string, and standard-library I/O overhead. Input text is not copied per line.
- Successful output can be sensitive: it reveals which retained lines contain ASCII controls. Handle stdout accordingly.
- Memory-allocation failures and stdout/stderr write or flush failures are outside the input-error guarantee. Output-write failures attempt exit status 2 and may leave partial stdout; diagnostic-write failures may prevent the required stderr message.
- The implementation uses only the standard library and permitted APIs. It performs no filesystem access, networking, subprocess execution, or dynamic loading.
Run it
rustc --edition=2021 recipe.rs -o recipe
./recipe < input.txtExample input
hello
a b
é
Expected output
{"positions":[2,3]}
