Documentation
¶
Index ¶
- Constants
- Variables
- func Average[T Number](values ...T) T
- func CountRunes(slice []rune, target rune) int
- func Diff(x, y any) string
- 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 NamedDiff(xname, yname string, x, y any) string
- func NextPrime(n u32) u32
- func PJWHash(str string) uint32
- func SafeSliceAccess[T any](slice []T, index int) T
- func SearchSymbol(t lexer.TokenType) string
- func ShouldSkipFile(w *krfs.Walker, excludedPaths []string, seenMap *map[string]struct{}, ...) bool
- type Endianness
- type MoHeader
- type Number
Constants ¶
View Source
const ( BigEndianMagicNumber uint32 = 0xde120495 LittleEndianMagicNumber uint32 = 0x950412de )
Variables ¶
View Source
var ( PoSymbols = PoLexer.Symbols() PoRules = []lexer.SimpleRule{ {Name: "WS", Pattern: `\s+`}, {Name: "Integer", Pattern: `\d+`}, {Name: "LB", Pattern: `\[`}, {Name: "RB", Pattern: `\]`}, {Name: "String", Pattern: `"(\\"|[^"])*"`}, {Name: "Msgctxt", Pattern: "msgctxt"}, {Name: "MsgidPlural", Pattern: "msgid_plural"}, {Name: "Msgid", Pattern: "msgid"}, {Name: "Msgstr", Pattern: "msgstr"}, {Name: "Comment", Pattern: "#[^\n]*"}, } PoLexer = lexer.MustSimple(PoRules) PoParser = participle.MustBuild[poFile]( participle.Lexer(PoLexer), participle.Unquote("String"), participle.Elide( "WS", "Comment", ), ) )
View Source
var IsBigEndian = cpu.IsBigEndian
View Source
var LitterOptions = litter.Options{ HidePrivateFields: true, HideZeroValues: true, }
View Source
var NativeEndianOrder = func() binary.ByteOrder { if IsBigEndian { return binary.BigEndian } return binary.LittleEndian }()
View Source
var SupportedCharsets = map[string]bool{ "ASCII": true, "ISO-8859-1": true, "ISO-8859-2": true, "ISO-8859-3": true, "ISO-8859-4": true, "ISO-8859-5": true, "ISO-8859-6": true, "ISO-8859-7": true, "ISO-8859-8": true, "ISO-8859-9": true, "ISO-8859-13": true, "ISO-8859-14": true, "ISO-8859-15": true, "KOI8-R": true, "KOI8-U": true, "KOI8-T": true, "CP850": true, "CP866": true, "CP874": true, "CP932": true, "CP949": true, "CP950": true, "CP1250": true, "CP1251": true, "CP1252": true, "CP1253": true, "CP1254": true, "CP1255": true, "CP1256": true, "CP1257": true, "GB2312": true, "EUC-JP": true, "EUC-KR": true, "EUC-TW": true, "BIG5": true, "BIG5-HKSCS": true, "GBK": true, "GB18030": true, "SHIFT_JIS": true, "JOHAB": true, "TIS-620": true, "VISCII": true, "GEORGIAN-PS": true, "UTF-8": true, }
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 ¶
func SearchSymbol ¶ added in v2.4.0
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.