Files
zip/snake_case.go
zeekay 4d74af5e3d feat(zip): support native Rust, C++, and Go self-documenting SDKs, MCPs, and @hanzo/docs
- Add App.RustSDK() for full ZAP-native self-documenting Rust SDK with rustdoc
- Add App.CppSDK() for modern C++20 self-documenting SDK with Doxygen
- Add App.RustMCP() and App.CppMCP() for native Model Context Protocol tools & servers
- Add App.DocsMarkdown() for @hanzo/docs MDX pages with Go/Rust/C++ tabbed snippets
- Add cmd/zipgen CLI tool for sdk, mcp, and docs generation
2026-09-03 19:16:02 -07:00

36 lines
748 B
Go

package zip
import "strings"
func snakeCase(s string) string {
var b strings.Builder
runes := []rune(s)
n := len(runes)
for i := 0; i < n; i++ {
r := runes[i]
if r >= 'A' && r <= 'Z' {
if i > 0 {
prev := runes[i-1]
next := rune(0)
if i+1 < n {
next = runes[i+1]
}
if (prev >= 'a' && prev <= 'z') || (prev >= '0' && prev <= '9') ||
(prev >= 'A' && prev <= 'Z' && next >= 'a' && next <= 'z') {
b.WriteByte('_')
}
}
b.WriteRune(r + ('a' - 'A'))
} else if r == '-' || r == '.' || r == '/' || r == '_' {
b.WriteByte('_')
} else {
b.WriteRune(r)
}
}
res := b.String()
for strings.Contains(res, "__") {
res = strings.ReplaceAll(res, "__", "_")
}
return strings.Trim(res, "_")
}