public void Test_GetGEDCOMFormat()
        {
            GEDCOMTree tree = new GEDCOMTree();

            // Tests of determine GEDCOM-format
            Assert.AreEqual(GEDCOMFormat.gf_Unknown, GEDCOMProvider.GetGEDCOMFormat(tree));
            tree.Header.Source = "GENBOX";
            Assert.AreEqual(GEDCOMFormat.gf_GENBOX, GEDCOMProvider.GetGEDCOMFormat(tree));
        }
Esempio n. 2
0
        public override string ParseString(string strValue)
        {
            GEDCOMFormat format = GEDCOMProvider.GetGEDCOMFormat(Owner);

            fApproximated = GEDCOMApproximated.daExact;
            fCalendar     = GEDCOMCalendar.dcGregorian;
            fYear         = UNKNOWN_YEAR;
            fYearBC       = false;
            fYearModifier = "";
            fMonth        = "";
            fDay          = 0;

            if (!string.IsNullOrEmpty(strValue))
            {
                if (format == GEDCOMFormat.gf_Ahnenblatt)
                {
                    strValue = PrepareAhnenblattDate(strValue);
                }

                var strTok = new StringTokenizer(strValue);
                strTok.IgnoreWhiteSpace = false;
                strTok.Next();
                strTok.SkipWhiteSpaces();

                // extract approximated
                var token = strTok.CurrentToken;
                if (token.Kind == TokenKind.Word)
                {
                    string su  = token.Value.ToUpperInvariant();
                    int    idx = SysUtils.IndexOf(GEDCOMDateApproximatedArray, su);
                    if (idx >= 0)
                    {
                        fApproximated = (GEDCOMApproximated)idx;
                        strTok.Next();
                        strTok.SkipWhiteSpaces();
                    }
                }

                // extract escape
                token = strTok.CurrentToken;
                if (token.Kind == TokenKind.Symbol && token.Value[0] == '@')
                {
                    var escapeStr = token.Value;
                    do
                    {
                        token      = strTok.Next();
                        escapeStr += token.Value;
                    } while (token.Kind != TokenKind.Symbol || token.Value[0] != '@');
                    // FIXME: check for errors

                    int idx = SysUtils.IndexOf(GEDCOMDateEscapeArray, escapeStr);
                    if (idx >= 0)
                    {
                        fCalendar = (GEDCOMCalendar)idx;
                    }

                    strTok.Next();
                    strTok.SkipWhiteSpaces();
                }

                // extract day
                token = strTok.CurrentToken;
                if (token.Kind == TokenKind.Number && token.Value.Length <= 2)
                {
                    fDay  = (byte)(int)token.ValObj;
                    token = strTok.Next();
                }

                // extract delimiter
                if (token.Kind == TokenKind.WhiteSpace && token.Value[0] == ' ')
                {
                    fDateFormat = GEDCOMDateFormat.dfGEDCOMStd;
                    token       = strTok.Next();
                }
                else if (token.Kind == TokenKind.Symbol && token.Value[0] == '.')
                {
                    fDateFormat = GEDCOMDateFormat.dfSystem;
                    token       = strTok.Next();
                }

                // extract month
                string[] monthes = GetMonthNames(fCalendar);
                if (token.Kind == TokenKind.Word)
                {
                    string mth = token.Value;

                    int idx = SysUtils.IndexOf(monthes, mth);
                    if (idx >= 0)
                    {
                        fMonth = mth;
                    }

                    token = strTok.Next();
                }
                else if (fDateFormat == GEDCOMDateFormat.dfSystem && token.Kind == TokenKind.Number)
                {
                    int idx = (int)token.ValObj;
                    fMonth = monthes[idx - 1];

                    token = strTok.Next();
                }

                // extract delimiter
                if (fDateFormat == GEDCOMDateFormat.dfSystem)
                {
                    if (token.Kind == TokenKind.Symbol && token.Value[0] == '.')
                    {
                        token = strTok.Next();
                    }
                }
                else
                {
                    if (token.Kind == TokenKind.WhiteSpace && token.Value[0] == ' ')
                    {
                        token = strTok.Next();
                    }
                }

                // extract year
                if (token.Kind == TokenKind.Number)
                {
                    fYear = (short)(int)token.ValObj;
                    token = strTok.Next();

                    // extract year modifier
                    if (token.Kind == TokenKind.Symbol && token.Value[0] == '/')
                    {
                        token = strTok.Next();
                        if (token.Kind != TokenKind.Number)
                        {
                            // error
                        }
                        fYearModifier = token.Value;
                        token         = strTok.Next();
                    }

                    // extract bc/ad
                    if (token.Kind == TokenKind.Word && token.Value[0] == 'B')
                    {
                        token = strTok.Next();
                        if (token.Kind != TokenKind.Symbol || token.Value[0] != '.')
                        {
                            // error
                        }
                        token = strTok.Next();
                        if (token.Kind != TokenKind.Word || token.Value[0] != 'C')
                        {
                            // error
                        }
                        token = strTok.Next();
                        if (token.Kind != TokenKind.Symbol || token.Value[0] != '.')
                        {
                            // error
                        }
                        strTok.Next();
                        fYearBC = true;
                    }
                }

                strValue = strTok.GetRest();
            }

            DateChanged();

            return(strValue);
        }