Files
gists/projects/go-tools/goipgrep/internal/normalize/mac.go
T
tobias 1cbf8afb4a chore: cleanup — untrack binaries, consolidate Go dirs, dedupe tools
- Untrack and delete compiled binaries (tarsum, gosoft.exe, rust uniq/uniq2);
  ignore build outputs (dist/, bin/, *.exe, *.test, .ruff_cache/)
- Merge tools/go/ and projects/go-tools/go/ into projects/go-tools/<name>/
- Fix goipgrep .gitignore: bare 'ipgrep' pattern was ignoring cmd/ipgrep/,
  so the main entrypoint was never tracked; now anchored to /ipgrep
- Archive duplicate implementations to archive/experimental/{rust,go}/
  (uniq, between, tarsum rewrites); canonical versions stay in tools/
- Update README tool catalog to match new layout

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 13:42:45 +02:00

44 lines
854 B
Go

package normalize
import (
"strings"
)
// NormalizeMAC converts supported MAC forms to canonical lower-case colon-separated form.
// Accepts: xx:xx:xx:xx:xx:xx, xx-xx-xx-xx-xx-xx, xxxx.xxxx.xxxx
func NormalizeMAC(s string) (string, bool) {
s = strings.TrimSpace(s)
if s == "" {
return "", false
}
s = strings.ToLower(s)
// remove common separators
s = strings.ReplaceAll(s, ":", "")
s = strings.ReplaceAll(s, "-", "")
s = strings.ReplaceAll(s, ".", "")
if len(s) != 12 {
return "", false
}
for i := 0; i < 12; i++ {
c := s[i]
if (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') {
continue
}
return "", false
}
// canonical form aa:bb:cc:dd:ee:ff
var b strings.Builder
b.Grow(17)
for i := 0; i < 12; i += 2 {
if i > 0 {
b.WriteByte(':')
}
b.WriteByte(s[i])
b.WriteByte(s[i+1])
}
return b.String(), true
}