Example #1
0
        public static Address OtherTag(ParseContextCommon ctx, string Tag, Address exist)
        {
            // These tags are not subordinate to the ADDR struct. Strictly speaking,
            // the ADDR tag is required, but allow it not to exist.
            Address addr = exist ?? new Address();

            switch (Tag)
            {
            case "PHON":
                addr.Phon.Add(ctx.Remain);
                break;

            case "WWW":
                addr.WWW.Add(ctx.Remain);
                break;

            case "EMAIL":
                addr.Email.Add(ctx.Remain);
                break;

            case "FAX":
                addr.Fax.Add(ctx.Remain);
                break;
            }
            return(addr);
        }
Example #2
0
 public void Init(ParseContextCommon ctx, StructCommon parent, int linedex = 0)
 {
     base.Init(ctx);
     Parent  = parent;
     Begline = linedex;
     Endline = linedex;
 }
Example #3
0
        public static StructParseContext Alloc(ParseContextCommon ctx, StructCommon parent, int linedex)
        {
            var spc = _pool.GetObject();

            spc.Init(ctx, parent, linedex);
            return(spc);
        }
Example #4
0
        //public StructParseContext(ParseContext2 ctx, StructCommon parent)
        //    : base(ctx)
        //{
        //    Parent = parent;
        //    Record = ctx.Parent;
        //}

        //public StructParseContext(ParseContextCommon ctx, StructCommon parent, int linedex = 0)
        //    : base(ctx)
        //{
        //    // TODO pass Level, Record into here?
        //    Parent = parent;
        //    Begline = linedex;
        //    Endline = linedex;
        //}

        public StructParseContext(ParseContextCommon ctx, int linedex, char level, StructCommon parent)
            : base(ctx)
        {
            Parent  = parent;
            Begline = linedex;
            Endline = linedex;
            Level   = level;
        }
Example #5
0
        public static Note NoteParser(ParseContextCommon ctx, int linedex, char level)
        {
            Note note = new Note();

            note.Builder = new StringBuilder(512);
            var ctx2 = PContextFactory.Alloc(ctx, note, linedex); // TODO no record for context!

            ctx2.Level = level;

            if (ctx as ParseContext2 != null)
            {
                ctx2.Record = (ctx as ParseContext2).Parent;
            }
            // FAM.NOTE.SOUR crapped out 'cause Record was null
            if (ctx as StructParseContext != null)
            {
                ctx2.Record = (ctx as StructParseContext).Record;
            }

            if (!string.IsNullOrEmpty(ctx.Remain) && ctx.Remain[0] == '@')
            {
                note.Xref = ctx.Remain.Trim(trim);
            }
            else
            {
                note.Builder.Append(ctx.gs.RemainLS(ctx.Lines.GetLine(linedex)));
                //note.Builder.Append(ctx.Remain); // NOTE: trailing spaces are preserved, may be confusing
            }

            StructParse(ctx2, tagDict);

            if (note.Builder.Length > 0)
            {
                // Store an in-line note to the database
                string text = note.Builder.ToString().Replace("@@", "@");
#if SQLITE
                note.Key = SQLite.Instance.StoreNote(text);
#elif LITEDB
                note.Key = LiteDB.Instance.StoreNote(text);
#elif NOTESTREAM
                note.Key = NoteStream.Instance.StoreNote(text);
#else
                note.Text = text;
#endif
            }
            else
            {
                note.Text = "";
            }

            //note.Text = note.Builder.ToString().Replace("@@", "@"); // TODO faster replace;
            note.Builder = null;
            ctx.Endline  = ctx2.Endline;
            PContextFactory.Free(ctx2);
            return(note);
        }
Example #6
0
        internal void Init(ParseContextCommon ctx)
        {
            Lines   = ctx.Lines;
            Begline = ctx.Begline;
            Endline = ctx.Endline;
            Level   = ctx.Level;
            Remain1 = ctx.Remain1;
            gs      = ctx.gs;

            tagCache = ctx.tagCache;
        }
Example #7
0
        private static SourceCit CommonParser(ParseContextCommon ctx, int linedex, char level, List <UnkRec> errs)
        {
            SourceCit          cit  = new SourceCit();
            StructParseContext ctx2 = new StructParseContext(ctx, linedex, level, cit); // TODO no record for context!

            string extra;
            string xref;

            parseXrefExtra(ctx.Remain, out xref, out extra);

            cit.Xref = xref;
            if (xref != null && (xref.Trim().Length == 0 || cit.Xref.Contains("@")))  // No xref is valid but not if empty/illegal
            {
                var unk = new UnkRec();
                unk.Error = UnkRec.ErrorCode.InvXref; // TODO {Error = "Invalid source citation xref id"};
                unk.Beg   = ctx.Begline + ctx.Lines.Beg;
                unk.End   = ctx.Endline + ctx.Lines.Beg;
                errs.Add(unk);
            }
            if (!string.IsNullOrEmpty(extra))
            {
                cit.Desc = extra;
            }

            StructParse(ctx2, tagDict);
            ctx.Endline = ctx2.Endline;

            if (!cit.Data && cit.Xref != null && cit.AnyText)
            {
                var unk = new UnkRec();
                unk.Error = UnkRec.ErrorCode.RefSourText; // TODO { Error = "TEXT tag used for reference source citation" };
                unk.Beg   = ctx.Begline + ctx.Lines.Beg;
                unk.End   = ctx2.Endline + ctx.Lines.Beg;
                errs.Add(unk);
            }
            if (cit.Xref == null && cit.Event != null)
            {
                var unk = new UnkRec();
                unk.Error = UnkRec.ErrorCode.EmbSourEven; // TODO { Error = "EVEN tag used for embedded source citation" };
                unk.Beg   = ctx.Begline + ctx.Lines.Beg;
                unk.End   = ctx2.Endline + ctx.Lines.Beg;
                errs.Add(unk);
            }
            if (cit.Xref == null && cit.Page != null)
            {
                var unk = new UnkRec();
                unk.Error = UnkRec.ErrorCode.EmbSourPage; // TODO { Error = "PAGE tag used for embedded source citation" };
                unk.Beg   = ctx.Begline + ctx.Lines.Beg;
                unk.End   = ctx.Endline + ctx.Lines.Beg;
                errs.Add(unk);
            }
            return(cit);
        }
Example #8
0
 public ParseContextCommon(ParseContextCommon ctx)
 {
     Init(ctx);
 }