diff options
Diffstat (limited to 'vendor/github.com/containers/buildah/util/util.go')
-rw-r--r-- | vendor/github.com/containers/buildah/util/util.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/vendor/github.com/containers/buildah/util/util.go b/vendor/github.com/containers/buildah/util/util.go index 4be0b2de8..8ec767601 100644 --- a/vendor/github.com/containers/buildah/util/util.go +++ b/vendor/github.com/containers/buildah/util/util.go @@ -381,3 +381,17 @@ func LogIfNotRetryable(err error, what string) (retry bool) { func LogIfUnexpectedWhileDraining(err error, what string) { logIfNotErrno(err, what, syscall.EINTR, syscall.EAGAIN, syscall.EIO) } + +// TruncateString trims the given string to the provided maximum amount of +// characters and shortens it with `...`. +func TruncateString(str string, to int) string { + newStr := str + if len(str) > to { + const tr = "..." + if to > len(tr) { + to -= len(tr) + } + newStr = str[0:to] + tr + } + return newStr +} |