-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdoc.go
More file actions
115 lines (89 loc) · 3.07 KB
/
doc.go
File metadata and controls
115 lines (89 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
This is free and unencumbered software released into the public domain. For more
information, see <http://unlicense.org/> or the accompanying UNLICENSE file.
*/
/*
Package gedcom provides functions to parse and produce GEDCOM files.
GEDCOM (Genealogical Data Communication) is a standard format used for
exchanging genealogical data between software applications. This package
includes functionality for both parsing existing GEDCOM files and generating
new ones.
# Decoding GEDCOM Files
The package provides a streaming [Decoder] for reading GEDCOM files. Use
[NewDecoder] to create a decoder that reads from an [io.Reader]:
data, err := os.ReadFile("family.ged")
if err != nil {
log.Fatal(err)
}
d := gedcom.NewDecoder(bytes.NewReader(data))
g, err := d.Decode()
if err != nil {
log.Fatal(err)
}
for _, ind := range g.Individual {
if len(ind.Name) > 0 {
fmt.Println(ind.Name[0].Name)
}
}
The decoder is streaming and can handle large files without loading the entire
contents into memory.
# Encoding GEDCOM Files
The package also provides an [Encoder] for generating GEDCOM files. Use
[NewEncoder] to create an encoder that writes to an [io.Writer]:
g := &gedcom.Gedcom{
Header: &gedcom.Header{
SourceSystem: gedcom.SystemRecord{
Xref: "MyApp",
ProductName: "My Application",
},
CharacterSet: "UTF-8",
},
Individual: []*gedcom.IndividualRecord{
{
Xref: "I1",
Name: []*gedcom.NameRecord{
{Name: "John /Doe/"},
},
Sex: "M",
},
},
Trailer: &gedcom.Trailer{},
}
f, err := os.Create("output.ged")
if err != nil {
log.Fatal(err)
}
defer f.Close()
enc := gedcom.NewEncoder(f)
if err := enc.Encode(g); err != nil {
log.Fatal(err)
}
# Data Model
The [Gedcom] struct is the top-level container returned by the decoder and
accepted by the encoder. It contains slices of records for individuals,
families, sources, and other GEDCOM record types.
[IndividualRecord] represents a person and contains their names, sex, life
events (birth, death, etc.), family links, and citations.
[FamilyRecord] represents a family unit and links to husband, wife, and
children as [IndividualRecord] pointers.
[EventRecord] is a flexible type used for both events (birth, death, marriage)
and attributes (occupation, residence). The Tag field indicates the event type.
[SourceRecord] and [CitationRecord] handle source citations for genealogical
claims.
# Name Parsing
The [SplitPersonalName] helper function parses GEDCOM-formatted names:
parsed := gedcom.SplitPersonalName("John \"Jack\" /Smith/ Jr.")
// parsed.Given = "John"
// parsed.Nickname = "Jack"
// parsed.Surname = "Smith"
// parsed.Suffix = "Jr."
# User-Defined Tags
GEDCOM allows custom tags prefixed with an underscore. These are captured in
[UserDefinedTag] slices on most record types, preserving vendor-specific
extensions.
# Specification Coverage
This package implements approximately 80% of the GEDCOM 5.5 specification,
which is sufficient for parsing about 99% of real-world GEDCOM files. It has
not been extensively tested with non-ASCII character sets.
*/
package gedcom