X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=r.go;h=483fc2a67cb830076a5cbb69c2b7a539ed959f1a;hb=bc8cebaebde70164a86c00ec5ead3693513cc924;hp=ca9bba8316c63b248bcc2eacb648e50db564f427;hpb=f9f1568a138310677728de89da321b5b84ccbb7d;p=gorecfile.git diff --git a/r.go b/r.go index ca9bba8..483fc2a 100644 --- a/r.go +++ b/r.go @@ -1,6 +1,6 @@ /* recfile -- GNU recutils'es recfiles parser on pure Go -Copyright (C) 2020 Sergey Matveev +Copyright (C) 2020-2022 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,7 +15,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -// GNU recutils'es recfiles parser on pure Go package recfile import ( @@ -124,7 +123,7 @@ func (r *Reader) Next() ([]Field, error) { return fields, nil } -// Same as Next(), but creates map from the fields. +// Same as Next(), but with unique keys and last value. func (r *Reader) NextMap() (map[string]string, error) { fields, err := r.Next() if err != nil { @@ -136,3 +135,16 @@ func (r *Reader) NextMap() (map[string]string, error) { } return m, nil } + +// Same as Next(), but with unique keys and slices of values. +func (r *Reader) NextMapWithSlice() (map[string][]string, error) { + fields, err := r.Next() + if err != nil { + return nil, err + } + m := make(map[string][]string) + for _, f := range fields { + m[f.Name] = append(m[f.Name], f.Value) + } + return m, nil +}