MCPcopy Create free account
hub / github.com/TruthHun/BookStack / Substr

Function Substr

utils/util.go:617–638  ·  view source on GitHub ↗

Substr returns the substr from start to length.

(s string, length int)

Source from the content-addressed store, hash-verified

615
616// Substr returns the substr from start to length.
617func Substr(s string, length int) string {
618 bt := []rune(s)
619 start := 0
620 dot := false
621
622 if start > len(bt) {
623 start = start % len(bt)
624 }
625 var end int
626 if (start + length) > (len(bt) - 1) {
627 end = len(bt)
628 } else {
629 end = start + length
630 dot = true
631 }
632
633 str := string(bt[start:end])
634 if dot {
635 str = str + "..."
636 }
637 return str
638}
639
640// 分页函数(这个分页函数不具有通用性)
641// rollPage:展示分页的个数

Callers

nothing calls this directly

Calls 1

stringFunction · 0.85

Tested by

no test coverage detected