Browse Source

Better parsing of tabs

bmallred 9 years ago
parent
commit
32dd105c0c
3 changed files with 14 additions and 9 deletions
  1. 1 8
      account.go
  2. 12 0
      helpers.go
  3. 1 1
      transaction.go

+ 1 - 8
account.go

15
15
16
// Convert from a string to an account
16
// Convert from a string to an account
17
func (a *Account) FromString(text string) error {
17
func (a *Account) FromString(text string) error {
18
	parts := strings.Split(text, "\t")
19
	fields := []string{}
20
	for _, p := range parts {
21
		if p != "" {
22
			fields = append(fields, p)
23
		}
24
	}
25
18
	fields := parseTabs(text)
26
	if len(fields) != 2 {
19
	if len(fields) != 2 {
27
		return errors.New("Invalid account format")
20
		return errors.New("Invalid account format")
28
	}
21
	}

+ 12 - 0
helpers.go

24
	}
24
	}
25
}
25
}
26
26
27
// Parse some text separating the fields by tab(s).
28
func parseTabs(text string) []string {
29
	parts := strings.Split(text, "\t")
30
	fields := []string{}
31
	for _, p := range parts {
32
		if p != "" {
33
			fields = append(fields, p)
34
		}
35
	}
36
	return fields
37
}
38
27
// Format the ledger so it is human readable
39
// Format the ledger so it is human readable
28
func formatLedger() {
40
func formatLedger() {
29
}
41
}

+ 1 - 1
transaction.go

26
26
27
		switch i {
27
		switch i {
28
		case 0:
28
		case 0:
29
			fields := strings.Split(line, "\t")
29
			fields := parseTabs(text)
30
30
31
			date, err := parseDate(fields[0])
31
			date, err := parseDate(fields[0])
32
			check(err)
32
			check(err)