diff options
| author | Michael Strùˆder <mikezter@gmail.com> | 2017-04-29 16:19:24 +0200 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2017-05-09 20:20:24 -0400 |
| commit | aa5050461a30d36a384edd45d20585a89d3da344 (patch) | |
| tree | 4785f5faa2dc1c2780fe3f778e3fdc58a0045215 /todolist/parser.go | |
| parent | 6cb4a95af8bc4a8348c7b115fba334e668fe95e5 (diff) | |
extract subcommand, id, and input string in Parser
Diffstat (limited to 'todolist/parser.go')
| -rw-r--r-- | todolist/parser.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/todolist/parser.go b/todolist/parser.go index 1f070c3..d55ab3b 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -9,7 +9,9 @@ import ( "time" ) -type Parser struct{} +type Parser struct { + input string +} func (p *Parser) ParseNewTodo(input string) *Todo { r, _ := regexp.Compile(`^(add|a)(\\ |) `) @@ -28,6 +30,19 @@ func (p *Parser) ParseNewTodo(input string) *Todo { return todo } +func (p Parser) Parse() (string, int, string) { + input := p.input + r := regexp.MustCompile(`(\w+) (\d+) (.*)`) + matches := r.FindStringSubmatch(input) + id, err := strconv.Atoi(matches[2]) + if err != nil { + fmt.Println("Invalid id.") + id = -1 + } + + return matches[1], id, matches[3] +} + func (p *Parser) Subject(input string) string { if strings.Contains(input, " due") { index := strings.LastIndex(input, " due") |
