package main import "strings" import "time" const HeadFormat = "> 2006-01-02" func NextLine(s string) (line, rest string) { line, rest, _ = strings.Cut(s, "\n") if line[len(line) - 1] == '\r' { line = line[:len(line) - 1] } return } func NextEntry(s *string) (ts time.Time, body string, ok bool) { var err error for { if *s == "" { return ts, body, false } line, rest := NextLine(*s) *s = rest if ts, err = time.Parse(HeadFormat, line); err == nil { break } } for { if *s == "" { break } line, rest := NextLine(*s) if _, err = time.Parse(HeadFormat, line); err != nil { body += line + "\n" *s = rest } else { break } } return ts, strings.TrimSpace(body), true }