| Conditions | 2 |
| Total Lines | 7 |
| Code Lines | 5 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | package utils |
||
| 5 | func CenterString(str string, width int) string { |
||
| 6 | spaces := int(float64(width-len(str)) / 2) |
||
| 7 | // If the string is longer than the width, return the string as is |
||
| 8 | if spaces < 0 { |
||
| 9 | return str |
||
| 10 | } |
||
| 11 | return strings.Repeat(" ", spaces) + str + strings.Repeat(" ", width-(spaces+len(str))) |
||
| 12 | } |
||
| 21 |