MCPcopy
hub / github.com/flosch/pongo2 / filterTruncatecharsHTML

Function filterTruncatecharsHTML

filters_builtin.go:223–245  ·  view source on GitHub ↗
(in *Value, param *Value)

Source from the content-addressed store, hash-verified

221}
222
223func filterTruncatecharsHTML(in *Value, param *Value) (*Value, *Error) {
224 value := in.String()
225 newLen := max(param.Integer()-3, 0)
226
227 newOutput := bytes.NewBuffer(nil)
228
229 textcounter := 0
230
231 filterTruncateHTMLHelper(value, newOutput, func() bool {
232 return textcounter >= newLen
233 }, func(c rune, s int, idx int) int {
234 textcounter++
235 newOutput.WriteRune(c)
236
237 return idx + s
238 }, func() {
239 if textcounter >= newLen && textcounter < len(value) {
240 newOutput.WriteString("...")
241 }
242 })
243
244 return AsSafeValue(newOutput.String()), nil
245}
246
247func filterTruncatewords(in *Value, param *Value) (*Value, *Error) {
248 words := strings.Fields(in.String())

Callers

nothing calls this directly

Calls 6

maxFunction · 0.85
filterTruncateHTMLHelperFunction · 0.85
AsSafeValueFunction · 0.85
IntegerMethod · 0.80
WriteStringMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…