package main

import (
	"fmt"
	"strconv"
	"strings"
)

func ConvertStringUint32(s string) (uint32, error) {
	v, err := strconv.ParseUint(s, 10, 32)
	return uint32(v), err
}

func ConvertStringToRgb(str string) ([3]uint8, error) {
	parts := strings.SplitN(str, ",", 4)
	if len(parts) != 3 {
		return [3]uint8{}, fmt.Errorf("invalid rgb")
	}
	var rgb [3]uint8
	for i, p := range parts {
		n, err := strconv.ParseUint(strings.TrimSpace(p), 10, 8)
		if err != nil {
			return [3]uint8{}, fmt.Errorf("invalid component %d: %w", i, err)
		}
		rgb[i] = uint8(n)
	}
	return rgb, nil
}
