MCPcopy Create free account
hub / github.com/gobeam/stringy / Pad

Method Pad

stringy.go:242–265  ·  view source on GitHub ↗

Pad takes three param length i.e total length to be after padding, with i.e what to pad with and pad type which can be ("both" or "left" or "right") it return string after padding upto length by with param and on padType type it can be chained on function which return StringManipulation interface

(length int, with, padType string)

Source from the content-addressed store, hash-verified

240// upto length by with param and on padType type it can be chained on function which return
241// StringManipulation interface
242func (i *input) Pad(length int, with, padType string) string {
243 input := getInput(*i)
244 inputLength := len(input)
245 padLength := len(with)
246 if inputLength >= length {
247 return input
248 }
249 switch padType {
250 case Right:
251 var count = 1 + ((length - padLength) / padLength)
252 var result = input + strings.Repeat(with, count)
253 return result[:length]
254 case Left:
255 var count = 1 + ((length - padLength) / padLength)
256 var result = strings.Repeat(with, count) + input
257 return result[(len(result) - length):]
258 case Both:
259 length := (float64(length - inputLength)) / float64(2)
260 repeat := math.Ceil(length / float64(padLength))
261 return strings.Repeat(with, int(repeat))[:int(math.Floor(float64(length)))] + input + strings.Repeat(with, int(repeat))[:int(math.Ceil(float64(length)))]
262 default:
263 return input
264 }
265}
266
267// RemoveSpecialCharacter removes all special characters and returns the string
268// it can be chained on function which return StringManipulation interface

Callers

nothing calls this directly

Calls 1

getInputFunction · 0.85

Tested by

no test coverage detected