MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / splitString

Function splitString

pkg/util/inputmapping.go:53–79  ·  view source on GitHub ↗

splitString splits a string along the specified separator, but it ignores anything between double quotes for splitting. We do simple inside/outside quote counting. Quotes are not stripped from output.

(s string, sep rune)

Source from the content-addressed store, hash-verified

51// ignores anything between double quotes for splitting. We do simple
52// inside/outside quote counting. Quotes are not stripped from output.
53func splitString(s string, sep rune) []string {
54 const escapeChar rune = '"'
55
56 var parts []string
57 var part string
58 inQuotes := false
59
60 for _, c := range s {
61 if c == escapeChar {
62 if inQuotes {
63 inQuotes = false
64 } else {
65 inQuotes = true
66 }
67 }
68
69 // If we've gotten the separator rune, consider the previous part
70 // complete, but only if we're outside of quoted sections
71 if c == sep && !inQuotes {
72 parts = append(parts, part)
73 part = ""
74 continue
75 }
76 part += string(c)
77 }
78 return append(parts, part)
79}

Callers 2

TestSplitStringFunction · 0.85
ParseCommandlineMapFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestSplitStringFunction · 0.68