MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / sanitizeIdentifier

Function sanitizeIdentifier

internal/plugins/ansible/inventory.go:564–592  ·  view source on GitHub ↗
(raw string)

Source from the content-addressed store, hash-verified

562}
563
564func sanitizeIdentifier(raw string) string {
565 raw = strings.ToLower(strings.TrimSpace(raw))
566 if raw == "" {
567 return "unknown"
568 }
569
570 var out strings.Builder
571 prevUnderscore := false
572 for _, ch := range raw {
573 isAlnum := (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9')
574 if isAlnum {
575 out.WriteRune(ch)
576 prevUnderscore = false
577 continue
578 }
579
580 if !prevUnderscore {
581 out.WriteRune('_')
582 prevUnderscore = true
583 }
584 }
585
586 sanitized := strings.Trim(out.String(), "_")
587 if sanitized == "" {
588 return "unknown"
589 }
590
591 return sanitized
592}
593
594func uniqueAlias(existing []InventoryHost, base string) string {
595 if base == "" {

Callers 2

BuildInventoryWithFormatFunction · 0.85
TestSanitizeIdentifierFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by 1

TestSanitizeIdentifierFunction · 0.68