package forumlog import ( "bufio" "strings" ) // ParseMetadata parses metadata, discards the broken parts, and returns the // parsed data as a map (`m`) and the position of the first IRC post (`n`) func ParseMetadata(data string) map[string][]string { result := make(map[string][]string) key := "" scanner := bufio.NewScanner(strings.NewReader(data)) for scanner.Scan() { line := strings.Trim(scanner.Text(), "\r\t  ") if strings.HasPrefix(line, "[") { break } if len(line) < 1 { key = "" continue } if key == "" { split := strings.Split(line, ":") key = split[0] } else { result[key] = append(result[key], line) } } return result }