refacto: make the strung truncation utility private

pull/21/head
Dominique Merle 3 years ago
parent 2adc569378
commit fd70088161

@ -23,12 +23,12 @@ type Formatter interface {
) (string, error)
}
// TruncateString safely truncates a string (hopefully)
// truncateString safely truncates a string (hopefully)
// from https://dev.to/takakd/go-safe-truncate-string-9h0
// with some tweaks, like the suffix ; the length includes the suffix
// Supports Japanese, see Range loops https://blog.golang.org/strings
// Provide a space as rune to disable the suffix
func TruncateString(str string, length int, suffix rune) string {
func truncateString(str string, length int, suffix rune) string {
if length <= 0 {
return ""
}

@ -51,7 +51,7 @@ func (t *GnuplotMeritFormatter) Format(
for _, proposalResult := range proposalsResults {
proposalTally := pollTally.Proposals[proposalResult.Index]
row := make([]string, 0, 10)
row = append(row, TruncateString(proposals[proposalResult.Index], 23, '…'))
row = append(row, truncateString(proposals[proposalResult.Index], 23, '…'))
for gradeIndex := range grades {
row = append(row, strconv.FormatFloat(

@ -33,7 +33,7 @@ func (t *GnuplotOpinionFormatter) Format(
}
}
for i, proposalName := range proposalsNames {
proposalsNames[i] = TruncateString(proposalName, 16, '…')
proposalsNames[i] = truncateString(proposalName, 16, '…')
}
buffer := new(bytes.Buffer)

@ -62,7 +62,7 @@ func (t *TextFormatter) Format(
line += fmt.Sprintf(
" %*s ",
amountOfCharactersForProposal,
TruncateString(proposals[proposalResult.Index], amountOfCharactersForProposal, '…'),
truncateString(proposals[proposalResult.Index], amountOfCharactersForProposal, '…'),
)
remainingWidth := expectedWidth - len(line)

Loading…
Cancel
Save