Exemplo n.º 1
0
        private Tuple <object, GedParse> Make(GedRecord rec)
        {
            // 1. The first line in the rec should start with '0'
            var head = rec.FirstLine();

            gs.Split(head, ' ');
            char lvl = gs.Level(head);

            //int firstDex = LineUtil.FirstChar(head);
            //if (head[firstDex] != '0')
            if (lvl != '0')
            {
                var rec2 = new Unknown(rec, null, gs.Tag(head));
                //rec2.Error = UnkRec.ErrorCode.InvLevel;
                return(new Tuple <object, GedParse>(rec2, null));
                //throw new Exception("record head not zero"); // TODO should this be an error record instead?
            }

            // 2. search for and find the tag
            //LineUtil.LineData ld = new LineUtil.LineData(); // TODO static?
            //LineUtil.LevelTagAndRemain(ld, head);

            //gs.Split(head, ' ');

            // 3. create a GedCommon derived class
            var remain = new string(gs.Remain(head));

            return(GedRecFactory(rec, gs.Ident(head), gs.Tag(head), remain));
            //return GedRecFactory(rec, ld.Ident, ld.Tag, ld.Remain);
        }
Exemplo n.º 2
0
        private Tuple <object, GedParse> GedRecFactory(GedRecord rec, string ident, string tag, string remain)
        {
            if (string.IsNullOrWhiteSpace(tag))
            {
                var foo = new Unknown(rec, ident, "");
                foo.Errors.Add(new UnkRec {
                    Error = UnkRec.ErrorCode.MissTag
                });
                return(new Tuple <object, GedParse>(foo, null));
            }

            // Parse 'top level' records. Parsing of some record types (e.g. NOTE, SOUR, etc) are likely to be in 'common' with sub-record parsing

            // TODO Very much brute force. If/until this is found to be optimizable
            switch (tag.ToUpper())
            {
            case "INDI":
                return(new Tuple <object, GedParse>(new IndiRecord(rec, ident, remain), _IndiParseSingleton));

            case "FAM":
                return(new Tuple <object, GedParse>(new FamRecord(rec, ident, remain), _FamParseSingleton));

            case "SOUR":
                return(new Tuple <object, GedParse>(new SourceRecord(rec, ident, remain), _SourParseSingleton));

            case "REPO":
                return(new Tuple <object, GedParse>(new Repository(rec, ident, remain), _RepoParseSingleton));

            case "NOTE":
            {
                string remainLS = gs.RemainLS(rec.FirstLine());
                return(new Tuple <object, GedParse>(new NoteRecord(rec, ident, remainLS), _NoteParseSingleton));
            }

            case "OBJE":
                return(new Tuple <object, GedParse>(new MediaRecord(rec, ident, remain), _MediaParseSingleton));

            case "HEAD":
                return(new Tuple <object, GedParse>(new HeadRecord(rec), _HeadParseSingleton));

            case "TRLR":
                return(null);

            case "SUBM":     // TODO temp ignore
            case "SUBN":     // TODO temp ignore
                return(new Tuple <object, GedParse>(new DontCare(rec, tag), null));

            default:
            {
                var foo = new Unknown(rec, ident, tag);
                return(new Tuple <object, GedParse>(foo, null));
            }
            }
        }