MCPcopy Index your code
hub / github.com/apache/answer / FetchRangedExcerpt

Function FetchRangedExcerpt

pkg/htmltext/htmltext.go:153–171  ·  view source on GitHub ↗

FetchRangedExcerpt returns a ranged excerpt from the HTML string. Note: offset is a rune index, not a byte index

(html, trimMarker string, offset int, limit int)

Source from the content-addressed store, hash-verified

151// FetchRangedExcerpt returns a ranged excerpt from the HTML string.
152// Note: offset is a rune index, not a byte index
153func FetchRangedExcerpt(html, trimMarker string, offset int, limit int) (text string) {
154 if len(html) == 0 {
155 text = html
156 return
157 }
158
159 runeText := []rune(ClearText(html))
160 begin, end := getRuneRange(runeText, offset, limit)
161 text = string(runeText[begin:end])
162
163 if begin > 0 {
164 text = trimMarker + text
165 }
166 if end < len(runeText) {
167 text += trimMarker
168 }
169
170 return
171}
172
173// FetchMatchedExcerpt returns the matched excerpt according to the words
174func FetchMatchedExcerpt(html string, words []string, trimMarker string, trimLength int) string {

Callers 3

FetchExcerptFunction · 0.85
FetchMatchedExcerptFunction · 0.85
TestFetchRangedExcerptFunction · 0.85

Calls 2

ClearTextFunction · 0.85
getRuneRangeFunction · 0.85

Tested by 1

TestFetchRangedExcerptFunction · 0.68