From bae85f18220abcffed2daf5d269fa4aec8ab5510 Mon Sep 17 00:00:00 2001 From: rampaa Date: Thu, 17 Oct 2024 20:04:26 +0300 Subject: [PATCH] Minor --- JL.Core/Dicts/JMnedict/JmnedictEntry.cs | 10 ++++----- JL.Core/Dicts/JMnedict/JmnedictLoader.cs | 26 +++++++++++++++--------- JL.Core/Dicts/JMnedict/Translation.cs | 8 ++++---- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/JL.Core/Dicts/JMnedict/JmnedictEntry.cs b/JL.Core/Dicts/JMnedict/JmnedictEntry.cs index efe6e613..e72b0ca4 100644 --- a/JL.Core/Dicts/JMnedict/JmnedictEntry.cs +++ b/JL.Core/Dicts/JMnedict/JmnedictEntry.cs @@ -1,9 +1,9 @@ namespace JL.Core.Dicts.JMnedict; -internal ref struct JmnedictEntry() +internal readonly ref struct JmnedictEntry(int id, List kebList, List rebList, List translationList) { - public int Id { get; set; } = 0; - public List KebList { get; } = []; - public List RebList { get; } = []; - public List TranslationList { get; } = []; + public int Id { get; } = id; + public List KebList { get; } = kebList; + public List RebList { get; } = rebList; + public List TranslationList { get; } = translationList; } diff --git a/JL.Core/Dicts/JMnedict/JmnedictLoader.cs b/JL.Core/Dicts/JMnedict/JmnedictLoader.cs index dc59dd8d..cef7a067 100644 --- a/JL.Core/Dicts/JMnedict/JmnedictLoader.cs +++ b/JL.Core/Dicts/JMnedict/JmnedictLoader.cs @@ -69,7 +69,11 @@ public static async Task Load(Dict dict) private static JmnedictEntry ReadEntry(XmlTextReader xmlReader) { - JmnedictEntry entry = new(); + int id = 0; + List kebList = []; + List rebList = []; + List translationList = []; + while (!xmlReader.EOF) { if (xmlReader is { Name: "entry", NodeType: XmlNodeType.EndElement }) @@ -82,19 +86,19 @@ private static JmnedictEntry ReadEntry(XmlTextReader xmlReader) switch (xmlReader.Name) { case "ent_seq": - entry.Id = xmlReader.ReadElementContentAsInt(); + id = xmlReader.ReadElementContentAsInt(); break; case "k_ele": - entry.KebList.Add(ReadKEle(xmlReader).GetPooledString()); + kebList.Add(ReadKEle(xmlReader).GetPooledString()); break; case "r_ele": - entry.RebList.Add(ReadREle(xmlReader).GetPooledString()); + rebList.Add(ReadREle(xmlReader).GetPooledString()); break; case "trans": - entry.TranslationList.Add(ReadTrans(xmlReader)); + translationList.Add(ReadTrans(xmlReader)); break; default: @@ -109,7 +113,7 @@ private static JmnedictEntry ReadEntry(XmlTextReader xmlReader) } } - return entry; + return new JmnedictEntry(id, kebList, rebList, translationList); } private static string ReadKEle(XmlTextReader xmlReader) @@ -126,7 +130,9 @@ private static string ReadREle(XmlTextReader xmlReader) private static Translation ReadTrans(XmlTextReader xmlReader) { - Translation translation = new(); + List nameTypeList = []; + List transDetList = []; + while (!xmlReader.EOF) { if (xmlReader is { Name: "trans", NodeType: XmlNodeType.EndElement }) @@ -139,11 +145,11 @@ private static Translation ReadTrans(XmlTextReader xmlReader) switch (xmlReader.Name) { case "name_type": - translation.NameTypeList.Add(ReadEntity(xmlReader)); + nameTypeList.Add(ReadEntity(xmlReader)); break; case "trans_det": - translation.TransDetList.Add(xmlReader.ReadElementContentAsString().GetPooledString()); + transDetList.Add(xmlReader.ReadElementContentAsString().GetPooledString()); break; //case "xref": @@ -162,7 +168,7 @@ private static Translation ReadTrans(XmlTextReader xmlReader) } } - return translation; + return new Translation(nameTypeList, transDetList); } private static string ReadEntity(XmlTextReader xmlReader) diff --git a/JL.Core/Dicts/JMnedict/Translation.cs b/JL.Core/Dicts/JMnedict/Translation.cs index 833273df..fc3c98f6 100644 --- a/JL.Core/Dicts/JMnedict/Translation.cs +++ b/JL.Core/Dicts/JMnedict/Translation.cs @@ -1,8 +1,8 @@ namespace JL.Core.Dicts.JMnedict; -internal sealed class Translation +internal sealed class Translation(List nameTypeList, List transDetList) { - public List NameTypeList { get; } = []; - public List TransDetList { get; } = []; - //public List XRefList { get; } = [] + public List NameTypeList { get; } = nameTypeList; + public List TransDetList { get; } = transDetList; + //public List XRefList { get; } }