func (s *selectionSpec) match(r *marc21.MarcRecord) bool { if s.field == "" { return true } if marc21.IsControlFieldTag(s.field) { field, err := r.GetControlField(s.field) if err != nil { return false } if s.criterion != nil { return s.criterion.MatchString(field) } return true } else { // Data Field subfields := make([]string, 1) field, _ := r.GetDataField(s.field) for instance := 0; instance < field.ValueCount(); instance++ { // if no subfield is specified in the spec then // we want to search all of them. since these can // vary per field instance we need to get the list // each time. if s.subfield != "" { subfields[0] = s.subfield } else { subfields = field.GetSubfields(instance) } for _, subfield := range subfields { sfv := field.GetNthSubfield(subfield, instance) if sfv != "" { // the subfield exists: need to check because the // user supplied subfield may not exist in this // instance if s.criterion != nil { // and there is a search criterion if s.criterion.MatchString(sfv) { // and it matches return true } } else { // no search criterion, but the field exists return true } } } } return false } }
func printRecord(record *marc21.MarcRecord, w *tabwriter.Writer) error { fmt.Fprintf(w, "Leader\t%s\n", record.GetLeader()) fields := record.GetFieldList() for _, f := range fields { if marc21.IsControlFieldTag(f) { v, _ := record.GetControlField(f) fmt.Fprintf(w, "%s\t%s\n", f, v) } else { v, _ := record.GetDataField(f) printDataField(w, v) } } w.Flush() return nil }