utils

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculatePercentage

func CalculatePercentage(value, total int, decimalPlaces int) float64

CalculatePercentage calculates (value / total) * 100 with specific truncation. decimalPlaces controls the number of decimal places in the result. Mimics C# ReportGenerator.Core.Common.MathExtensions.CalculatePercentage.

func FindFileInSourceDirs

func FindFileInSourceDirs(relativePath string, sourceDirs []string, reader filereader.Reader, logger *slog.Logger) (string, error)

FindFileInSourceDirs resolves a file path from a report against a list of source directories.

func FormatPercentage

func FormatPercentage(percentage float64, decimalPlaces int) string

FormatPercentage formats a float64 percentage value (0-100) as a string with a specific number of decimal places, appending "%". Handles NaN by returning "N/A".

func IsValidUnixSeconds

func IsValidUnixSeconds(ts int64) bool

isValidUnixSeconds checks if a timestamp (in seconds) is within a reasonable range. E.g., between 1975-01-01 and 2100-01-01.

func SortByLineAndName

func SortByLineAndName[T SortableByLineAndName](slice []T)

SortByLineAndName sorts a slice of items that implement SortableByLineAndName. Items are sorted by their first line number, then by their sortable name. Items with a FirstLine of 0 (or less) are typically pushed to the end or handled as per specific needs. This implementation pushes items with FirstLine 0 to the end if other items have non-zero FirstLine.

Types

type SortableByLineAndName

type SortableByLineAndName interface {
	GetFirstLine() int
	GetSortableName() string // This should return a name suitable for lexicographical sorting.
}

SortableByLineAndName defines an interface for items that can be sorted primarily by their first line number and secondarily by a sortable name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL