Skip to content

Commit

Permalink
fix: typo of delimiter (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: goflutterjava <goflutterjava@gmail.com>
  • Loading branch information
goflutterjava authored Dec 25, 2024
1 parent 8f46997 commit 3ef4402
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// Unmarshal parses an ASCII table into a slice of the specified type.
func Unmarshal[E any](asciiTable string, v E) ([]string, []E, error) {
var delimitter = "*+|"
var delimiter = "*+|"
var skip = []string{"---"}
lines := strings.Split(strings.TrimSpace(asciiTable), "\n")
if len(lines) < 4 {
Expand All @@ -27,11 +27,11 @@ func Unmarshal[E any](asciiTable string, v E) ([]string, []E, error) {
}

for i, line := range lines[0:defaultLines] {
headerLine := strings.Trim(line, delimitter+" ")
headerLine := strings.Trim(line, delimiter+" ")
if skipLine(headerLine, skip) {
continue
}
headers = splitRow(headerLine, delimitter)
headers = splitRow(headerLine, delimiter)
if len(headers) > 1 {
headerLineNumber = i
break
Expand All @@ -51,7 +51,7 @@ func Unmarshal[E any](asciiTable string, v E) ([]string, []E, error) {
continue
}

row := splitRow(strings.Trim(line, delimitter+" "), delimitter)
row := splitRow(strings.Trim(line, delimiter+" "), delimiter)
if len(row) != len(headers) {
return nil, nil, fmt.Errorf("row length does not match header length: %v", row)
}
Expand Down Expand Up @@ -79,10 +79,10 @@ func Unmarshal[E any](asciiTable string, v E) ([]string, []E, error) {
return headers, results, nil
}

// Helper function to split a row by the first character in the delimitter string and trim whitespace.
func splitRow(row string, delimitter string) []string {
// Helper function to split a row by the first character in the delimiter string and trim whitespace.
func splitRow(row string, delimiter string) []string {
var cells []string
for _, char := range strings.Split(delimitter, "") {
for _, char := range strings.Split(delimiter, "") {
cells = strings.Split(row, char)
for i := range cells {
cells[i] = strings.TrimSpace(cells[i])
Expand Down

0 comments on commit 3ef4402

Please sign in to comment.