@@ -317,11 +317,10 @@ func (n *NameStyle) Type() string {
317317}
318318
319319type table struct {
320- contents tableContents
321- threshold Threshold
322- nameStyle NameStyle
323- footnotes []string
324- footnoteIndexes map [string ]int
320+ contents tableContents
321+ threshold Threshold
322+ nameStyle NameStyle
323+ footnotes * Footnotes
325324}
326325
327326func (s HistorySize ) TableString (threshold Threshold , nameStyle NameStyle ) string {
@@ -397,18 +396,17 @@ func (s HistorySize) TableString(threshold Threshold, nameStyle NameStyle) strin
397396 I ("Number of submodules" , s .MaxExpandedSubmoduleCountTree , s .MaxExpandedSubmoduleCount , metric , " " , 100 ),
398397 ),
399398 ),
400- threshold : threshold ,
401- nameStyle : nameStyle ,
402- footnoteIndexes : make ( map [ string ] int ),
399+ threshold : threshold ,
400+ nameStyle : nameStyle ,
401+ footnotes : NewFootnotes ( ),
403402 }
404403
405404 return t .String ()
406405}
407406
408407func (t * table ) String () string {
409- lines := t .generateLines ()
410- footnotes := t .generateFootnotes ()
411- return lines + footnotes
408+ linesString := t .generateLines ()
409+ return linesString + t .footnotes .String ()
412410}
413411
414412func (t * table ) generateHeader () string {
@@ -436,7 +434,7 @@ func (t *table) formatRow(
436434 if indent != 0 {
437435 prefix = spaces [:2 * (indent - 1 )] + "* "
438436 }
439- citation := t .createCitation (footnote )
437+ citation := t .footnotes . CreateCitation (footnote )
440438 spacer := ""
441439 l := len (prefix ) + len (name ) + len (citation )
442440 if l < 28 {
@@ -447,32 +445,3 @@ func (t *table) formatRow(
447445 prefix , name , spacer , citation , valueString , unitString , levelOfConcern ,
448446 )
449447}
450-
451- func (t * table ) createCitation (footnote string ) string {
452- if footnote == "" {
453- return ""
454- }
455-
456- index , ok := t .footnoteIndexes [footnote ]
457- if ! ok {
458- index = len (t .footnoteIndexes ) + 1
459- t .footnotes = append (t .footnotes , footnote )
460- t .footnoteIndexes [footnote ] = index
461- }
462- return fmt .Sprintf ("[%d]" , index )
463- }
464-
465- func (t * table ) generateFootnotes () string {
466- if len (t .footnotes ) == 0 {
467- return ""
468- }
469-
470- buf := & bytes.Buffer {}
471- buf .WriteByte ('\n' )
472- for i , footnote := range t .footnotes {
473- index := i + 1
474- citation := fmt .Sprintf ("[%d]" , index )
475- fmt .Fprintf (buf , "%-4s %s\n " , citation , footnote )
476- }
477- return buf .String ()
478- }
0 commit comments