Source File
keypath.go
Belonging Package
github.com/pancsta/d2/d2format
package d2formatimport ()// FormatKeyPath formats the scalar values in a as a canonical key path, like// Format(d2ast.MakeKeyPathString(a)), without building a temporary key path AST.// Quoting in the input nodes is intentionally ignored, just as in MakeKeyPathString.func ( []d2ast.String) string {:= printer{inKey: true}for , := range {if > 0 {.sb.WriteByte('.')}:= .ScalarString()// The exported specials set can be customized by callers.if plainKey() && !strings.ContainsAny(, d2ast.UnquotedKeySpecials) {:= strings.ToLower()if == "null" {.sb.WriteString("'null'")} else if , := d2ast.ReservedKeywords[]; {.sb.WriteString()} else {.sb.WriteString()}} else {.node(d2ast.RawString(, true))}}return .sb.String()}// Keep the fast path deliberately narrow. Other strings use the regular// formatter's quoting, escaping, Unicode, and invalid UTF-8 handling.func plainKey( string) bool {if == "" {return false}for := 0; < len(); ++ {:= []if >= 'a' && <= 'z' || >= 'A' && <= 'Z' || >= '0' && <= '9' || == '_' {continue}return false}return true}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |