Skip to content

Commit

Permalink
#72 Fix up issues on Stravaig.Gedcom project
Browse files Browse the repository at this point in the history
  • Loading branch information
colinangusmackay committed Jan 9, 2021
1 parent 859275c commit 9aebbdd
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/Stravaig.Gedcom/Extensions/CharExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static bool IsGedcomAlphanum(this char target)
/// where, respectively:
/// (0x21)-(0x22)=! "
/// (0x24)-(0x2F)=$ % & ' ( ) * + , - . /
/// (0x3A)-(0x3F)=: ; < = > ?
/// (0x3A)-(0x3F)=: ; &lt; = > ?
/// (0x5B)-(0x5E)=[ \ ] ^
/// (0x60)=`
/// (0x7B)-(0x7E)={ | } ~
Expand Down
2 changes: 0 additions & 2 deletions src/Stravaig.Gedcom/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using Stravaig.Gedcom.Model;

namespace Stravaig.Gedcom.Extensions
{
public static class StringExtensions
{
private const char PointerBookend = (char) 0x40; // @ symbol.
private const char Zero = (char) 0x30; // number 0.

/// <summary>
/// Determines if the target string is a valid pointer identifier.
Expand Down
1 change: 0 additions & 1 deletion src/Stravaig.Gedcom/GedcomLine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics;
using System.Text;

Expand Down
2 changes: 1 addition & 1 deletion src/Stravaig.Gedcom/GedcomLineReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class GedcomLineReader : IDisposable
private readonly GedcomLineParser _parser;
private readonly TextReader _reader;
private int _lineNumber;
private bool _isAtEnd = false;
private bool _isAtEnd;

public GedcomLineReader(TextReader reader)
{
Expand Down
1 change: 0 additions & 1 deletion src/Stravaig.Gedcom/GedcomPointer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Data.Common;
using Stravaig.Gedcom.Extensions;

namespace Stravaig.Gedcom
Expand Down
1 change: 0 additions & 1 deletion src/Stravaig.Gedcom/GedcomRecord.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion src/Stravaig.Gedcom/GedcomRecordReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class GedcomRecordReader
{
private readonly GedcomLineReader _reader;
private int _lineNumber;
private GedcomLine _peekedLine = null;
private GedcomLine _peekedLine;
public GedcomRecordReader(GedcomLineReader reader)
{
_reader = reader;
Expand Down
1 change: 0 additions & 1 deletion src/Stravaig.Gedcom/Model/Comparers/DateComparer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Stravaig.Gedcom.Constants;
using Stravaig.Gedcom.Settings;

Expand Down
1 change: 0 additions & 1 deletion src/Stravaig.Gedcom/Model/EventRecord.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using Stravaig.Gedcom.Extensions;

// EVENT_DETAIL:=
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Net.NetworkInformation;

namespace Stravaig.Gedcom.Model.Extensions
{
public static class GedcomPlaceRecordExtensions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Diagnostics;
using System.Linq;
using Stravaig.Gedcom.Extensions;

namespace Stravaig.Gedcom.Model.Extensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,7 @@ private static bool IsSubjectEntryOrIsInSubjectLifetime(GedcomIndividualRecord s
var deathDate = subject.DeathEvent?.Date;
return te.Date.IsBetween(birthDate, deathDate);
}

private static IEnumerable<TimelineEntry> GetBirthAndDeathOnly(GedcomIndividualRecord subject)
{
if (subject.BirthEvent != null)
yield return new TimelineEntry(subject, subject.BirthEvent);
if (subject.DeathEvent != null)
yield return new TimelineEntry(subject, subject.DeathEvent);
}


private static IEnumerable<TimelineEntry> GetAllEvents(GedcomIndividualRecord subject)
{
HashSet<GedcomPointer> individualsYielded = new HashSet<GedcomPointer>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Xml;

namespace Stravaig.Gedcom.Model.Extensions
{
Expand Down
1 change: 0 additions & 1 deletion src/Stravaig.Gedcom/Model/GedcomIndividualRecord.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Data.Common;
using System.Linq;
using Stravaig.Gedcom.Extensions;

Expand Down
4 changes: 0 additions & 4 deletions src/Stravaig.Gedcom/Model/GedcomNoteRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ public class GedcomNoteRecord : MultiLineTextRecord
{
public static readonly GedcomTag NoteTag = "NOTE".AsGedcomTag();

private readonly Lazy<string> _noteText;

public GedcomNoteRecord(GedcomRecord record, GedcomDatabase database)
: base(record, database)
{
if (record.Tag != NoteTag)
throw new ArgumentException("Expected a \"NOTE\" record.", nameof(record));

_noteText = new Lazy<string>(GetText);
}

public GedcomPointer? CrossReferenceId => _record.CrossReferenceId;
Expand Down
3 changes: 0 additions & 3 deletions src/Stravaig.Gedcom/Model/GedcomSourceRecord.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Stravaig.Gedcom.Extensions;

// From Pages 27. 28
Expand Down
98 changes: 58 additions & 40 deletions src/Stravaig.Gedcom/Model/Parsers/DateParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,40 @@ namespace Stravaig.Gedcom.Model.Parsers
{
public class DateParser
{
private const string SymbolAbout = "ABT";
private const string SymbolAboutAlt = "ABOUT";
private const string SymbolAfter = "AFT";
private const string SymbolAfterAlt = "AFTER";
private const string SymbolAnd = "AND";
private const string SymbolBefore = "BEF";
private const string SymbolBeforeAlt = "BEFORE";
private const string SymbolBetween = "BET";
private const string SymbolBetweenAlt = "BETWEEN";
private const string SymbolCalculated = "CAL";
private const string SymbolEstimated = "EST";
private const string SymbolFrom = "FROM";
private const string SymbolInterpreted = "INT";
private const string SymbolTo = "TO";

private static readonly string[] MonthNames = new[]
static class Symbol
{
public const string About = "ABT";
public const string AboutAlt = "ABOUT";
public const string After = "AFT";
public const string AfterAlt = "AFTER";
public const string And = "AND";
public const string Before = "BEF";
public const string BeforeAlt = "BEFORE";
public const string Between = "BET";
public const string BetweenAlt = "BETWEEN";
public const string Calculated = "CAL";
public const string Estimated = "EST";
public const string From = "FROM";
public const string Interpreted = "INT";
public const string To = "TO";
}

private static readonly string[] MonthNames =
{
// THE GEDCOM STANDARD-release-5.5.1.pdf
// P52/53
"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
"JAN",
"FEB",
"MAR",
"APR",
"MAY",
"JUN",
"JUL",
"AUG",
"SEP",
"OCT",
"NOV",
"DEC"
};

private enum State
Expand Down Expand Up @@ -247,25 +261,25 @@ private void ParseDateValue()
return;
}

if (IsCurrentTokenOneOf(SymbolFrom, SymbolTo))
if (IsCurrentTokenOneOf(Symbol.From, Symbol.To))
{
ParseDatePeriod();
return;
}

if (IsCurrentTokenOneOf(SymbolBefore, SymbolAfter, SymbolBetween, SymbolBeforeAlt, SymbolAfterAlt, SymbolBetweenAlt))
if (IsCurrentTokenOneOf(Symbol.Before, Symbol.After, Symbol.Between, Symbol.BeforeAlt, Symbol.AfterAlt, Symbol.BetweenAlt))
{
ParseDateRange();
return;
}

if (IsCurrentTokenOneOf(SymbolAbout, SymbolCalculated, SymbolEstimated, SymbolAboutAlt))
if (IsCurrentTokenOneOf(Symbol.About, Symbol.Calculated, Symbol.Estimated, Symbol.AboutAlt))
{
ParseDateApproximated();
return;
}

if (IsCurrentToken(SymbolInterpreted))
if (IsCurrentToken(Symbol.Interpreted))
{
ParseDateInterpreted();
return;
Expand Down Expand Up @@ -340,9 +354,9 @@ private void ParseDateInterpreted()

private void ParseDateApproximated()
{
if (IsCurrentTokenOneOf(SymbolAbout, SymbolAboutAlt))
if (IsCurrentTokenOneOf(Symbol.About, Symbol.AboutAlt))
Type = DateType.ApproximatedAbout;
else if (IsCurrentToken(SymbolCalculated))
else if (IsCurrentToken(Symbol.Calculated))
Type = DateType.ApproximatedCalculated;
else
Type = DateType.ApproximatedEstimated;
Expand All @@ -354,26 +368,26 @@ private void ParseDateApproximated()
private void ParseDateRange()
{
Type = DateType.Range;
if (IsCurrentTokenOneOf(SymbolBefore, SymbolBeforeAlt))
if (IsCurrentTokenOneOf(Symbol.Before, Symbol.BeforeAlt))
{
_state = State.SecondDate;
MoveNext();
ParseDate();
MoveNext();
}
else if (IsCurrentTokenOneOf(SymbolAfter, SymbolAfterAlt))
else if (IsCurrentTokenOneOf(Symbol.After, Symbol.AfterAlt))
{
_state = State.FirstDate;
MoveNext();
ParseDate();
MoveNext();
}
else if (IsCurrentTokenOneOf(SymbolBetween, SymbolBetweenAlt))
else if (IsCurrentTokenOneOf(Symbol.Between, Symbol.BetweenAlt))
{
_state = State.FirstDate;
MoveNext();
ParseDate();
if (IsCurrentToken(SymbolAnd))
if (IsCurrentToken(Symbol.And))
{
_state = State.SecondDate;
MoveNext();
Expand All @@ -389,51 +403,55 @@ private void ParseDateRange()
private void ParseDatePeriod()
{
Type = DateType.Period;
if (IsCurrentToken(SymbolFrom))
if (IsCurrentToken(Symbol.From))
{
_state = State.FirstDate;
MoveNext();
ParseDate();
}

if (IsCurrentToken(SymbolTo))
if (IsCurrentToken(Symbol.To))
{
_state = State.SecondDate;
MoveNext();
ParseDate();
}
}

private void ParseCalendarEscape()
{
Action<CalendarType> setCalendar =
_state == State.FirstDate
? new Action<CalendarType>(c => Calendar1 = c)
: new Action<CalendarType>(c => Calendar2 = c);
void SetCalendar(CalendarType calendar)
{
if (_state == State.FirstDate)
Calendar1 = calendar;
else
Calendar2 = calendar;
}

switch (_currentToken)
{
case "@#DHEBREW@":
setCalendar(CalendarType.Hebrew);
SetCalendar(CalendarType.Hebrew);
break;
case "@#DROMAN@":
setCalendar(CalendarType.Roman);
SetCalendar(CalendarType.Roman);
break;
case "@#DFRENCH":
MoveNext();
ParseCalendarEscape();
return;
case "@#DFRENCHR@":
case "R@":
setCalendar(CalendarType.French);
SetCalendar(CalendarType.French);
break;
case "@#DGREGORIAN@":
setCalendar(CalendarType.Gregorian);
SetCalendar(CalendarType.Gregorian);
break;
case "@#DJULIAN@":
setCalendar(CalendarType.Julian);
SetCalendar(CalendarType.Julian);
break;
case "@#DUNKNOWN@":
setCalendar(CalendarType.Unknown);
SetCalendar(CalendarType.Unknown);
break;
default:
throw new InvalidOperationException($"Expected a Calendar Escape, but got \"{_currentToken}\".");
Expand Down
1 change: 0 additions & 1 deletion src/Stravaig.Gedcom/Model/Record.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Stravaig.Gedcom.Extensions;

namespace Stravaig.Gedcom.Model
Expand Down
2 changes: 1 addition & 1 deletion src/Stravaig.Gedcom/Model/Relationship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Stravaig.Gedcom.Model
{
public readonly struct Relationship
{
public static readonly Relationship NotRelated = new Relationship(Model.Gender.Unknown, GenerationZeroRelationships.NotGenZero);
public static readonly Relationship NotRelated = new Relationship(Gender.Unknown, GenerationZeroRelationships.NotGenZero);
private readonly GenerationZeroRelationships _generationZero;

public Relationship(Gender gender, int directedGenerationsRemoved, Qualification qualification = Qualification.Biological)
Expand Down
1 change: 0 additions & 1 deletion src/Stravaig.Gedcom/Model/TimelineEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Text;
using Stravaig.Gedcom.Extensions;

Expand Down

0 comments on commit 9aebbdd

Please sign in to comment.