Compare commits
No commits in common. "master" and "v0.1.9" have entirely different histories.
55
Records.cs
55
Records.cs
@ -11,8 +11,6 @@ namespace Txt2Bib.Records
|
||||
|
||||
public abstract record ItemType
|
||||
{
|
||||
public string Pages { get; set; } = "";
|
||||
|
||||
protected static bool IsDoi(string url)
|
||||
{
|
||||
return url.Contains("doi");
|
||||
@ -22,16 +20,7 @@ namespace Txt2Bib.Records
|
||||
a = a.Trim();
|
||||
var s = a.Split(' ');
|
||||
return s.Length > 1 ?
|
||||
$"{s[1]} {s[0][0]}{s[0][1..].ToLower()}" : a;
|
||||
}
|
||||
|
||||
protected string CreatePages(string pages)
|
||||
{
|
||||
if (pages.Length == 0) { return ""; }
|
||||
|
||||
return pages.Split('-').Length == 2 ?
|
||||
$"{pages.Split('-')[0]}--{pages.Split('-')[1].TrimEnd('.')}" :
|
||||
pages;
|
||||
$"{s[1]} {s[0][0]}{s[0][1..].ToLowerInvariant()}" : a;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +33,8 @@ namespace Txt2Bib.Records
|
||||
public ushort Year { get; set; } = 1950;
|
||||
public string Volume { get; set; } = "";
|
||||
public string? Issue { get; set; } = null;
|
||||
public ushort FirstPage { get; set; } = 1;
|
||||
public ushort LastPage { get; set; } = 1;
|
||||
public string Doi { get; set; } = "";
|
||||
public string Url { get; set; } = "";
|
||||
|
||||
@ -59,7 +50,15 @@ namespace Txt2Bib.Records
|
||||
Volume = entryLines[5] != string.Empty ? checkVol(entryLines[5]) : Volume;
|
||||
Issue = entryLines[5].Split(',').Length == 2 ?
|
||||
entryLines[5].Split(',')[1].Trim() : Issue;
|
||||
Pages = CreatePages(entryLines[6]);
|
||||
try
|
||||
{
|
||||
FirstPage = ushort.Parse(entryLines[6].Split('-')[0]);
|
||||
LastPage = ushort.Parse(entryLines[6].Split('-')[1].TrimEnd('.'));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("Formato pagine non corretto");
|
||||
}
|
||||
|
||||
if (entryLines.Length > 7 )
|
||||
{
|
||||
@ -79,7 +78,7 @@ namespace Txt2Bib.Records
|
||||
$"\tyear = \"{Year}\",\n" +
|
||||
$"\tvolume = \"{Volume}\",\n" +
|
||||
$"\tnumber = \"{Issue}\",\n" +
|
||||
$"\tpages = \"{Pages}\",\n" +
|
||||
$"\tpages = \"{FirstPage}--{LastPage}\",\n" +
|
||||
$"\tdoi = \"{Doi}\",\n" +
|
||||
$"\turl = \"{Url}\",\n" +
|
||||
"}\n";
|
||||
@ -165,6 +164,8 @@ namespace Txt2Bib.Records
|
||||
public string Publisher { get; set; } = "";
|
||||
public string Series { get; set; } = "";
|
||||
public string Address { get; set; } = "";
|
||||
public ushort FirstPage { get; set; } = 1;
|
||||
public ushort LastPage { get; set; } = 1;
|
||||
public string Url { get; set; } = "";
|
||||
public string Doi { get; set; } = "";
|
||||
|
||||
@ -180,7 +181,15 @@ namespace Txt2Bib.Records
|
||||
Series = entryLines[6] != String.Empty ? entryLines[6] : Series;
|
||||
Address = entryLines[7] != String.Empty ? entryLines[7] : Address;
|
||||
Publisher = entryLines[8];
|
||||
Pages = CreatePages(entryLines[9]);
|
||||
try
|
||||
{
|
||||
FirstPage = ushort.Parse(entryLines[9].Split('-')[0]);
|
||||
LastPage = ushort.Parse(entryLines[9].Split('-')[1].TrimEnd('.'));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("Formato numeri di pagina errato...");
|
||||
}
|
||||
|
||||
if (entryLines.Length > 10)
|
||||
{
|
||||
@ -207,7 +216,7 @@ namespace Txt2Bib.Records
|
||||
$"\tseries = {{{Series}}},\n" +
|
||||
$"\taddress = \"{Address}\",\n" +
|
||||
$"\tyear = \"{Year}\",\n" +
|
||||
$"\tpages = \"{Pages}\",\n" +
|
||||
$"\tpages = \"{FirstPage}--{LastPage}\",\n" +
|
||||
$"\turl = \"{Url}\",\n" +
|
||||
$"\tdoi = \"{Doi}\",\n" +
|
||||
"}\n";
|
||||
@ -225,6 +234,8 @@ namespace Txt2Bib.Records
|
||||
public string Publisher { get; set; } = "";
|
||||
public string Series { get; set; } = "";
|
||||
public string Address { get; set; } = "";
|
||||
public ushort FirstPage { get; set; } = 1;
|
||||
public ushort LastPage { get; set; } = 1;
|
||||
public string Url { get; set; } = "";
|
||||
public string Doi { get; set; } = "";
|
||||
|
||||
@ -238,7 +249,15 @@ namespace Txt2Bib.Records
|
||||
Series = entryLines[6] != String.Empty ? entryLines[6] : Series;
|
||||
Address = entryLines[7] != String.Empty ? entryLines[7] : Address;
|
||||
Publisher = entryLines[8];
|
||||
Pages = CreatePages(entryLines[9]);
|
||||
try
|
||||
{
|
||||
FirstPage = ushort.Parse(entryLines[9].Split('-')[0]);
|
||||
LastPage = ushort.Parse(entryLines[9].Split('-')[1].TrimEnd('.'));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new Exception("Formato numeri di pagina errato...");
|
||||
}
|
||||
|
||||
if (entryLines.Length > 10)
|
||||
{
|
||||
@ -264,7 +283,7 @@ namespace Txt2Bib.Records
|
||||
$"\tseries = {{{Series}}},\n" +
|
||||
$"\taddress = \"{Address}\",\n" +
|
||||
$"\tyear = \"{Year}\",\n" +
|
||||
$"\tpages = \"{Pages}\",\n" +
|
||||
$"\tpages = \"{FirstPage}--{LastPage}\",\n" +
|
||||
$"\turl = \"{Url}\",\n" +
|
||||
$"\tdoi = \"{Doi}\",\n" +
|
||||
"}\n";
|
||||
|
@ -15,7 +15,7 @@ namespace Txt2Bib
|
||||
/// </summary>
|
||||
public class Text2Bib
|
||||
{
|
||||
private readonly string[] _citTypes = { "J", "B", "C", "P", "PB" };
|
||||
private readonly string[] _citTypes = { "J", "B", "C", "P" };
|
||||
|
||||
/// <summary>
|
||||
/// Generate single .bib file from input text files
|
||||
@ -43,8 +43,8 @@ namespace Txt2Bib
|
||||
{
|
||||
using var reader = File.OpenText(path);
|
||||
byte[] contentBytes = File.ReadAllBytes(path);
|
||||
// Assumes UTF8!
|
||||
var content = Encoding.UTF8.GetString(contentBytes);
|
||||
// Use Windows 1252??
|
||||
var content = Encoding.Latin1.GetString(contentBytes);
|
||||
|
||||
IEnumerable<string> entries = new List<string>();
|
||||
try
|
||||
@ -85,7 +85,6 @@ namespace Txt2Bib
|
||||
{
|
||||
"J" => new Article().Convert(lines),
|
||||
"B" => new Book().Convert(lines),
|
||||
"PB" => new Book().Convert(lines),
|
||||
"C" => new Chapter().Convert(lines),
|
||||
"P" => new Proceedings().Convert(lines),
|
||||
_ => ""
|
||||
|
@ -5,7 +5,7 @@
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
<Version>0.2.0</Version>
|
||||
<Version>0.1.9</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user