Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Oct 17, 2024
1 parent 483ccba commit bae85f1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
10 changes: 5 additions & 5 deletions JL.Core/Dicts/JMnedict/JmnedictEntry.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace JL.Core.Dicts.JMnedict;

internal ref struct JmnedictEntry()
internal readonly ref struct JmnedictEntry(int id, List<string> kebList, List<string> rebList, List<Translation> translationList)
{
public int Id { get; set; } = 0;
public List<string> KebList { get; } = [];
public List<string> RebList { get; } = [];
public List<Translation> TranslationList { get; } = [];
public int Id { get; } = id;
public List<string> KebList { get; } = kebList;
public List<string> RebList { get; } = rebList;
public List<Translation> TranslationList { get; } = translationList;
}
26 changes: 16 additions & 10 deletions JL.Core/Dicts/JMnedict/JmnedictLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public static async Task Load(Dict dict)

private static JmnedictEntry ReadEntry(XmlTextReader xmlReader)
{
JmnedictEntry entry = new();
int id = 0;
List<string> kebList = [];
List<string> rebList = [];
List<Translation> translationList = [];

while (!xmlReader.EOF)
{
if (xmlReader is { Name: "entry", NodeType: XmlNodeType.EndElement })
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -126,7 +130,9 @@ private static string ReadREle(XmlTextReader xmlReader)

private static Translation ReadTrans(XmlTextReader xmlReader)
{
Translation translation = new();
List<string> nameTypeList = [];
List<string> transDetList = [];

while (!xmlReader.EOF)
{
if (xmlReader is { Name: "trans", NodeType: XmlNodeType.EndElement })
Expand All @@ -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":
Expand All @@ -162,7 +168,7 @@ private static Translation ReadTrans(XmlTextReader xmlReader)
}
}

return translation;
return new Translation(nameTypeList, transDetList);
}

private static string ReadEntity(XmlTextReader xmlReader)
Expand Down
8 changes: 4 additions & 4 deletions JL.Core/Dicts/JMnedict/Translation.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace JL.Core.Dicts.JMnedict;

internal sealed class Translation
internal sealed class Translation(List<string> nameTypeList, List<string> transDetList)
{
public List<string> NameTypeList { get; } = [];
public List<string> TransDetList { get; } = [];
//public List<string> XRefList { get; } = []
public List<string> NameTypeList { get; } = nameTypeList;
public List<string> TransDetList { get; } = transDetList;
//public List<string> XRefList { get; }
}

0 comments on commit bae85f1

Please sign in to comment.