MCPcopy Index your code
hub / github.com/coder/slog / quote

Function quote

internal/entryhuman/entry.go:399–420  ·  view source on GitHub ↗

quotes quotes a string so that it is suitable as a key for a map or in general some output that cannot span multiple lines or have weird characters.

(key string)

Source from the content-addressed store, hash-verified

397// as a key for a map or in general some output that
398// cannot span multiple lines or have weird characters.
399func quote(key string) string {
400 // strconv.Quote does not quote an empty string so we need this.
401 if key == "" {
402 return `""`
403 }
404
405 var hasSpace bool
406 for _, r := range key {
407 if unicode.IsSpace(r) {
408 hasSpace = true
409 break
410 }
411 }
412 quoted := strconv.Quote(key)
413 // If the key doesn't need to be quoted, don't quote it.
414 // We do not use strconv.CanBackquote because it doesn't
415 // account tabs.
416 if !hasSpace && quoted[1:len(quoted)-1] == key {
417 return key
418 }
419 return quoted
420}
421
422func quoteKey(key string) string {
423 // Replace spaces in the map keys with underscores.

Callers 4

formatValueFunction · 0.85
writeValueFastFunction · 0.85
FmtMethod · 0.85
quoteKeyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected