MCPcopy
hub / github.com/apache/answer / GetQuestionLink

Function GetQuestionLink

pkg/checker/question_link.go:39–62  ·  view source on GitHub ↗
(content string)

Source from the content-addressed store, hash-verified

37}
38
39func GetQuestionLink(content string) []QuestionLink {
40 uniqueIDs := make(map[string]struct{})
41 var questionLinks []QuestionLink
42
43 // use two pointer to find the link
44 left, right := 0, 0
45 for right < len(content) {
46 // find "/questions/" or "#"
47 switch {
48 case right+11 < len(content) && content[right:right+11] == "/questions/":
49 left = right
50 right += 11
51 processURL(content, &left, &right, uniqueIDs, &questionLinks)
52 case content[right] == '#':
53 left = right + 1
54 right = left
55 processID(content, &left, &right, uniqueIDs, &questionLinks)
56 default:
57 right++
58 }
59 }
60
61 return questionLinks
62}
63
64func processURL(content string, left, right *int, uniqueIDs map[string]struct{}, questionLinks *[]QuestionLink) {
65 for *right < len(content) && (isDigit(content[*right]) || isLetter(content[*right])) {

Callers 2

TestGetQuestionLinkFunction · 0.92
UpdateQuestionLinkMethod · 0.92

Calls 2

processURLFunction · 0.85
processIDFunction · 0.85

Tested by 1

TestGetQuestionLinkFunction · 0.74