MCPcopy Index your code
hub / github.com/go-python/gopy / extractPythonName

Function extractPythonName

bind/utils.go:240–267  ·  view source on GitHub ↗
(gname, gdoc string)

Source from the content-addressed store, hash-verified

238)
239
240func extractPythonName(gname, gdoc string) (string, string, error) {
241 const (
242 PythonName = "gopy:name "
243 NLPythonName = "\n" + PythonName
244 )
245 i := -1
246 var tag string
247 // Check for either a doc string that starts with our tag,
248 // or as the first token of a newline
249 if strings.HasPrefix(gdoc, PythonName) {
250 i = 0
251 tag = PythonName
252 } else {
253 i = strings.Index(gdoc, NLPythonName)
254 tag = NLPythonName
255 }
256 if i < 0 {
257 return gname, gdoc, nil
258 }
259 s := gdoc[i+len(tag):]
260 if end := strings.Index(s, "\n"); end > 0 {
261 if !isValidPythonName(s[:end]) {
262 return "", "", fmt.Errorf("gopy: invalid identifier: %s", s[:end])
263 }
264 return s[:end], gdoc[:i] + s[end:], nil
265 }
266 return gname, gdoc, nil
267}
268
269// extractPythonNameFieldTag parses a struct field tag and returns
270// a new python name. If the tag is not defined then the original

Callers 3

TestExtractPythonNameFunction · 0.85
genFuncSigMethod · 0.85
genFuncBodyMethod · 0.85

Calls 1

isValidPythonNameFunction · 0.85

Tested by 1

TestExtractPythonNameFunction · 0.68