Skip to content

Commit

Permalink
Handle user defined tags on names, media titles and parse some submit…
Browse files Browse the repository at this point in the history
…ter data
  • Loading branch information
iand committed Jul 28, 2024
1 parent 00e34a2 commit 0c40194
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
25 changes: 14 additions & 11 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ func makeRootParser(d *Decoder, g *Gedcom) parser {
d.pushParser(makeIndividualParser(d, obj, level))
case "SUBM":
// TODO: parse submitters
g.Submitter = append(g.Submitter, &SubmitterRecord{})
obj := d.submitter(xref)
g.Submitter = append(g.Submitter, obj)
case "FAM":
obj := d.family(xref)
g.Family = append(g.Family, obj)
Expand Down Expand Up @@ -356,7 +357,13 @@ func makeNameParser(d *Decoder, n *NameRecord, minLevel int) parser {
n.Note = append(n.Note, r)
d.pushParser(makeNoteParser(d, r, level))
default:
d.unhandledTag(level, tag, value, xref)
n.UserDefined = append(n.UserDefined, UserDefinedTag{
Tag: tag,
Value: value,
Xref: xref,
Level: level,
})
d.pushParser(makeUserDefinedTagParser(d, &n.UserDefined[len(n.UserDefined)-1], level))
}

return nil
Expand Down Expand Up @@ -415,6 +422,7 @@ func makeSourceParser(d *Decoder, s *SourceRecord, minLevel int) parser {
d.pushParser(makeTextParser(d, &s.Title, level))
case "ABBR":
s.FiledBy = value
d.pushParser(makeTextParser(d, &s.FiledBy, level))
case "AUTH":
s.Originator = value
d.pushParser(makeTextParser(d, &s.Originator, level))
Expand Down Expand Up @@ -541,8 +549,10 @@ func makeCitationParser(d *Decoder, c *CitationRecord, minLevel int) parser {
switch tag {
case "PAGE":
c.Page = value
d.pushParser(makeTextParser(d, &c.Page, level))
case "QUAY":
c.Quay = value
d.pushParser(makeTextParser(d, &c.Quay, level))
case "NOTE":
r := &NoteRecord{Note: value}
c.Note = append(c.Note, r)
Expand Down Expand Up @@ -910,15 +920,8 @@ func makeMediaParser(d *Decoder, m *MediaRecord, minLevel int) parser {
f.Format = value
d.pushParser(makeMediaFileFormatParser(d, f, level))
case "TITL": // version 5.5
var f *FileRecord
if len(m.File) == 0 {
f = &FileRecord{}
m.File = append(m.File, f)
} else {
f = m.File[len(m.File)-1]
}
f.Title = value
d.pushParser(makeTextParser(d, &f.Title, level))
m.Title = value
d.pushParser(makeTextParser(d, &m.Title, level))
case "RIN":
m.AutomatedRecordId = value
case "REFN":
Expand Down
6 changes: 3 additions & 3 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func TestSubmitter(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}

submitters := []*SubmitterRecord{{}}
submitters := []*SubmitterRecord{{Xref: "SUBMITTER"}}

if diff := cmp.Diff(submitters, g.Submitter); diff != "" {
t.Errorf("submitter mismatch (-want +got):\n%s", diff)
Expand Down Expand Up @@ -609,14 +609,14 @@ func TestFamily(t *testing.T) {
{
Name: `\\network\drive\path\file name.bmp`,
Format: "bmp",
Title: "A bmp picture",
},
},
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
Title: "A bmp picture",
},
},
UserDefined: []UserDefinedTag{
Expand Down Expand Up @@ -704,14 +704,14 @@ func TestSource(t *testing.T) {
{
Name: `\\network\drive\path\file name.bmp`,
Format: "bmp",
Title: "A bmp picture",
},
},
Note: []*NoteRecord{
{
Note: "A note\nNote continued here. The word TEST should not be broken!",
},
},
Title: "A bmp picture",
},
},
UserDefined: []UserDefinedTag{
Expand Down
12 changes: 11 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type IndividualRecord struct {
type MediaRecord struct {
Xref string
File []*FileRecord
Title string
UserReference []*UserReferenceRecord
AutomatedRecordId string
Change ChangeRecord
Expand Down Expand Up @@ -183,7 +184,15 @@ type CitationRecord struct {
}

type SubmitterRecord struct {
Xref string
Xref string
Name string
Address *AddressRecord
Media []*MediaRecord
Language []string
SubmitterRecordFileID string
AutomatedRecordId string
Note []*NoteRecord
Change *ChangeRecord
}

type NameRecord struct {
Expand All @@ -199,6 +208,7 @@ type NameRecord struct {
Romanized []*VariantNameRecord
Citation []*CitationRecord
Note []*NoteRecord
UserDefined []UserDefinedTag
}

type VariantNameRecord struct {
Expand Down

0 comments on commit 0c40194

Please sign in to comment.