github.com/haraldrudell/parl@v0.4.176/pruntime/pruntimelib/parse-func-line.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package pruntimelib 7 8 import ( 9 "bytes" 10 "fmt" 11 ) 12 13 // ParseFuncLine parses a line of a package name, optionally fully qualified, and 14 // a possible receiver type name and a function name, followed by a parenthesised 15 // argument list. 16 // samples: 17 // 18 // main.main() 19 // main.(*MyType).goroutine1(0x0?, 0x140000120d0, 0x2) 20 // codeberg.org/haraldrudell/goprogramming/std/runtime-debug/gp-debug-stack/mypackage.Fn(...) 21 func ParseFuncLine(funcLine []byte) (funcName string, args string) { 22 var leftIndex = bytes.IndexByte(funcLine, '(') 23 if leftIndex < 1 { 24 panic(fmt.Errorf("bad debug.Stack function line: no left parenthesis: %q", funcLine)) 25 } 26 27 // determine if parenthesis is for optional type name rarther than function arguments 28 if funcLine[leftIndex-1] == '.' { 29 nextIndex := bytes.IndexByte(funcLine[leftIndex+1:], '(') 30 if nextIndex < 1 { 31 panic(fmt.Errorf("bad debug.Stack function line: no second left parenthesis: %q", funcLine)) 32 } 33 leftIndex += nextIndex + 1 34 } 35 36 funcName = string(funcLine[:leftIndex]) 37 args = string(funcLine[leftIndex:]) 38 39 return 40 }