diff --git a/MainWindow.xaml b/MainWindow.xaml
index 7ed98c3..5fd0ec1 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -21,6 +21,11 @@
+
diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs
index d144778..9e0443b 100644
--- a/MainWindow.xaml.cs
+++ b/MainWindow.xaml.cs
@@ -77,5 +77,11 @@ namespace Txt2Bib
var txt2bib = new Text2Bib();
Debug.Text = txt2bib.Generate(DropArea.Text);
}
+
+ private void CopyDebug_Click(object sender, RoutedEventArgs e)
+ {
+ Debug.SelectAll();
+ Debug.Copy();
+ }
}
}
diff --git a/Records.cs b/Records.cs
index d66d0ce..a2b5c3b 100644
--- a/Records.cs
+++ b/Records.cs
@@ -1,26 +1,30 @@
using System;
+using System.Configuration;
+using System.Linq;
+using System.Text.RegularExpressions;
namespace Txt2Bib.Records
{
- public interface IBib { }
+ public interface IBib { public string ToString(); }
public record class ArticleBib : IBib
{
public string Type { get; init; } = "article";
- public string[] Author { get; init; } = { "Gianni e Pinotto" };
- public string Title { get; init; } = "";
- public string Journal { get; init; } = "";
- public ushort Year { get; init; } = 1950;
- public ushort Volume { get; init; } = 1;
- public byte Issue { get; init; } = 1;
- public ushort FirstPage { get; init; } = 1;
- public ushort LastPage { get; init; } = 1;
- public string Doi { get; init; } = "";
- public string Url { get; init; } = "";
+ public string[] Author { get; set; } = { "Gianni e Pinotto" };
+ public string Title { get; set; } = "";
+ public string Journal { get; set; } = "";
+ public ushort Year { get; set; } = 1950;
+ public ushort Volume { get; set; } = 1;
+ public byte? 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; } = "";
public override string ToString()
{
return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" +
+ $"\tauthor = \"{string.Join(" and ", Author)}\",\n" +
$"\ttitle = \"{Title}\",\n" +
$"\tjournal = \"{Journal}\",\n" +
$"\tyear = \"{Year}\",\n" +
@@ -36,16 +40,17 @@ namespace Txt2Bib.Records
public record class BookBib : IBib
{
public string Type { get; init; } = "book";
- public string[] Author { get; init; } = { "Gianni e Pinotto" };
- public string Title { get; init; } = "";
- public string Publisher { get; init; } = "";
- public string Place { get; init; } = "";
- public string Url { get; init; } = "";
- public ushort Year { get; init; } = 1950;
+ public string[] Author { get; set; } = { "Gianni e Pinotto" };
+ public string Title { get; set; } = "";
+ public string Publisher { get; set; } = "";
+ public string Place { get; set; } = "";
+ public string Url { get; set; } = "";
+ public ushort Year { get; set; } = 1950;
public override string ToString()
{
return $"@{Type}" + "{" +$"{Author[0][..5]}_{Year},\n" +
+ $"\tauthor = \"{string.Join(" and", Author)}\",\n" +
$"\ttitle = \"{Title}\",\n" +
$"\tpublisher = \"{Publisher}\",\n" +
$"\taddress = \"{Place}\",\n" +
diff --git a/Text2Bib.cs b/Text2Bib.cs
index 6a33db2..a0422b6 100644
--- a/Text2Bib.cs
+++ b/Text2Bib.cs
@@ -15,7 +15,7 @@ namespace Txt2Bib
{
private readonly Dictionary _citTypes = new()
{
- { "J" , "article"},
+ { "J" , "article" },
{ "B", "book" },
{ "P", "conference" },
{ "C" , "inbook" }
@@ -41,7 +41,7 @@ namespace Txt2Bib
var entries = result.Split('%').ToList().Select(entry =>
{
- return Process(entry).ToString();
+ return Process(entry);
});
foreach (var entry in entries)
@@ -52,23 +52,53 @@ namespace Txt2Bib
return output;
}
- private IBib Process(string entryFromTxt)
+ private string Process(string entryFromTxt)
{
- var lines = entryFromTxt.Trim().Split("\n");
+ var lines = entryFromTxt.Trim().Replace("\r", string.Empty).Split("\n");
var type = lines.First();
System.Diagnostics.Debug.WriteLine($"Entry: {entryFromTxt}; Prima riga: {type}");
- IBib citType = type switch
+ string citation = type switch
{
- "J" => new ArticleBib(),
- "B" => new BookBib(),
+ "J" => ConvertArticle(lines),
+ //"B" => new BookBib(),
//"C" => new ChapterBib(),
//"P" => new ConferenceBib(),
- _ => new ArticleBib(),
+ _ => ConvertArticle(lines),
};
- return citType;
+ return citation;
+ }
+
+ private static string ConvertArticle(string[] entryLines)
+ {
+ var temp = entryLines[1].Split(',');
+ var rearrange = (string a) =>
+ {
+ a = a.Trim();
+ var s = a.Split(' ');
+ return $"{s[1]} {s[0]}";
+ };
+ var authors = temp.Select(a => rearrange(a)).ToArray();
+ var article = new ArticleBib
+ {
+ Author = authors,
+ Year = ushort.Parse(entryLines[2]),
+ Title = entryLines[3],
+ Journal = entryLines[4],
+ // TODO split with ',' for issue
+ Volume = entryLines[5].Split(',').Length == 2 ?
+ byte.Parse(entryLines[5].Split(',')[0]) :
+ byte.Parse(entryLines[5]),
+ Issue = entryLines[5].Split(',').Length == 2 ?
+ byte.Parse(entryLines[5].Split(',')[1]) : null,
+ FirstPage = ushort.Parse(entryLines[6].Split('-')[0]),
+ LastPage = ushort.Parse(entryLines[6].Split('-')[1]),
+ Doi = entryLines.Length > 7 ? entryLines[7] : "",
+ };
+
+ return article.ToString();
}
///
diff --git a/Txt2Bib.csproj b/Txt2Bib.csproj
index 4106cb0..261334f 100644
--- a/Txt2Bib.csproj
+++ b/Txt2Bib.csproj
@@ -7,4 +7,12 @@
true
+
+
+
+
+
+
+
+
diff --git a/copy-icon.png b/copy-icon.png
new file mode 100644
index 0000000..5144d82
Binary files /dev/null and b/copy-icon.png differ