| 37 | } |
| 38 | |
| 39 | func 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 | |
| 64 | func processURL(content string, left, right *int, uniqueIDs map[string]struct{}, questionLinks *[]QuestionLink) { |
| 65 | for *right < len(content) && (isDigit(content[*right]) || isLetter(content[*right])) { |