/// <summary> /// Deal with a single line. It either starts with '0' and is to be a new record, /// or is accumulated into a record. /// </summary> /// <param name="line"></param> /// <param name="lineNum"></param> private bool ProcessLine(char [] line, int lineNum) { int len = line.Length; int dex = LineUtil.FirstChar(line, 0, len); if (dex < 0) { if (_emptyLineSeen == 0) { DoError(UnkRec.ErrorCode.EmptyLine, lineNum); } _emptyLineSeen++; return(true); // empty line } if (len > 255) // TODO anything special for UTF-16? { DoError(UnkRec.ErrorCode.LineTooLong, lineNum); // proceed anyway } char level = line[dex]; if (level < '0' || level > '9') { DoError(UnkRec.ErrorCode.InvLevel, lineNum); return(false); // cannot proceed } // NOTE: do NOT warn about leading spaces "GEDCOM readers should ignore it when it occurs". if (level == '0' && _currRec.LineCount > 0) { // start of a new record. deal with the previous record first // TODO records should go into a 'to parse' list and asynchronously turned into head/indi/fam/etc var parsed = Parser.Parse(_currRec); if (parsed == null) { return(false); } Data.Add(parsed); _currRec = new GedRecord(lineNum, line); } else { _currRec.AddLine(line); } return(true); }
/// <summary> /// Determine the level value for a line. /// </summary> /// <param name="linedex">Index in the record for the line in question</param> /// <param name="sublinedex">The index WITHIN the line for the first character. non-zero if leading spaces.</param> /// <returns>Space on error; otherwise the level as a character</returns> public char GetLevel(int linedex, out int sublinedex) { sublinedex = -1; if (linedex >= Max) { return(' '); } var line = _lines[linedex]; int dex = LineUtil.FirstChar(line, 0, line.Length); // Can't happen? empty lines stripped earlier... //if (dex < 0) // return ' '; // empty line sublinedex = dex; return(line[dex]); // TODO can level values exceed 9 ??? }