MCPcopy Create free account
hub / github.com/alibaba/open-code-review / extractCodeBlock

Function extractCodeBlock

internal/diff/relocation.go:79–97  ·  view source on GitHub ↗

extractCodeBlock extracts the content of the first fenced code block from text. Returns empty string if no code block is found.

(text string)

Source from the content-addressed store, hash-verified

77// extractCodeBlock extracts the content of the first fenced code block from text.
78// Returns empty string if no code block is found.
79func extractCodeBlock(text string) string {
80 text = strings.TrimSpace(text)
81 start := strings.Index(text, "```")
82 if start < 0 {
83 return ""
84 }
85 afterOpen := start + 3
86 // Skip optional language tag on the opening fence line.
87 if nl := strings.IndexByte(text[afterOpen:], '\n'); nl >= 0 {
88 afterOpen += nl + 1
89 } else {
90 return ""
91 }
92 end := strings.Index(text[afterOpen:], "```")
93 if end < 0 {
94 return ""
95 }
96 return strings.TrimSpace(text[afterOpen : afterOpen+end])
97}

Callers 2

ReLocateCommentFunction · 0.85
TestExtractCodeBlockFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestExtractCodeBlockFunction · 0.68