private bool AddressParse(GedcomAddress address, string tag, string lineValue, GedcomLineValueType lineValueType) { bool done = false; // FIXME: checking for ADDR is wrong, doesn't work properly, ok to just // check address is not null? Real solution is to use a stack for PreviousTag // like it should have been doing in the first place // PreviousTag is now using a stack so will return the parent tag, which should be ADDR if (address != null || _ParseState.PreviousTag == "ADDR") { switch (tag) { case "CONT": address.AddressLine += Environment.NewLine; address.AddressLine += lineValue; done = true; break; case "ADR1": if (lineValueType == GedcomLineValueType.DataType) { address.AddressLine1 = lineValue; } done = true; break; case "ADR2": if (lineValueType == GedcomLineValueType.DataType) { address.AddressLine2 = lineValue; } done = true; break; case "ADR3": if (lineValueType == GedcomLineValueType.DataType) { address.AddressLine3 = lineValue; } done = true; break; case "CITY": if (lineValueType == GedcomLineValueType.DataType) { address.City = lineValue; } done = true; break; case "STAE": if (lineValueType == GedcomLineValueType.DataType) { address.State = lineValue; } done = true; break; case "POST": if (lineValueType == GedcomLineValueType.DataType) { address.PostCode = lineValue; } done = true; break; case "CTRY": if (lineValueType == GedcomLineValueType.DataType) { address.Country = lineValue; } done = true; break; } } return done; }
private void Parser_TagFound(object sender, EventArgs e) { _level = _Parser.Level; _xrefID = _Parser.XrefID; _tag = TagMap(_Parser.Tag); _lineValue = _Parser.LineValue; _lineValueType = _Parser.LineValueType; GedcomRecord current = null; // pop previous levels from the stack current = PopStack(_level); if (current == null) { switch (_tag) { case "FAM": // must have an xref id to have a family record // otherwise it can't be referenced anywhere if (!string.IsNullOrEmpty(_xrefID)) { current = new GedcomFamilyRecord(); } break; case "INDI": // must have an xref id to have an individual record // otherwise it can't be referenced anywhere if (!string.IsNullOrEmpty(_xrefID)) { current = new GedcomIndividualRecord(); } break; case "OBJE": // must have an xref id to have a multimedia record // otherwise it can't be referenced anywhere if (!string.IsNullOrEmpty(_xrefID)) { current = new GedcomMultimediaRecord(); } break; case "NOTE": // must have an xref id to have a note record // otherwise it can't be referenced anywhere if (!string.IsNullOrEmpty(_xrefID)) { GedcomNoteRecord note = new GedcomNoteRecord(); current = note; // set initial note text if needed if (_lineValueType == GedcomLineValueType.DataType) { note.ParsedText.Append(_lineValue); } else if (_lineValue != string.Empty) { // pointer to a note, this should not occur // as we should be at level 0 here Debug.WriteLine("Spurious Note pointer: " + _xrefID + "\t at level: " + _level); } } break; case "REPO": // must have an xref id to have a repository record // otherwise it can't be referenced anywhere if (!string.IsNullOrEmpty(_xrefID)) { current = new GedcomRepositoryRecord(); } break; case "SOUR": // must have an xref id to have a source record // otherwise it can't be referenced anywhere if (!string.IsNullOrEmpty(_xrefID)) { current = new GedcomSourceRecord(); } break; case "SUBM": // must have an xref id to have a submitter record // otherwise it can't be referenced anywhere if (!string.IsNullOrEmpty(_xrefID)) { current = new GedcomSubmitterRecord(); } break; case "HEAD": // header record current = new GedcomHeader(); break; case "SUBN": // Submission record if (!string.IsNullOrEmpty(_xrefID)) { current = new GedcomSubmissionRecord(); } break; case "TRLR": break; default: // Unknown tag Debug.WriteLine("Unknown: " + _tag + " at level: " + _level); break; } // if we created a new record push it onto the stack if (current != null) { if (!string.IsNullOrEmpty(_xrefID)) { current.XRefID = _xrefID; } current.Database = _ParseState.Database; current.Level = _level; _ParseState.Records.Push(current); } } else { switch (current.RecordType) { case GedcomRecordType.Header: ReadHeaderRecord(); break; case GedcomRecordType.Family: ReadFamilyRecord(); break; case GedcomRecordType.Individual: ReadIndividualRecord(); break; case GedcomRecordType.Multimedia: ReadMultimediaRecord(); break; case GedcomRecordType.Note: ReadNoteRecord(); break; case GedcomRecordType.Repository: ReadRepositoryRecord(); break; case GedcomRecordType.Source: ReadSourceRecord(); break; case GedcomRecordType.Submitter: ReadSubmitterRecord(); break; case GedcomRecordType.Submission: ReadSubmissionRecord(); break; // Non top level records case GedcomRecordType.Event: ReadEventRecord(); break; case GedcomRecordType.FamilyEvent: ReadEventRecord(); break; case GedcomRecordType.IndividualEvent: ReadEventRecord(); break; case GedcomRecordType.Place: ReadPlaceRecord(); break; case GedcomRecordType.SourceCitation: ReadSourceCitationRecord(); break; case GedcomRecordType.FamilyLink: ReadFamilyLinkRecord(); break; case GedcomRecordType.Association: ReadAssociationRecord(); break; case GedcomRecordType.Name: ReadNameRecord(); break; case GedcomRecordType.Date: ReadDateRecord(); break; case GedcomRecordType.RepositoryCitation: ReadRepositoryCitation(); break; case GedcomRecordType.CustomRecord: ReadEventRecord(); break; } } _ParseState.AddPreviousTag(_tag, _level); }
/// <summary> /// Parses the given data, which should be 1 or more lines, multiple /// calls can be made with multiple lines. /// Events are triggered upon reading a line, or on an error. /// If TagCollection and XrefTagCollection haven't been set /// prior to calling default IndexedKeyCollection objects will be /// used. To support replacing XRefs you need to set XrefTagCollection /// to an instance of XRefIndexedKeyCollection before calling. /// </summary> /// <param name="data">Data to parse, expected to be unicode</param> public bool GedcomParse(string data) { _Error = GedcomErrorState.NoError; int i = 0; int len = data.Length; // Tags are always the same, data.Substring was allocating lots // of memory, instead use a special collection which matches via // array index, e.g tagCollection[str, index, length] to avoid // the extra allocations, and caches the resulting string for // use again without having to substring if (_tagCollection == null) { _tagCollection = new Utility.IndexedKeyCollection(); } // same for Xrefs if (_xrefCollection == null) { _xrefCollection = new Utility.IndexedKeyCollection(); } while (i < len) { int temp = i; switch (_State) { case GedcomState.Level: // eat up leading white space while (temp < len && char.IsWhiteSpace(data[temp])) { temp ++; } bool hadLevel = false; int lvl = 0; while (temp < len && IsDigit(data[temp])) { hadLevel = true; lvl *= 10; lvl += (((int)data[temp++]) - (int)'0'); } // possible we had data after eating white space // but that it wasn't a digit if (!hadLevel) { if (ApplyConcContOnNewLineHack && (_previousTag == "CONC" || _previousTag == "CONT")) { _Level = _previousLevel; _Tag = "CONC"; _State = GedcomState.LineValue; } else { _Error = GedcomErrorState.LevelExpected; } } else if (temp == i) { if (!char.IsWhiteSpace(data[i])) { _Error = GedcomErrorState.LevelExpected; } else { i ++; } } else { _Level = lvl; if (_Level > MaxLevel) { _Error = GedcomErrorState.LevelInvalid; _Level = -1; } else { i = temp; } } // move to next state if we have a level // and we are still in a level state (may not be // if we have some hacks active) if (_Level != -1 && _State == GedcomState.Level) { if (IsDelim(data[i])) { i ++; if (IgnoreInvalidDelim) { while (i < len && IsDelim(data[i])) { i ++; } _State = GedcomState.XrefID; } else if (IsDelim(data[i])) { _Error = GedcomErrorState.InvalidDelim; } else { _State = GedcomState.XrefID; } } else { _Error = GedcomErrorState.LevelMissingDelim; } } break; case GedcomState.XrefID: // no optional xref id just move to next state // otherwise extract pointer if (IsXrefID(data,temp)) { // bypass first @ i ++; temp = i; while (temp < len && data[temp] != '@') { temp ++; } if ( (temp - i) > MaxXRefLength) { _Error = GedcomErrorState.XrefIDTooLong; } else { _XrefID = _xrefCollection[data, i, temp - i]; i = temp + 1; if (IsDelim(data[i])) { i ++; if (IgnoreInvalidDelim) { while (i < len && IsDelim(data[i])) { i ++; } _State = GedcomState.Tag; } else if (IsDelim(data[i])) { _Error = GedcomErrorState.InvalidDelim; } else { _State = GedcomState.Tag; } } else { _Error = GedcomErrorState.XrefIDMissingDelim; } } } else { _State = GedcomState.Tag; } break; case GedcomState.Tag: while (temp < len && (IsAlphaNum(data[temp]) || (AllowHyphenOrUnderscoreInTag && (data[temp] == '-' || data[temp] == '_')))) { temp ++; } if (temp == i) { _Error = GedcomErrorState.TagExpected; } else { _Tag = _tagCollection[data, i, temp - i]; i = temp; } if (_Tag != string.Empty) { if (_Tag == "TRLR" && i == len) { FoundTag(); } else { if (i < len && IsDelim(data[i])) { i ++; _State = GedcomState.LineValue; } // not else if so we can handle tags with a trailing space but no line value if (i == len || IsTerminator(data[i])) { FoundTag(); while (i < len && IsTerminator(data[i])) { i ++; } } else if (_State != GedcomState.LineValue && !IgnoreMissingTerms) { _Error = GedcomErrorState.TagMissingDelimOrTerm; } } } break; case GedcomState.LineValue: if (IsPointer(data,temp)) { // bypass first @ i ++; temp = i; while (temp < len && data[temp] != '@') { temp ++; } if ((temp - i) > 0) { _LineValue = _xrefCollection[data, i, temp - i]; i = temp + 1; _LineValueType = GedcomLineValueType.PointerType; } // GEDCOM only allows a single XREF for a pointer // Genopro ignores this and puts a comma separated // list of XREFs in the mess it pretends is GEDCOM. // This causes us to get stuck in the LineValue state // (this could of cause happen with anything after the // pointer) if (i < len) { // we will allow white space, but nothing else while (i < len && IsDelim(data[i])) { i ++; } if (i < len && !IsTerminator(data[i])) { _Error = GedcomErrorState.LineValueInvalid; } } } else { while (_Error == GedcomErrorState.NoError && _LineValue == string.Empty) { if (temp < len && IsAnyChar(data,temp)) { temp ++; } else if (temp < len && IsEscape(data,temp)) { // bypass @# temp += 2; while (temp < len && data[temp] != '@') { temp ++; } temp ++; } // hack for presidents.ged, email address // is used in PHON on line 13 with a single @ // this isn't valid GEDCOM // Should be escaped as @@ but handle it anyway // Same thing occurs in user supplied file TOUT200801_unicode.ged // with RELA @INDI:BAPM else if (temp < len && data[temp] == '@') { temp ++; } else if (temp != i) { if ((temp < len) && !IsTerminator(data[temp])) { _Error = GedcomErrorState.LineValueInvalid; } else { temp = Math.Min(temp, len); string dup = data.Substring(i, temp - i); // unescape @@ _LineValue = dup.Replace("@@", "@"); _LineValueType = GedcomLineValueType.DataType; } i = temp; } // FIXME: no line value, but have hit the terminator // what should this be allowed for? // Family Tree Maker outputs emtpy CONT (and CONC?) else if (_Tag == "CONT" || _Tag == "CONC") { _LineValue = " "; } else { // hit a terminator break; } } } if (_Error == GedcomErrorState.NoError) { // can't use FoundTag here, may not want to reset _previousLevel = _Level; _previousTag = _Tag; if (TagFound != null) { TagFound(this,EventArgs.Empty); } if (i == len || IsTerminator(data[i])) { while (i < len && IsTerminator(data[i])) { i ++; } // reset states ResetParseState(false); } else if (!IgnoreMissingTerms) { _Error = GedcomErrorState.LineValueMissingTerm; } } break; } if (_Error != GedcomErrorState.NoError) { if (ParserError != null) { ParserError(this,EventArgs.Empty); } break; } } // reset parse status for more input ResetParseState(false); return (_Error == GedcomErrorState.NoError); }
private void ReadIndividualRecord() { GedcomIndividualRecord individualRecord; individualRecord = _ParseState.Records.Peek() as GedcomIndividualRecord; GedcomIndividualEvent individualEvent; // some custom tags we convert to generic facts/events // this means we have to set the line value to the type // they represent, so store the real line value and use // for the event classification. string customToGenericClassification = string.Empty; if (_tag.StartsWith("_")) { switch (_tag) { // we convert _MILT to EVEN Military Service case "_MILT": _tag = "EVEN"; _lineValue = "Military Service"; _lineValueType = GedcomLineValueType.DataType; break; // we convert _MDCL to FACT Medical case "_MDCL": _tag = "FACT"; customToGenericClassification = _lineValue; _lineValue = "Medical"; _lineValueType = GedcomLineValueType.DataType; break; // we convert _HEIG to FACT Height case "_HEIG": _tag = "FACT"; customToGenericClassification = _lineValue; _lineValue = "Height"; _lineValueType = GedcomLineValueType.DataType; break; // we convert _WEIG to FACT Weight case "_WEIG": _tag = "FACT"; customToGenericClassification = _lineValue; _lineValue = "Weight"; _lineValueType = GedcomLineValueType.DataType; break; default: GedcomCustomRecord custom = new GedcomCustomRecord(); custom.Level = _level; custom.XRefID = _xrefID; custom.Tag = _tag; if (_lineValueType == GedcomLineValueType.DataType) { custom.Classification = _lineValue; } // FIXME: may want to use customs at some point //individualRecord.Events.Add(custom); _ParseState.Records.Push(custom); break; } } if (_level == individualRecord.ParsingLevel + 1) { switch (_tag) { case "FAMC": if (_lineValueType == GedcomLineValueType.PointerType) { GedcomFamilyLink childIn = new GedcomFamilyLink(); childIn.Level = _level; childIn.Family = _lineValue; childIn.Indi = individualRecord.XRefID; _missingReferences.Add(_lineValue); individualRecord.ChildIn.Add(childIn); _ParseState.Records.Push(childIn); } break; case "FAMS": if (_lineValueType == GedcomLineValueType.PointerType) { GedcomFamilyLink spouseIn = new GedcomFamilyLink(); spouseIn.Level = _level; spouseIn.Family = _lineValue; spouseIn.Indi = individualRecord.XRefID; spouseIn.PreferedSpouse = (individualRecord.SpouseIn.Count == 0); _missingReferences.Add(_lineValue); individualRecord.SpouseIn.Add(spouseIn); _ParseState.Records.Push(spouseIn); } break; case "ASSO": if (_lineValueType == GedcomLineValueType.PointerType) { GedcomAssociation association = new GedcomAssociation(); association.Level = _level; association.Individual = _lineValue; _missingReferences.Add(_lineValue); individualRecord.Associations.Add(association); _ParseState.Records.Push(association); } break; case "RESN": if (_lineValueType == GedcomLineValueType.DataType) { try { individualRecord.RestrictionNotice = EnumHelper.Parse<GedcomRestrictionNotice>(_lineValue,true); } catch { Debug.WriteLine("Invalid restriction type: " + _lineValue); // default to confidential to protect privacy individualRecord.RestrictionNotice = GedcomRestrictionNotice.Confidential; } } break; case "NAME": if (_lineValueType == GedcomLineValueType.DataType) { GedcomName name = new GedcomName(); name.Database = _ParseState.Database; name.Level = _level; name.Name = _lineValue; name.PreferedName = (individualRecord.Names.Count == 0); individualRecord.Names.Add(name); _ParseState.Records.Push(name); } break; // Invalid, but seen from Family Origins, Family Tree Maker, Personal Ancestral File, and Legacy case "AKA": if (_lineValueType == GedcomLineValueType.DataType) { GedcomName name = new GedcomName(); name.Database = _ParseState.Database; name.Level = _level; name.Name = _lineValue; name.Type = "aka"; name.PreferedName = (individualRecord.Names.Count == 0); individualRecord.Names.Add(name); } break; case "SEX": if (_lineValueType == GedcomLineValueType.DataType) { switch (_lineValue) { case "M": individualRecord.Sex = GedcomSex.Male; break; case "F": individualRecord.Sex = GedcomSex.Female; break; // non standard case "B": individualRecord.Sex = GedcomSex.Both; break; // non standard case "N": individualRecord.Sex = GedcomSex.Neuter; break; // non standard case "U": individualRecord.Sex = GedcomSex.Undetermined; break; } } break; case "SUBM": if (_lineValueType == GedcomLineValueType.PointerType) { individualRecord.SubmitterRecords.Add(_lineValue); _missingReferences.Add(_lineValue); } else { GedcomSubmitterRecord submitter = new GedcomSubmitterRecord(); submitter.Level = 0; // new top level submitter, always 0 submitter.ParsingLevel = _level; submitter.XRefID = Database.GenerateXref("SUBM"); _ParseState.Records.Push(submitter); individualRecord.SubmitterRecords.Add(submitter.XRefID); } break; case "ALIA": if (_lineValueType == GedcomLineValueType.PointerType) { individualRecord.Alia.Add(_lineValue); _missingReferences.Add(_lineValue); } else if (_lineValueType == GedcomLineValueType.DataType) { // Family Tree Maker doing this? // ALIA is unsupported in gedcom 5.5 as a way of // adding multiple names, the spec // does say it should be a pointer to an individual // though, not another name. // spec allows multiple NAME though, so add one // with this name GedcomName name = new GedcomName(); name.Database = _ParseState.Database; name.Level = _level; name.Name = _lineValue; name.Type = "aka"; name.PreferedName = (individualRecord.Names.Count == 0); individualRecord.Names.Add(name); } break; case "ANCI": if (_lineValueType == GedcomLineValueType.PointerType) { individualRecord.Anci.Add(_lineValue); _missingReferences.Add(_lineValue); } break; case "DESI": if (_lineValueType == GedcomLineValueType.PointerType) { individualRecord.Desi.Add(_lineValue); _missingReferences.Add(_lineValue); } break; case "RFN": if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.PermanentRecordFileNumber = _lineValue; } break; case "AFN": if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.AncestralFileNumber = _lineValue; } break; case "REFN": if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.UserReferenceNumber = _lineValue; } break; case "RIN": if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.AutomatedRecordID = _lineValue; } break; case "CHAN": GedcomChangeDate date = new GedcomChangeDate(Database); date.Level = _level; _ParseState.Records.Push(date); break; case "NOTE": AddNoteRecord(individualRecord); break; case "SOUR": AddSourceCitation(individualRecord); break; case "OBJE": AddMultimediaRecord(individualRecord); break; case "BIRT": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BIRT; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CHR": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CHR; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "DEAT": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.DEAT; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BURI": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BURI; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CREM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CREM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "ADOP": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.ADOP; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BAPM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BAPM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BARM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BARM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BASM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BASM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "BLES": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.BLES; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CHRA": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CHRA; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CONF": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CONF; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "FCOM": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.FCOM; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "ORDN": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.ORDN; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "NATU": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.NATU; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "EMIG": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.EMIG; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "IMMI": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.IMMI; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CENS": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CENS; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "PROB": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.PROB; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "WILL": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.WILL; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "GRAD": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.GRAD; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "RETI": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.RETI; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "EVEN": // event individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.GenericEvent; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Events.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "CAST": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.CASTFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "DSCR": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.DSCRFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "EDUC": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.EDUCFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "IDNO": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.IDNOFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "NATI": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.NATIFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "NCHI": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.NCHIFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "NMR": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.NMRFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "OCCU": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.OCCUFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "PROP": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.PROPFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "RELI": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.RELIFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "RESI": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.RESIFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "SSN": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.SSNFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "TITL": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.TITLFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; case "FACT": // fact individualEvent = new GedcomIndividualEvent(); individualEvent.EventType = GedcomEvent.GedcomEventType.GenericFact; individualEvent.Level = _level; individualEvent.IndiRecord = individualRecord; if (_lineValueType == GedcomLineValueType.DataType) { individualEvent.EventName = _lineValue; } if (!string.IsNullOrEmpty(customToGenericClassification)) { individualEvent.Classification = customToGenericClassification; } individualRecord.Attributes.Add(individualEvent); _ParseState.Records.Push(individualEvent); break; // Not according to the spec, but Family Tree Maker sticks // an address under an individual so we will support reading it case "ADDR": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.Address.AddressLine = _lineValue; } break; case "PHON": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(individualRecord.Address.Phone1)) { individualRecord.Address.Phone1 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Phone2)) { individualRecord.Address.Phone2 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Phone3)) { individualRecord.Address.Phone3 = _lineValue; } else { // should never occur only 3 phone numbers are allowed } } break; case "EMAIL": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(individualRecord.Address.Email1)) { individualRecord.Address.Email1 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Email2)) { individualRecord.Address.Email2 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Email3)) { individualRecord.Address.Email3 = _lineValue; } else { // should never occur only 3 emails are allowed } } break; case "FAX": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(individualRecord.Address.Fax1)) { individualRecord.Address.Fax1 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Fax2)) { individualRecord.Address.Fax2 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Fax3)) { individualRecord.Address.Fax3 = _lineValue; } else { // should never occur only 3 fax numbers are allowed } } break; case "WWW": if (individualRecord.Address == null) { individualRecord.Address = new GedcomAddress(); individualRecord.Address.Database = Database; } if (_lineValueType == GedcomLineValueType.DataType) { if (string.IsNullOrEmpty(individualRecord.Address.Www1)) { individualRecord.Address.Www1 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Www2)) { individualRecord.Address.Www2 = _lineValue; } else if (string.IsNullOrEmpty(individualRecord.Address.Www3)) { individualRecord.Address.Www3 = _lineValue; } else { // should never occur only 3 urls are allowed } } break; } } else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) && _level == _ParseState.PreviousLevel + 1) { string pTag = _ParseState.PreviousTag; if (pTag == "REFN" && _tag == "TYPE") { if (_lineValueType == GedcomLineValueType.DataType) { individualRecord.UserReferenceType = _lineValue; } } else { AddressParse(individualRecord.Address, _tag, _lineValue, _lineValueType); } } else if ( (!string.IsNullOrEmpty(_ParseState.PreviousTag)) && _level == _ParseState.PreviousLevel) { AddressParse(individualRecord.Address, _tag, _lineValue, _lineValueType); } else { // shouldn't be here Debug.WriteLine("Unknown state / tag parsing individual (" + individualRecord.XRefID + ") node: " + _tag + "\t at level: " + _level); System.Console.WriteLine("Unknown state / tag parsing individual (" + individualRecord.XRefID + ") node: " + _tag + "\t at level: " + _level); System.Console.WriteLine("Previous tag: " + _ParseState.PreviousTag + "\tPrevious Level: " + _ParseState.PreviousLevel); } }
private void ResetParseState(bool resetLevel, GedcomCharset charset) { _charset = charset; _XrefID = string.Empty; _Tag = string.Empty; _LineValue = string.Empty; _State = GedcomState.Level; if (resetLevel) { _Level = -1; _previousLevel = -1; _previousTag = string.Empty; } _LineValueType = GedcomLineValueType.NoType; }