Skip to content

Commit

Permalink
Merge branch 'master' of github.com:howeyc/ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Jan 6, 2016
2 parents bfd5c61 + c8aaeea commit 7cf5d35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/ledger/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func PrintBalances(accountList []*ledger.Account, printZeroBalances bool, depth,
}
fmt.Println(strings.Repeat("-", columns))
outBalanceString := overallBalance.FloatString(ledger.DisplayPrecision)
spaceCount := columns - len(outBalanceString)
spaceCount := columns - utf8.RuneCountInString(outBalanceString)
fmt.Printf("%s%s\n", strings.Repeat(" ", spaceCount), outBalanceString)
}

Expand All @@ -65,7 +65,7 @@ func PrintTransaction(trans *ledger.Transaction, columns int) {
fmt.Printf("%s %s\n", trans.Date.Format(ledger.TransactionDateFormat), trans.Payee)
for _, accChange := range trans.AccountChanges {
outBalanceString := accChange.Balance.FloatString(ledger.DisplayPrecision)
spaceCount := columns - 4 - len(accChange.Name) - len(outBalanceString)
spaceCount := columns - 4 - utf8.RuneCountInString(accChange.Name) - utf8.RuneCountInString(outBalanceString)
fmt.Printf(" %s%s%s\n", accChange.Name, strings.Repeat(" ", spaceCount), outBalanceString)
}
fmt.Println("")
Expand Down
8 changes: 4 additions & 4 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ func ParseLedger(ledgerReader io.Reader) (generalLedger []*Transaction, err erro
var lineCount int
for scanner.Scan() {
line = scanner.Text()
// remove heading and tailing space from the line
trimmedLine := strings.Trim(line, whitespace)
lineCount++
if strings.HasPrefix(line, ";") {
// nop
} else if len(line) == 0 {
} else if len(trimmedLine) == 0 {
if trans != nil {
transErr := balanceTransaction(trans)
if transErr != nil {
Expand All @@ -52,9 +54,7 @@ func ParseLedger(ledgerReader io.Reader) (generalLedger []*Transaction, err erro
trans = &Transaction{Payee: payeeString, Date: transDate}
} else {
var accChange Account
// remove heading and tailing space from the line
line = strings.Trim(line, whitespace)
lineSplit := strings.Split(line, " ")
lineSplit := strings.Split(trimmedLine, " ")
nonEmptyWords := []string{}
for _, word := range lineSplit {
if len(word) > 0 {
Expand Down

0 comments on commit 7cf5d35

Please sign in to comment.