Ejemplo n.º 1
0
        public static bool ParseGEDCOM(string text, GEDCOMRecord record)
        {
            try
            {
                // Init values.
                record.Clear();

                // Some GEDCOM files indent each record with whitespace, delete any
                // whitespace from the beginning and end of the record.
                text = text.Trim();

                // Return right away as nothing to parse.
                if (string.IsNullOrEmpty(text))
                {
                    return(false);
                }

                // Get the parts of the record.
                Match match = GEDCOMRegex.Match(text);
                record.Level = Convert.ToInt32(match.Groups["level"].Value, CultureInfo.InvariantCulture);
                record.Tag   = match.Groups["tag"].Value.Trim();
                record.Data  = match.Groups["data"].Value.Trim();

                // For records the Id is specified in the tag, and the tag in the data
                if (record.Tag[0] == '@')
                {
                    record.Id   = CleanId(record.Tag);
                    record.Tag  = record.Data;
                    record.Data = String.Empty;

                    // Some GEDCOM files have additional info,
                    // we only handle the tag info.
                    int pos = record.Tag.IndexOf(' ');
                    if (pos != -1)
                    {
                        record.Tag = record.Tag.Substring(0, pos);
                    }
                }

                // If there are cross-reference Pointers they are defined in the Data
                if (!String.IsNullOrEmpty(record.Data) && record.Data[0] == '@')
                {
                    record.XRefId = CleanId(record.Data);
                    record.Data   = String.Empty;
                }

                return(true);
            }
            catch
            {
                // This record is invalid, clear all values.
                record.Clear();
                return(false);
            }
        }