Build your own grep
Stage 3 of 7v2 · f4edd4c8

Case-insensitive matching

Implement case-insensitive comparison behind an explicit flag.

Case-insensitive matching

Implement case-insensitive comparison behind an explicit flag. This stage adds one observable capability to the project; keep every operation from earlier stages working.

Model and contract

The harness reads one JSON request from stdin and returns one compact JSON response. The request models arguments, files, and text without depending on the runner filesystem.

Representative input:

{ "op": "search", "pattern": "error", "text": "OK\nError 42\n", "flags": ["i"] }

Exact output:

{ "matches": ["Error 42"], "exit": 0 }

The output ends with a newline. For an invalid request, leave stdout empty, write a diagnostic containing error to stderr, and exit with a non-zero status.

How to approach it

Keep input parsing, core logic, and output serialization separate. First write down the invariants behind “case-insensitive matching”, walk through the example by hand, and exercise boundaries before optimizing. Do not replace the mechanism taught by this stage with a library function that solves it completely.

Pay particular attention to empty inputs, index or length boundaries, and malformed data. The result must be deterministic: preserve the ordering required by the request and emit compact JSON.

Acceptance criteria

  • The representative input produces exactly the output shown.
  • Invalid input follows the stderr and exit-status contract.
  • Capabilities from earlier stages keep working.