// MiniJsonLoader (Stage-B scaffold)
// Purpose: centralize minimal JSON cursor ops for Mini-VM.
// Implementation note: For now we delegate to local MiniJsonCur-compatible
// helpers. In a later step, this can be swapped to use `apps/libs/json_cur.hako`
// (JsonCursorBox) without touching Mini-VM call sites.

static box MiniJsonLoader {
  read_quoted_from(s, pos) {
    // Local fallback (same behavior as MiniJsonCur.read_quoted_from)
    // Keep in sync with Mini-VM until libs adoption gate is enabled.
    local i = pos
    if s.substring(i, i+1) != "\"" { return "" }
    i = i + 1
    local out = ""
    local n = s.length()
    loop (i < n) {
      local ch = s.substring(i, i+1)
      if ch == "\"" { break }
      if ch == "\\" { i = i + 1  ch = s.substring(i, i+1) }
      out = out + ch
      i = i + 1
    }
    return out
  }
  read_digits_from(s, pos) {
    local out = ""
    local i = pos
    if i == null { return out }
    if i < 0 { return out }
    loop (true) {
      local ch = s.substring(i, i+1)
      if ch == "" { break }
      if ch == "0" || ch == "1" || ch == "2" || ch == "3" || ch == "4" || ch == "5" || ch == "6" || ch == "7" || ch == "8" || ch == "9" {
        out = out + ch
        i = i + 1
      } else { break }
    }
    return out
  }
  next_non_ws(s, pos) {
    local i = pos
    local n = s.length()
    loop (i < n) {
      local ch = s.substring(i, i+1)
      if ch != " " && ch != "\n" && ch != "\r" && ch != "\t" { return i }
      i = i + 1
    }
    return -1
  }
}

