GraphQL API and utilities for the rpdata project
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
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 }
|