From ce4eeccd54e48aa2733989c99fffc8128c72645f Mon Sep 17 00:00:00 2001 From: femsci Date: Tue, 26 Dec 2023 17:19:12 +0100 Subject: [PATCH] init; VCF --- .gitignore | 2 + Nyanbyte.IDShare.sln | 27 ++++ .../Nyanbyte.IDShare.Vcf.csproj | 9 ++ src/Nyanbyte.IDShare.Vcf/Vcard.cs | 128 ++++++++++++++++++ 4 files changed, 166 insertions(+) create mode 100644 .gitignore create mode 100644 Nyanbyte.IDShare.sln create mode 100644 src/Nyanbyte.IDShare.Vcf/Nyanbyte.IDShare.Vcf.csproj create mode 100644 src/Nyanbyte.IDShare.Vcf/Vcard.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afec7c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/obj/ +**/bin/ diff --git a/Nyanbyte.IDShare.sln b/Nyanbyte.IDShare.sln new file mode 100644 index 0000000..b4a8c28 --- /dev/null +++ b/Nyanbyte.IDShare.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3E1B6FBD-3EAA-4729-B808-0E6B2BCDB7A7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nyanbyte.IDShare.Vcf", "src\Nyanbyte.IDShare.Vcf\Nyanbyte.IDShare.Vcf.csproj", "{8696BF96-C969-4A1B-B1D1-A4BA47634DEA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8696BF96-C969-4A1B-B1D1-A4BA47634DEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8696BF96-C969-4A1B-B1D1-A4BA47634DEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8696BF96-C969-4A1B-B1D1-A4BA47634DEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8696BF96-C969-4A1B-B1D1-A4BA47634DEA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {8696BF96-C969-4A1B-B1D1-A4BA47634DEA} = {3E1B6FBD-3EAA-4729-B808-0E6B2BCDB7A7} + EndGlobalSection +EndGlobal diff --git a/src/Nyanbyte.IDShare.Vcf/Nyanbyte.IDShare.Vcf.csproj b/src/Nyanbyte.IDShare.Vcf/Nyanbyte.IDShare.Vcf.csproj new file mode 100644 index 0000000..fa71b7a --- /dev/null +++ b/src/Nyanbyte.IDShare.Vcf/Nyanbyte.IDShare.Vcf.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + + diff --git a/src/Nyanbyte.IDShare.Vcf/Vcard.cs b/src/Nyanbyte.IDShare.Vcf/Vcard.cs new file mode 100644 index 0000000..524949e --- /dev/null +++ b/src/Nyanbyte.IDShare.Vcf/Vcard.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nyanbyte.IDShare.Vcf; + +public class Vcard +{ + + public DateTime? Birthday { get; set; } + + public static Vcard FromString(string data) + { + data = data.Trim(); + + string[] lines = data.Split('\n'); + + if (lines.Length < 3) + { + throw new ArgumentException("Invalid data."); + } + + if (lines[0] != "BEGIN:VCARD" || lines[^1] != "END:VCARD") + { + throw new ArgumentException("Not a proper VCF format."); + } + + if (lines[1] != "VERSION:4.0") + { + throw new ArgumentException("Invalid data: This implementation supports only VCF version 4.0."); + } + + foreach (string line in lines[2..^2]) + { + string keyword = line[..line.IndexOf(':')]; + string? type = null; + if (keyword.Contains(';')) + { + type = keyword[(keyword.IndexOf(';') + 1)..]; + keyword = keyword[..keyword.IndexOf(';')]; + } + + switch (keyword) + { + case "ADR": + NotImplemented(); + break; + case "BDAY": + NotImplemented(); + break; + case "CATEGORIES": + NotImplemented(); + break; + case "EMAIL": + NotImplemented(); + break; + case "FN": + NotImplemented(); + break; + case "GENDER": + NotImplemented(); + break; + case "KEY": + NotImplemented(); + break; + case "KIND": + NotImplemented(); + break; + case "LOGO": + NotImplemented(); + break; + case "N": + NotImplemented(); + break; + case "NICKNAME": + NotImplemented(); + break; + case "NOTE": + NotImplemented(); + break; + case "ORG": + NotImplemented(); + break; + case "PHOTO": + NotImplemented(); + break; + case "REV": + NotImplemented(); + break; + case "ROLE": + NotImplemented(); + break; + case "TEL": + NotImplemented(); + break; + case "TITLE": + NotImplemented(); + break; + case "TZ": + NotImplemented(); + break; + case "URL": + NotImplemented(); + break; + } + } + + throw new NotImplementedException(); + } + + private static void NotImplemented() + { + //nimpl or msg + throw new NotImplementedException(); + } + + public override string ToString() + { + StringBuilder sb = new("BEGIN:VCARD\nVERSION:4.0;\n"); + + throw new NotImplementedException(); + + sb.Append("END:VCARD"); + return sb.ToString(); + } +}