diff --git a/Records.cs b/Records.cs index 16f07a3..6ffb53d 100644 --- a/Records.cs +++ b/Records.cs @@ -71,7 +71,7 @@ namespace Txt2Bib.Records public override string ToString() { - return $"@{Type}{{{Author[0][..5]}_{Year},\n" + + return $"@{Type}{{{Author[0][..5].Replace(". ", "_")}_{Year},\n" + $"\tauthor = \"{string.Join(" and ", Author)}\",\n" + $"\ttitle = {{{Title}}},\n" + $"\tjournal = \"{Journal}\",\n" + @@ -88,7 +88,8 @@ namespace Txt2Bib.Records public record class BookBib : IBib { public string Type { get; init; } = "book"; - public string[] Author { get; set; } = { "Gianni e Pinotto" }; + public string[] Author { get; set; } = Array.Empty(); + public string[] Editor { get; set; } = Array.Empty(); public string Title { get; set; } = ""; public ushort Year { get; set; } = 1950; public string Publisher { get; set; } = ""; @@ -104,7 +105,15 @@ namespace Txt2Bib.Records var s = a.Split(' '); return $"{s[1]} {s[0]}"; }; - Author = entryLines[1].Split(',').Select(a => rearrange(a)).ToArray(); + var auths = entryLines[1]; + if (auths.Contains("eds")) + { + Editor = auths.Replace("(eds.)", "").Split(',').Select(a => rearrange(a)).ToArray(); + } + else + { + Author = auths.Split(',').Select(a => rearrange(a)).ToArray(); + } Year = ushort.Parse(entryLines[2]); Title = entryLines[3]; Place = entryLines[4]; @@ -126,13 +135,28 @@ namespace Txt2Bib.Records public override string ToString() { - return $"@{Type}{{{Author[0][..5]}_{Year},\n" + - $"\tauthor = \"{string.Join(" and ", Author)}\",\n" + + var label = ""; + var authString = ""; + + if (Author.Length != 0) + { + label = Author[0][..5].Replace(". ", ""); + authString = $"\tauthor = \"{string.Join(" and ", Author)}\",\n"; + } + else + { + label = Editor[0][..5].Replace(". ", ""); + authString = $"\teditor = \"{string.Join(" and ", Editor)}\",\n"; + } + + return $"@{Type}{{{label}_{Year},\n" + + authString + $"\ttitle = {{{Title}}},\n" + $"\tpublisher = \"{Publisher}\",\n" + $"\taddress = \"{Place}\",\n" + $"\tyear = \"{Year}\",\n" + $"\turl = \"{Url}\",\n" + + $"\tdoi = \"{Doi}\",\n" + "}\n"; } } diff --git a/Text2Bib.cs b/Text2Bib.cs index a049b50..3c3d19a 100644 --- a/Text2Bib.cs +++ b/Text2Bib.cs @@ -77,8 +77,7 @@ namespace Txt2Bib if (!IsValidEntry(type)) throw new Exception($"Invalid entry type '{type}'"); - string citation = ""; - + string citation; try { citation = type switch