Example #1
0
        public static ParseResult <GedcomEvent> Parse(GedcomLine first, ILineProvider lineProvider)
        {
            GedcomEvent gedcomEvent = new GedcomEvent();

            var initialLevel = first.Level;

            GedcomLine line = default;
            string     currentRawLine;

            while ((currentRawLine = lineProvider.ReadLine()) != null)
            {
                line = ParserHelper.ParseLine(currentRawLine);

                if (line.Level <= first.Level)
                {
                    break;
                }

                switch (line.GetTagOrRef())
                {
                case "DATE":
                    // If checks we're parsing actual date and not
                    // CREA or CHAN tags
                    // TODO: should actually put CREA and CHAN into different parser
                    if (line.Level == initialLevel + 1)
                    {
                        gedcomEvent.Date = line.GetLineContent();
                    }
                    break;

                case "PLAC":
                    // If checks we're parsing actual date and not
                    // CREA or CHAN tags
                    // TODO: should actually put CREA and CHAN into different parser
                    if (line.Level == initialLevel + 1)
                    {
                        gedcomEvent.Location = line.GetLineContent();
                    }
                    break;
                }
            }

            return(ParseResult.Create(gedcomEvent, line));
        }
Example #2
0
        public static ParseResult <GedcomHeader> Parse(GedcomLine first, ILineProvider lineProvider)
        {
            CurrentLevel currentLevel = CurrentLevel.None;

            var header = new GedcomHeader();

            GedcomLine line = default;
            string     currentRawLine;

            while ((currentRawLine = lineProvider.ReadLine()) != null)
            {
                line = ParserHelper.ParseLine(currentRawLine);

                if (line.Level == 0)
                {
                    break;
                }

                if (line.Level == 1)
                {
                    switch (line.GetTagOrRef())
                    {
                    case "SOUR":
                        currentLevel = CurrentLevel.Sour;
                        break;

                    case "GEDC":
                        currentLevel = CurrentLevel.Gedc;
                        break;

                    case "CHAR":
                        header.GedcomCharacterSet = line.GetLineContent();
                        break;
                    }
                }
                else if (line.Level == 2)
                {
                    if (currentLevel == CurrentLevel.Sour)
                    {
                        switch (line.GetTagOrRef())
                        {
                        case "NAME":
                            header.SourceName = line.GetLineContent();
                            break;

                        case "VERS":
                            header.SourceVers = line.GetLineContent();
                            break;

                        case "CORP":
                            header.SourceCorp = line.GetLineContent();
                            break;
                        }
                    }
                    else if (currentLevel == CurrentLevel.Gedc)
                    {
                        if (line.GetTagOrRef() == "VERS")
                        {
                            header.GedcomVers = line.GetLineContent();
                        }
                    }
                }
            }

            return(ParseResult.Create(header, line));
        }
Example #3
0
        public static ParseResult <Family> Parse(GedcomLine first, ILineProvider lineProvider)
        {
            var family = new Family();

            family.ID = ParserHelper.ParseID(first.GetTagOrRef());

            bool inMarriage = false;

            var initialLevel = first.Level;

            GedcomLine line = default;
            string     currentRawLine;

            while ((currentRawLine = lineProvider.ReadLine()) != null)
            {
                line = ParserHelper.ParseLine(currentRawLine);

                if (line.Level == first.Level)
                {
                    break;
                }

                switch (line.GetTagOrRef())
                {
                case "MARR":
                {
                    inMarriage = true;
                    break;
                }

                case "DATE":
                    if (inMarriage)     // TODO: should have MARR parser
                    {
                        var date = line.GetLineContent();
                        if (family.Marriage == null)
                        {
                            family.Marriage = new GedcomEvent();
                        }
                        family.Marriage.Date = date;
                    }
                    break;

                case "PLAC":
                    if (inMarriage)     // Assume level + 1 is MARR
                    {
                        var place = line.GetLineContent();
                        if (family.Marriage == null)
                        {
                            family.Marriage = new GedcomEvent();
                        }
                        family.Marriage.Location = place;
                    }
                    break;

                case "HUSB":
                    // Ignore any husband and wife information in the middle of a marriage tag.
                    // Present for torture test files - and info redundant?
                    // can have e.g. "2 HUSB", with no additional info
                    var contentHusb = line.GetLineContent();
                    if (!string.IsNullOrEmpty(contentHusb))
                    {
                        family.HusbandID = ParserHelper.ParseID(contentHusb);
                    }
                    break;

                case "WIFE":
                    // Ignore any husband and wife information in the middle of a marriage tag.
                    // Present for torture test files - and info redundant?
                    // can have e.g. "2 HUSB", with no additional info
                    var contentWife = line.GetLineContent();
                    if (!string.IsNullOrEmpty(contentWife))
                    {
                        family.WifeID = ParserHelper.ParseID(contentWife);
                    }
                    break;

                case "CHIL":
                    family.ChildIDs.Add(ParserHelper.ParseID(line.GetLineContent()));
                    break;

                default:
                    inMarriage = false;
                    break;
                }
            }

            return(ParseResult.Create(family, line));
        }