31 lines
599 B
Go
31 lines
599 B
Go
package html
|
|
|
|
import "strings"
|
|
|
|
// path.go: ParseBlockID extracts the slot sequence from a data-block ID.
|
|
// Example: ParseBlockID("L-0-C-0") returns []byte{'L', 'C'}.
|
|
func ParseBlockID(id string) []byte {
|
|
if id == "" {
|
|
return nil
|
|
}
|
|
|
|
// Split on "-" and require the exact structural pattern:
|
|
// slot, 0, slot, 0, ...
|
|
var slots []byte
|
|
i := 0
|
|
for part := range strings.SplitSeq(id, "-") {
|
|
if i%2 == 0 {
|
|
if len(part) != 1 {
|
|
return nil
|
|
}
|
|
slots = append(slots, part[0])
|
|
} else if part != "0" {
|
|
return nil
|
|
}
|
|
i++
|
|
}
|
|
if i == 0 || i%2 != 0 {
|
|
return nil
|
|
}
|
|
return slots
|
|
}
|