Skip to content

Commit 61f089e

Browse files
committed
build: go fix
1 parent ed77c4a commit 61f089e

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

ledger/cmd/print.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,15 @@ func WriteTransaction(w io.StringWriter, trans *ledger.Transaction, columns int)
208208
w.WriteString(spaceStr[:1])
209209
w.WriteString(trans.Payee)
210210
if len(trans.PayeeComment) > 0 {
211-
spaceCount := columns - 10 - utf8.RuneCountInString(trans.Payee)
212-
if spaceCount < 1 {
213-
spaceCount = 1
214-
}
211+
spaceCount := max(columns-10-utf8.RuneCountInString(trans.Payee), 1)
215212
w.WriteString(spaceStr[:spaceCount])
216213
w.WriteString(trans.PayeeComment)
217214
}
218215
w.WriteString(newLine)
219216
for _, accChange := range trans.AccountChanges {
220217
n := accChange.Balance.FixedBank(amtBuf[:])
221218
outBalanceString := unsafe.String(unsafe.SliceData(amtBuf[n:]), 24-n)
222-
spaceCount := columns - 4 - utf8.RuneCountInString(accChange.Name) - utf8.RuneCountInString(outBalanceString)
223-
if spaceCount < 1 {
224-
spaceCount = 1
225-
}
219+
spaceCount := max(columns-4-utf8.RuneCountInString(accChange.Name)-utf8.RuneCountInString(outBalanceString), 1)
226220
w.WriteString(spaceStr[:4])
227221
w.WriteString(accChange.Name)
228222
w.WriteString(spaceStr[:spaceCount])

ledger/cmd/webHandlerReport.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func getRangeAndPeriod(dateRange, dateFreq string) (start, end time.Time, period
3131
func getAccounts(accountNeedle string, accountsHaystack []*ledger.Account) (results []*ledger.Account) {
3232
needleDepth := len(strings.Split(accountNeedle, ":"))
3333

34-
if dblstarIdx := strings.Index(accountNeedle, "**"); dblstarIdx != -1 {
34+
if before, _, ok := strings.Cut(accountNeedle, "**"); ok {
3535
foundAccountNames := make(map[string]*ledger.Account)
36-
prefixNeedle := accountNeedle[:dblstarIdx]
36+
prefixNeedle := before
3737
for _, hay := range accountsHaystack {
3838
if strings.HasPrefix(hay.Name, prefixNeedle) {
3939
foundAccountNames[hay.Name] = hay
@@ -48,8 +48,8 @@ func getAccounts(accountNeedle string, accountsHaystack []*ledger.Account) (resu
4848
for _, hay := range foundAccountNames {
4949
results = append(results, hay)
5050
}
51-
} else if starIdx := strings.Index(accountNeedle, "*"); starIdx != -1 {
52-
prefixNeedle := accountNeedle[:starIdx]
51+
} else if before, _, ok := strings.Cut(accountNeedle, "*"); ok {
52+
prefixNeedle := before
5353
for _, hay := range accountsHaystack {
5454
hayDepth := len(strings.Split(hay.Name, ":"))
5555
if strings.HasPrefix(hay.Name, prefixNeedle) && hayDepth == needleDepth {

0 commit comments

Comments
 (0)