Documentation
¶
Index ¶
- Constants
- Variables
- func Average[T Number](values ...T) T
- func CountRunes(slice []rune, target rune) int
- func Equal[X, Y any](x X, y Y) bool
- func FindLine[T ~int, B []rune | []byte | string](content B, index T) int
- func FindLineFromReader[T ~int](r *bytes.Reader, index T) int
- func Format[T any](args ...T) string
- func FuzzyEqual(x, y string) bool
- func IsPrime(n u32) bool
- func NextPrime(n u32) u32
- func PJWHash(str string) uint32
- func SafeSliceAccess[T any](slice []T, index int) T
- func ShouldSkipFile(w *krfs.Walker, excludedPaths []string, seenMap *map[string]bool, ...) bool
- type Endianness
- type Number
Constants ¶
View Source
const ( BigEndianMagicNumber uint32 = 0xde120495 LittleEndianMagicNumber uint32 = 0x950412de )
Variables ¶
View Source
var IsBigEndian = (*[2]uint8)(unsafe.Pointer(&[]uint16{1}[0]))[0] == 0
View Source
var NativeEndianOrder = func() binary.ByteOrder { if IsBigEndian { return binary.BigEndian } return binary.LittleEndian }()
Functions ¶
func CountRunes ¶
func FindLine ¶
FindLine returns the line number (1-based) for a given index within the content. The function accepts content as string, []rune, or []byte and determines the line number by counting newline characters ('\n') that appear before the specified index.
Generic Parameters:
- T: integer numeric type for the index (constrained to integer types)
- B: content type, constrained to []rune, []byte, or string
Parameters:
- content: the content to analyze (string, []rune, or []byte)
- index: position in the content for which to determine the line number
Returns:
- int: line number (starting from 1) corresponding to the index
- returns -1 if the index is out of range (negative or greater than content length)
Example usage:
text := "Line 1\nLine 2\nLine 3" lineNum := FindLine(text, 10) // Returns 2, as index 10 is on the second line
The function internally handles different content types:
- For strings: uses strings.Count to count '\n' occurrences
- For []rune: uses an auxiliary CountRunes function
- For []byte: uses bytes.Count to count '\n' occurrences
Implementation notes:
- The function uses a type assertion to determine the content type at runtime
- Counts the number of newline characters ('\n') before the given index
- Returns line number starting from 1
- Returns -1 if the index is out of bounds (negative or exceeding content length)
Edge cases:
- If the content is empty or the index is out of range, the function returns -1.
func FuzzyEqual ¶
func PJWHash ¶ added in v2.3.0
PJWHash computes a hash value for a string using the PJW (Elf) hash algorithm.
func SafeSliceAccess ¶
Types ¶
type Endianness ¶ added in v2.3.0
type Endianness int
const ( NativeEndian Endianness = iota LittleEndian BigEndian )
func (Endianness) MagicNumber ¶ added in v2.3.0
func (e Endianness) MagicNumber() uint32
func (Endianness) Order ¶ added in v2.3.0
func (e Endianness) Order() binary.ByteOrder
func (Endianness) String ¶ added in v2.3.0
func (e Endianness) String() string
Click to show internal directories.
Click to hide internal directories.