Documentation

Init.Data.String.PosRaw

Arithmetic of String.Pos.Raw #

This file contains basic theory about which does not actually need to know anything about strings and therefore does not depend on Init.Data.String.Decode.

theorem String.Pos.Raw.ext {x y : Raw} (byteIdx : x.byteIdx = y.byteIdx) :
x = y
@[export lean_string_pos_sub]
Equations
    Instances For
      Equations
        Equations
          instance String.instDecidableLeRaw (p₁ p₂ : Pos.Raw) :
          Decidable (p₁ p₂)
          Equations
            instance String.instDecidableLtRaw (p₁ p₂ : Pos.Raw) :
            Decidable (p₁ < p₂)
            Equations
              @[simp]
              @[simp]
              @[simp]
              theorem String.Pos.Raw.le_iff {i₁ i₂ : Raw} :
              i₁ i₂ i₁.byteIdx i₂.byteIdx
              theorem String.Pos.Raw.lt_iff {i₁ i₂ : Raw} :
              i₁ < i₂ i₁.byteIdx < i₂.byteIdx
              @[inline]

              Returns the size of the byte slice delineated by the positions lo and hi.

              Equations
                Instances For
                  @[deprecated String.rawEndPos_empty (since := "2025-10-20")]
                  @[extern lean_string_get_byte_fast]
                  def String.getUTF8Byte (s : String) (p : Pos.Raw) (h : p < s.rawEndPos) :

                  Accesses the indicated byte in the UTF-8 encoding of a string.

                  At runtime, this function is implemented by efficient, constant-time code.

                  Equations
                    Instances For
                      @[reducible, inline, extern lean_string_get_byte_fast, deprecated String.getUTF8Byte (since := "2025-10-01")]
                      abbrev String.getUtf8Byte (s : String) (p : Pos.Raw) (h : p < s.rawEndPos) :
                      Equations
                        Instances For
                          theorem String.Pos.Raw.le_trans {a b c : Raw} :
                          a bb ca c
                          theorem String.Pos.Raw.lt_of_lt_of_le {a b c : Raw} :
                          a < bb ca < c
                          @[inline]
                          def String.Pos.Raw.offsetBy (p offset : Raw) :

                          Offsets p by offset on the left. This is not an HAdd instance because it should be a relatively rare operation, so we use a name to make accidental use less likely. To offset a position by the size of a character character c or string s, you can use c + p resp. s + p.

                          This should be seen as an operation that converts relative positions into absolute positions.

                          See also Pos.Raw.increaseBy, which is an "advancing" operation.

                          Equations
                            Instances For
                              @[simp]
                              theorem String.Pos.Raw.byteIdx_offsetBy {p offset : Raw} :
                              (p.offsetBy offset).byteIdx = offset.byteIdx + p.byteIdx
                              @[inline]

                              Decreases p by offset. This is not an HSub instance because it should be a relatively rare operation, so we use a name to make accidental use less likely. To unoffset a position by the size of a character c or string s, you can use p - c resp. p - s.

                              This should be seen as an operation that converts absolute positions into relative positions.

                              See also Pos.Raw.decreaseBy, which is an "unadvancing" operation.

                              Equations
                                Instances For
                                  @[simp]
                                  theorem String.Pos.Raw.byteIdx_unoffsetBy {p offset : Raw} :
                                  (p.unoffsetBy offset).byteIdx = p.byteIdx - offset.byteIdx
                                  @[simp]
                                  theorem String.Pos.Raw.eq_zero_iff {p : Raw} :
                                  p = 0 p.byteIdx = 0
                                  @[inline]

                                  Advances p by n bytes. This is not an HAdd instance because it should be a relatively rare operation, so we use a name to make accidental use less likely. To add the size of a character c or string s to a raw position p, you can use p + c resp. p + s.

                                  This should be seen as an "advance" or "skip".

                                  See also Pos.Raw.offsetBy, which turns relative positions into absolute positions.

                                  Equations
                                    Instances For
                                      @[inline]

                                      Move the position p back by n bytes. This is not an HSub instance because it should be a relatively rare operation, so we use a name to make accidental use less likely. To remove the size of a character c or string s from a raw position p, you can use p - c resp. p - s.

                                      This should be seen as the inverse of an "advance" or "skip".

                                      See also Pos.Raw.unoffsetBy, which turns absolute positions into relative positions.

                                      Equations
                                        Instances For
                                          @[inline]

                                          Increases the byte offset of the position by 1. Not to be confused with Pos.next.

                                          Equations
                                            Instances For
                                              @[inline]

                                              Decreases the byte offset of the position by 1. Not to be confused with Pos.prev.

                                              Equations
                                                Instances For
                                                  @[simp]
                                                  theorem String.Pos.Raw.le_refl {p : Raw} :
                                                  p p
                                                  theorem String.Pos.Raw.le_of_lt {p q : Raw} :
                                                  p < qp q
                                                  theorem String.Pos.Raw.inc_le {p q : Raw} :
                                                  p.inc q p < q
                                                  theorem String.Pos.Raw.lt_of_le_of_lt {a b c : Raw} :
                                                  a bb < ca < c
                                                  theorem String.Pos.Raw.ne_of_lt {a b : Raw} :
                                                  a < ba b
                                                  @[deprecated String.Pos.Raw.lt_iff (since := "2025-10-10")]
                                                  theorem String.pos_lt_eq (p₁ p₂ : Pos.Raw) :
                                                  (p₁ < p₂) = (p₁.byteIdx < p₂.byteIdx)
                                                  @[deprecated String.Pos.Raw.byteIdx_add_char (since := "2025-10-10")]
                                                  theorem String.pos_add_char (p : Pos.Raw) (c : Char) :
                                                  theorem String.Pos.Raw.ne_zero_of_lt {a b : Raw} :
                                                  a < bb 0
                                                  @[reducible, inline]
                                                  abbrev String.Pos.Raw.min (p₁ p₂ : Raw) :

                                                  Returns either p₁ or p₂, whichever has the least byte index.

                                                  Equations
                                                    Instances For
                                                      @[export lean_string_pos_min]
                                                      Equations
                                                        Instances For
                                                          theorem String.Pos.Raw.byteIdx_mk (n : Nat) :
                                                          { byteIdx := n }.byteIdx = n
                                                          @[simp]
                                                          @[simp]
                                                          theorem String.Pos.Raw.mk_byteIdx (p : Raw) :
                                                          { byteIdx := p.byteIdx } = p
                                                          @[deprecated String.Pos.Raw.byteIdx_offsetBy (since := "2025-10-08")]
                                                          theorem String.Pos.Raw.add_byteIdx {p₁ p₂ : Raw} :
                                                          (p₂.offsetBy p₁).byteIdx = p₁.byteIdx + p₂.byteIdx
                                                          @[deprecated String.Pos.Raw.byteIdx_offsetBy (since := "2025-10-08")]
                                                          theorem String.Pos.Raw.add_eq {p₁ p₂ : Raw} :
                                                          p₂.offsetBy p₁ = { byteIdx := p₁.byteIdx + p₂.byteIdx }
                                                          @[deprecated String.Pos.Raw.byteIdx_unoffsetBy (since := "2025-10-08")]
                                                          theorem String.Pos.Raw.sub_byteIdx (p₁ p₂ : Raw) :
                                                          (p₁.unoffsetBy p₂).byteIdx = p₁.byteIdx - p₂.byteIdx
                                                          @[deprecated String.Pos.Raw.byteIdx_add_char (since := "2025-10-10")]
                                                          theorem String.Pos.Raw.add_char_eq (p : Raw) (c : Char) :
                                                          p + c = { byteIdx := p.byteIdx + c.utf8Size }
                                                          @[deprecated String.Pos.Raw.add_char_eq (since := "2025-10-10")]
                                                          theorem String.Pos.Raw.addChar_eq (p : Raw) (c : Char) :
                                                          p + c = { byteIdx := p.byteIdx + c.utf8Size }
                                                          @[deprecated String.Pos.Raw.byteIdx_zero_add_char (since := "2025-10-10")]
                                                          theorem String.Pos.Raw.zero_add_char_eq (c : Char) :
                                                          0 + c = { byteIdx := c.utf8Size }
                                                          @[deprecated String.Pos.Raw.zero_add_char_eq (since := "2025-10-10")]
                                                          theorem String.Pos.Raw.zero_addChar_eq (c : Char) :
                                                          0 + c = { byteIdx := c.utf8Size }
                                                          theorem String.Pos.Raw.add_char_right_comm (p : Raw) (c₁ c₂ : Char) :
                                                          p + c₁ + c₂ = p + c₂ + c₁
                                                          @[deprecated String.Pos.Raw.add_char_right_comm (since := "2025-10-10")]
                                                          theorem String.Pos.Raw.addChar_right_comm (p : Raw) (c₁ c₂ : Char) :
                                                          p + c₁ + c₂ = p + c₂ + c₁
                                                          theorem String.Pos.Raw.ne_of_gt {i₁ i₂ : Raw} (h : i₁ < i₂) :
                                                          i₂ i₁
                                                          @[deprecated String.Pos.Raw.byteIdx_add_string (since := "2025-10-10")]
                                                          theorem String.Pos.Raw.addString_eq (p : Raw) (s : String) :
                                                          p + s = { byteIdx := p.byteIdx + s.utf8ByteSize }
                                                          @[deprecated String.Pos.Raw.byteIdx_zero_add_string (since := "2025-10-10")]
                                                          @[deprecated String.Pos.Raw.zero_add_string_eq (since := "2025-10-10")]
                                                          theorem String.Pos.Raw.zero_addString_eq (s : String) :
                                                          0 + s = { byteIdx := s.utf8ByteSize }
                                                          @[simp]
                                                          theorem String.Pos.Raw.mk_le_mk {i₁ i₂ : Nat} :
                                                          { byteIdx := i₁ } { byteIdx := i₂ } i₁ i₂
                                                          @[simp]
                                                          theorem String.Pos.Raw.mk_lt_mk {i₁ i₂ : Nat} :
                                                          { byteIdx := i₁ } < { byteIdx := i₂ } i₁ < i₂