0 | module Text.ILex.LTENat
 1 |
 2 | import public Data.ByteString
 3 |
 4 | %default total
 5 |
 6 | public export
 7 | record LTENat (n : Nat) where
 8 |   constructor LN
 9 |   val : Nat
10 |   {auto 0 prf : LTE val n}
11 |
12 | export %inline
13 | lteNat : (0 m : Nat) -> Ix m n => LTENat n
14 | lteNat _ @{x} = LN (ixToNat x) @{ixLTE x}
15 |
16 | export %inline
17 | first : (0 n : Nat) -> LTENat n
18 | first n = LN 0
19 |
20 | export %inline
21 | last : (n : Nat) -> LTENat n
22 | last n = LN n
23 |
24 | export %inline
25 | bytesFromTill : IBuffer n -> (from, till : LTENat n) -> ByteString
26 | bytesFromTill buf (LN from @{lt1}) (LN till @{lt2}) =
27 |   BS (till `minus` from) (BV buf from $ plusMinusBothLTE _ _ lt1 lt2)
28 |
29 | export %inline
30 | stringFromTill : IBuffer n -> (from, till : LTENat n) -> String
31 | stringFromTill buf (LN from @{lt1}) (LN till @{lt2}) =
32 |   toString buf from (till `minus` from) @{plusMinusBothLTE _ _ lt1 lt2}
33 |