Documentation

QedShareCli.LineSpec

What the line cutter returns #

LineCut cuts a stream of chunks into lines as the chunks arrive. linesSpec says what the lines of a text are, on the whole text as a list of bytes: cut at every line feed, number the lines from 1, take the byte order mark off the first one, drop the blank ones.

cutLines_eq proves that cutLines returns exactly that for the chunks put together. So where the chunks end does not matter (cutLines_chunks), and no line is lost, joined or split. lineRanges_eq proves the same cut for the ranges used on a text held as a whole.

Split a list of bytes at every line feed.

Equations
Instances For

    Number lines, starting at no.

    Equations
    Instances For

      A numbered line as the cutter returns it: as a byte array, without a byte order mark if it is line 1.

      Equations
      Instances For

        The lines of a text: cut at every line feed, numbered from 1, the first without a byte order mark, the blank ones dropped.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          splitLF always returns at least one line.

          Bytes without a line feed are one line.

          theorem QedShare.Cli.splitLF_append (f rest : List UInt8) (h : ¬10 ∈ f) :
          splitLF (f ++ 10 :: rest) = f :: splitLF rest

          A line without a line feed, a line feed, then the rest: that line, then the rest's lines.

          The bytes of two arrays put together.

          theorem QedShare.Cli.feedLoop_spec (c : ByteArray) (n p start : Nat) (st : LineCut) (out : Array (Nat × ByteArray)) (hsp : start ≤ p) (hps : p ≤ c.size) (hn : c.size - p < n) (hbuf : ¬10 ∈ st.buf.data.toList ++ segB c start p) :
          ∃ (X : List (Nat × List UInt8)), (LineCut.feedLoop c n p start st out).snd.toList = out.toList ++ List.map lineOut X ∧ ¬10 ∈ (LineCut.feedLoop c n p start st out).fst.buf.data.toList ∧ ∀ (R : List UInt8), number st.lineNo (splitLF (st.buf.data.toList ++ segB c start c.size ++ R)) = X ++ number (LineCut.feedLoop c n p start st out).fst.lineNo (splitLF ((LineCut.feedLoop c n p start st out).fst.buf.data.toList ++ R))

          What LineCut.feedLoop does from byte p of a chunk on, when the current line (the kept bytes, then bytes start to p of the chunk) has no line feed: it returns some lines X, and for any text R that follows, the lines of everything are X, then the lines of the new kept bytes and R, numbered from the new line number.

          What LineCut.feed does with a chunk (see feedLoop_spec).

          The step of cutLines: feed one chunk, keep the lines.

          Equations
          Instances For

            What feeding a list of chunks does (see feedLoop_spec).

            theorem QedShare.Cli.cutLines_eq (chunks : List ByteArray) :
            cutLines chunks = linesSpec (List.flatMap (fun (x : ByteArray) => x.data.toList) chunks)

            cutLines returns the lines of the text. For any way of cutting a text into chunks, cutLines on the chunks gives the numbered non-blank lines of the whole text (linesSpec).

            Where the chunks end does not matter: two ways of cutting the same text into chunks give the same lines.

            theorem QedShare.Cli.lineRangesFrom_spec (bs : ByteArray) (n start i : Nat) (acc : Array (Nat × Nat)) (hsi : start ≤ i) (his : i ≤ bs.size) (hn : bs.size - i ≤ n) (hno : ¬10 ∈ segB bs start i) :
            List.map (fun (r : Nat × Nat) => segB bs r.fst r.snd) (lineRangesFrom bs n start i acc) = List.map (fun (r : Nat × Nat) => segB bs r.fst r.snd) acc.toList ++ splitLF (segB bs start bs.size)

            What lineRangesFrom does from byte i on, when the current line (bytes start to i) has no line feed.

            theorem QedShare.Cli.lineRanges_eq (bs : ByteArray) (start : Nat) (h : start ≤ bs.size) :
            List.map (fun (r : Nat × Nat) => segB bs r.fst r.snd) (lineRanges bs start) = splitLF (segB bs start bs.size)

            lineRanges cuts at every line feed: the byte ranges it returns are the lines of the bytes from start on.