MCPcopy Index your code
hub / github.com/writefreely/writefreely / TruncToWord

Function TruncToWord

parse/posts.go:70–82  ·  view source on GitHub ↗

TruncToWord truncates the given text to the provided limit.

(s string, l int)

Source from the content-addressed store, hash-verified

68
69// TruncToWord truncates the given text to the provided limit.
70func TruncToWord(s string, l int) (string, bool) {
71 truncated := false
72 c := []rune(s)
73 if len(c) > l {
74 truncated = true
75 s = string(c[:l])
76 spaceIdx := strings.LastIndexByte(s, ' ')
77 if spaceIdx > -1 {
78 s = s[:spaceIdx]
79 }
80 }
81 return s, truncated
82}
83
84// Truncate truncates the given text to the provided limit, returning the original string if it's shorter than the limit.
85func Truncate(s string, l int) string {

Callers 3

getSlugFromPostFunction · 0.92
friendlyPostTitleFunction · 0.92
TestTruncToWordFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestTruncToWordFunction · 0.68