<commit_before>package pagination

import (
	"fmt"
	"net/http"
	"net/url"
	"strconv"
	"strings"
)

const (
	// DefaultOffset is the standard offset chosen when nothing is provided
	DefaultOffset = 0
	// DefaultLimit is the standard limit chosen when nothing is provided
	DefaultLimit = 10
)

// AllItems is a convenience for requesting all items of a given entity
var AllItems = &Pagination{Offset: 0, Limit: -1}

// Pagination represents the necessary elements for a paginated request
type Pagination struct {
	Offset int
	Limit  int
}

// New takes an offset and limit.  It returns a newly created Pagination object
// and prevents the offset and limit from being set to illegal values.
func New(offset, limit int) *Pagination {
	p := &Pagination{
		Offset: offset,
		Limit:  limit,
	}

	if p.Offset < 0 {
		p.Offset = 0
	}

	if p.Limit < 1 {
		p.Limit = -1
	}

	return p
}

// ParseFromRequest parses pagination params from an http request. It will defer
// to defaults if the pagination params are not found.
func ParseFromRequest(req *http.Request) *Pagination {
	var oStr, lStr string

	if req.URL != nil {
		oStr = req.URL.Query().Get("offset")
		lStr = req.URL.Query().Get("limit")
	}

	if oStr == "" && lStr == "" && req.Header != nil {
		oStr = req.Header.Get("Offset")
		lStr = req.Header.Get("Limit")
	}

	if oStr == "" && lStr == "" {
		return New(DefaultOffset, DefaultLimit)
	}

	if oStr == "" {
		oStr = strconv.Itoa(DefaultOffset)
	}

	o, err := strconv.Atoi(oStr)
	if err != nil {
		o = DefaultOffset
	}

	if lStr == "" {<commit_msg>updating docs<commit_after>package pagination

import (
	"fmt"
	"net/http"
	"net/url"
	"strconv"
	"strings"
)

const (
	// DefaultOffset is the standard offset chosen when nothing is provided
	DefaultOffset = 0
	// DefaultLimit is the standard limit chosen when nothing is provided
	DefaultLimit = 10
)

// AllItems is a convenience for requesting all items of a given entity
var AllItems = &Pagination{Offset: 0, Limit: -1}

// Pagination represents the necessary elements for a paginated request
type Pagination struct {
	Offset int
	Limit  int
}

// New takes an offset and limit.  It returns a newly created Pagination object
// and prevents the offset and limit from being set to illegal values.
func New(offset, limit int) *Pagination {
	p := &Pagination{
		Offset: offset,
		Limit:  limit,
	}

	if p.Offset < 0 {
		p.Offset = 0
	}

	if p.Limit < 1 {
		p.Limit = -1
	}

	return p
}

// ParseFromRequest parses pagination params from an http request's query params
// or from the headers. The URL query params are favored over the header values
// if both are provided. It will defer to defaults if the pagination params are
// not found.
func ParseFromRequest(req *http.Request) *Pagination {
	var oStr, lStr string

	if req.URL != nil {
		oStr = req.URL.Query().Get("offset")
		lStr = req.URL.Query().Get("limit")
	}

	if oStr == "" && lStr == "" && req.Header != nil {
		oStr = req.Header.Get("Offset")
		lStr = req.Header.Get("Limit")
	}

	if oStr == "" && lStr == "" {
		return New(DefaultOffset, DefaultLimit)
	}

	if oStr == "" {
		oStr = strconv.Itoa(DefaultOffset)
	}

	o, err := strconv.Atoi(oStr)
	if err != nil {
		o = DefaultOffset
	}

	if lStr == "" {
{'fraction_non_alphanumeric': 0.11549208320397392, 'fraction_numerical': 0.005588326606643899, 'mean_word_length': 3.3248322147651006, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7357525', 'n_tokens_mistral': 1126, 'n_tokens_neox': 1064, 'n_words': 379}