diff --git a/MainWindow.xaml b/MainWindow.xaml index 4b5024a..64f2830 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -5,21 +5,22 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:Txt2Bib" mc:Ignorable="d" - Title="MainWindow" Height="900" Width="800"> - - - - diff --git a/Records.cs b/Records.cs new file mode 100644 index 0000000..1969734 --- /dev/null +++ b/Records.cs @@ -0,0 +1,29 @@ +using System; + +namespace Txt2Bib.Records +{ + public interface IBib { } + public record class ArticleBib : IBib + { + public string Type { get; init; } = "article"; + public string[] Author { get; init; } = { "" }; + 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 override string ToString() + { + return $"@{Type}\\{{{Author[0][..5]}_{Year}," + + $"\ttitle = \"{Title}\"," + + $"\tjournal = \"{Journal}\"," + + $"\tyear = \"{Year}\"," + + $"\tvolume = \"{Volume}\"," + + $"\tnumber = \"{Issue}\"," + + $"\tpages = \"{FirstPage}--{LastPage}\","; + } + } +} \ No newline at end of file diff --git a/Text2Bib.cs b/Text2Bib.cs index 3c39e78..49d444f 100644 --- a/Text2Bib.cs +++ b/Text2Bib.cs @@ -6,11 +6,25 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Controls.Primitives; using System.Windows; +using Txt2Bib.Records; +using System.ComponentModel.DataAnnotations; namespace Txt2Bib { internal class Text2Bib { + private readonly Dictionary _citTypes = new() + { + { "J" , "article"}, + { "B", "book" }, + { "P", "conference" }, + { "C" , "inbook" } + }; + /// + /// Generate single .bib file from input text files + /// + /// + /// public string Generate(string filenames) { var paths = filenames.Trim().Split('\n'); @@ -23,24 +37,36 @@ namespace Txt2Bib byte[] contentBytes = File.ReadAllBytes(path); result += Encoding.Latin1.GetString(contentBytes); - // How to determine actual encoding?? - /* - result += reader.CurrentEncoding.CodePage switch - { - 65001 => Encoding.UTF8.GetString(contentBytes), - _ => Encoding.Latin1.GetString(contentBytes) - }; - */ - } - //TODO process entry - foreach (string item in result.Split('%')) + var entries = result.Split('%').ToList().Select(entry => { - output += item; + return Process(entry); + }); + + foreach (var entry in entries) + { + output += entries; } return output; } + + private IBib Process(string entryFromTxt) + { + return new ArticleBib(); + } + + /// + /// TODO: How to determine correct encoding of text file?? + /// + /// The stream reader for the file + /// + private Encoding GuessEncoding(StreamReader reader) + { + var cp = "UTF-8"; + return Encoding.GetEncoding(cp); + + } } }