diff options
| author | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-01-16 00:46:28 +0800 |
|---|---|---|
| committer | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-01-16 01:07:21 +0800 |
| commit | 05b64e4315ba17960f5bb2119e79eec2476459b2 (patch) | |
| tree | d88f50d6fc4bc8f8a917d1c7161bd5d11a544418 /todolist/parser.go | |
| parent | c3c8817de6228557ba865465e3d639a104578587 (diff) | |
Bugfix: "todo a" no longer adds an empty todo
Diffstat (limited to 'todolist/parser.go')
| -rw-r--r-- | todolist/parser.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/todolist/parser.go b/todolist/parser.go index 433cfc6..6919bd7 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -13,6 +13,12 @@ import ( type Parser struct{} func (p *Parser) ParseNewTodo(input string) *Todo { + r, _ := regexp.Compile(`^(add|a)(\\ |)`) + input = r.ReplaceAllString(input, "") + if input == "" { + return nil + } + todo := NewTodo() todo.Subject = p.Subject(input) todo.Projects = p.Projects(input) @@ -24,8 +30,6 @@ func (p *Parser) ParseNewTodo(input string) *Todo { } func (p *Parser) Subject(input string) string { - r, _ := regexp.Compile(`^(add|a) `) - input = r.ReplaceAllString(input, "") if strings.Contains(input, " due") { index := strings.LastIndex(input, " due") return input[0:index] |
