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.

35 lines
682 B

  1. package forumlog
  2. import (
  3. "bufio"
  4. "strings"
  5. )
  6. // ParseMetadata parses metadata, discards the broken parts, and returns the
  7. // parsed data as a map (`m`) and the position of the first IRC post (`n`)
  8. func ParseMetadata(data string) map[string][]string {
  9. result := make(map[string][]string)
  10. key := ""
  11. scanner := bufio.NewScanner(strings.NewReader(data))
  12. for scanner.Scan() {
  13. line := strings.Trim(scanner.Text(), "\r\t  ")
  14. if strings.HasPrefix(line, "[") {
  15. break
  16. }
  17. if len(line) < 1 {
  18. key = ""
  19. continue
  20. }
  21. if key == "" {
  22. split := strings.Split(line, ":")
  23. key = split[0]
  24. } else {
  25. result[key] = append(result[key], line)
  26. }
  27. }
  28. return result
  29. }