MCPcopy Index your code
hub / github.com/bytebase/bytebase / TruncateString

Function TruncateString

backend/common/util.go:77–87  ·  view source on GitHub ↗

TruncateString truncates the string to have a maximum length of `limit` characters.

(str string, limit int)

Source from the content-addressed store, hash-verified

75
76// TruncateString truncates the string to have a maximum length of `limit` characters.
77func TruncateString(str string, limit int) (string, bool) {
78 chars := 0
79 // The string may contain unicode characters, so we iterate here.
80 for i := range str {
81 if chars >= limit {
82 return str[:i], true
83 }
84 chars++
85 }
86 return str, false
87}
88
89// TruncateStringWithDescription tries to truncate the string and append "... (view details in Bytebase)" if truncated.
90func TruncateStringWithDescription(str string) string {

Callers 15

generateSQLForTableFunction · 0.92
GenerateRestoreSQLFunction · 0.92
generateSQLForTableFunction · 0.92
GenerateRestoreSQLFunction · 0.92
generateSQLForTableFunction · 0.92
GenerateRestoreSQLFunction · 0.92
generateSQLForMixedDMLFunction · 0.92
GenerateRestoreSQLFunction · 0.92
generateSQLForTableFunction · 0.92
GenerateRestoreSQLFunction · 0.92
getVersionMethod · 0.92

Calls

no outgoing calls

Tested by 2

TestTruncateStringFunction · 0.68