@@ -217,9 +217,7 @@ func (lp *parser) parseTransaction(dateString, payeeString, payeeComment string)
217
217
218
218
postings := make ([]Account , 0 , 2 )
219
219
for lp .scanner .Scan () {
220
- line := lp .scanner .Text ()
221
- // remove heading and tailing space from the line
222
- trimmedLine := strings .TrimSpace (line )
220
+ trimmedLine := lp .scanner .Text ()
223
221
lp .lineCount ++
224
222
225
223
var currentComment string
@@ -239,22 +237,22 @@ func (lp *parser) parseTransaction(dateString, payeeString, payeeComment string)
239
237
}
240
238
241
239
var accChange Account
242
- accChange .Name = trimmedLine
243
240
accChange .Comment = currentComment
244
- if i := strings .LastIndexFunc (trimmedLine , unicode .IsSpace ); i >= 0 {
245
- acc := strings .TrimSpace (trimmedLine [:i ])
246
- amt := trimmedLine [i + 1 :]
247
- if decbal , derr := decimal .NewFromString (amt ); derr == nil {
248
- accChange .Name = acc
241
+ if iSpace := strings .LastIndexFunc (trimmedLine , unicode .IsSpace ); iSpace >= 0 {
242
+ if decbal , derr := decimal .NewFromString (trimmedLine [iSpace + 1 :]); derr == nil {
243
+ accChange .Name = strings .TrimSpace (trimmedLine [:iSpace ])
249
244
accChange .Balance = decbal
250
- } else if i := strings .Index (trimmedLine , "(" ); i >= 0 {
251
- acc := strings .TrimSpace (trimmedLine [:i ])
252
- amt := trimmedLine [i + 1 : len (trimmedLine )- 1 ]
253
- f , _ := compute .Evaluate (amt )
254
- accChange .Name = acc
245
+ } else if iParen := strings .Index (trimmedLine , "(" ); iParen >= 0 {
246
+ accChange .Name = strings .TrimSpace (trimmedLine [:iParen ])
247
+ f , _ := compute .Evaluate (trimmedLine [iParen + 1 : len (trimmedLine )- 1 ])
255
248
accChange .Balance = decimal .NewFromFloat (f )
249
+ } else {
250
+ accChange .Name = strings .TrimSpace (trimmedLine )
256
251
}
252
+ } else {
253
+ accChange .Name = strings .TrimSpace (trimmedLine )
257
254
}
255
+
258
256
postings = append (postings , accChange )
259
257
}
260
258
@@ -263,14 +261,14 @@ func (lp *parser) parseTransaction(dateString, payeeString, payeeComment string)
263
261
Date : transDate ,
264
262
PayeeComment : payeeComment ,
265
263
AccountChanges : postings ,
264
+ Comments : lp .comments ,
266
265
}
267
- transErr := balanceTransaction (trans )
268
- if transErr != nil {
266
+ lp .comments = nil
267
+
268
+ if transErr := balanceTransaction (trans ); transErr != nil {
269
269
err = fmt .Errorf ("Unable to balance transaction: %w" , transErr )
270
270
return
271
271
}
272
- trans .Comments = lp .comments
273
- lp .comments = nil
274
272
return
275
273
}
276
274
0 commit comments