38 lines
730 B
Go
38 lines
730 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, numeric index, slot, numeric index, ...
|
|
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 == "" {
|
|
return nil
|
|
}
|
|
for j := range len(part) {
|
|
if part[j] < '0' || part[j] > '9' {
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
i++
|
|
}
|
|
if i == 0 || i%2 != 0 {
|
|
return nil
|
|
}
|
|
return slots
|
|
}
|