add split string func
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// InterpolateColor calculates a color between two given colors based on progress (0 to 1)
|
||||
func InterpolateColor(start, end string, progress float64) string {
|
||||
r1, g1, b1 := HexToRGB(start)
|
||||
r2, g2, b2 := HexToRGB(end)
|
||||
|
||||
r := int(math.Round(float64(r1)*(1-progress) + float64(r2)*progress))
|
||||
g := int(math.Round(float64(g1)*(1-progress) + float64(g2)*progress))
|
||||
b := int(math.Round(float64(b1)*(1-progress) + float64(b2)*progress))
|
||||
|
||||
return fmt.Sprintf("#%02x%02x%02x", r, g, b)
|
||||
}
|
||||
|
||||
// Helper function to convert hex to RGB
|
||||
func HexToRGB(hex string) (int, int, int) {
|
||||
var r, g, b int
|
||||
_, err := fmt.Sscanf(hex, "#%02x%02x%02x", &r, &g, &b)
|
||||
if err != nil {
|
||||
return 0, 0, 0
|
||||
}
|
||||
return r, g, b
|
||||
}
|
||||
18
utils/splitStrings.utils.go
Normal file
18
utils/splitStrings.utils.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package utils
|
||||
|
||||
import "strings"
|
||||
|
||||
func SplitStrings(text string, count int) string {
|
||||
words := strings.Split(text, " ")
|
||||
var result strings.Builder
|
||||
|
||||
for i := 0; i < len(words); i += count {
|
||||
if i+count < len(words) {
|
||||
result.WriteString(strings.Join(words[i:i+count], " ") + "\n")
|
||||
} else {
|
||||
result.WriteString(strings.Join(words[i:], " "))
|
||||
}
|
||||
}
|
||||
|
||||
return result.String()
|
||||
}
|
||||
Reference in New Issue
Block a user