github.com/blend/go-sdk@v1.20220411.3/stringutil/fixed.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package stringutil 9 10 import "fmt" 11 12 // Fixed returns a fixed width, right aligned, string with a given minimum space padded width. 13 func Fixed(text string, width int) string { 14 fixedToken := fmt.Sprintf("%%%d.%ds", width, width) 15 return fmt.Sprintf(fixedToken, text) 16 } 17 18 // FixedLeft returns a fixed width, left aligned, string with a given minimum space padded width. 19 func FixedLeft(text string, width int) string { 20 if width < len(text) { 21 return text[0:width] 22 } 23 fixedToken := fmt.Sprintf("%%-%ds", width) 24 return fmt.Sprintf(fixedToken, text) 25 }