Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Jan 27, 2024
1 parent cc8a00d commit 9849cbb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
45 changes: 20 additions & 25 deletions JL.Core/Utilities/TextUtils.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
using System.Text;

namespace JL.Core.Utilities;
public class TextUtils
public static class TextUtils
{
private static int FirstInvalidUnicodeSequenceIndex(string text)
{
for (int i = 0; i < text.Length; i++)
{
char c = text[i];

if (c < '\ud800')
{
continue;
}
else if (c is '\uFFFE' || char.IsLowSurrogate(c))
{
return i;
}
else if (char.IsHighSurrogate(c))
if (c >= '\ud800')
{
if (i + 1 >= text.Length || !char.IsLowSurrogate(text[i + 1]))
if (c is '\uFFFE' || char.IsLowSurrogate(c))
{
return i;
}
else

if (char.IsHighSurrogate(c))
{
if ((i + 1) >= text.Length || !char.IsLowSurrogate(text[i + 1]))
{
return i;
}

++i;
}
}
Expand All @@ -45,26 +43,23 @@ private static string RemoveInvalidUnicodeSequences(string text, int index)
{
_ = sb.Append(c);
}
else if (c is '\uFFFE' || char.IsLowSurrogate(c))
{
continue;
}
else if (char.IsHighSurrogate(c))

else if (c is not '\uFFFE' && !char.IsLowSurrogate(c))
{
if (i + 1 >= text.Length || !char.IsLowSurrogate(text[i + 1]))
if (char.IsHighSurrogate(c))
{
continue;
if ((i + 1) < text.Length && char.IsLowSurrogate(text[i + 1]))
{
_ = sb.Append(c).Append(text[i + 1]);
++i;
}
}

else
{
_ = sb.Append(c).Append(text[i + 1]);
++i;
_ = sb.Append(c);
}
}
else
{
_ = sb.Append(c);
}
}

return sb.ToString();
Expand Down
5 changes: 4 additions & 1 deletion JL.Core/WordClass/JmdictWordClassUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ await Task.Run(async () =>
}
}

await Load().ConfigureAwait(false);
if (DictUtils.WordClassDictionary.Count is 0)
{
await Load().ConfigureAwait(false);
}
}
}
2 changes: 2 additions & 0 deletions JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,8 @@ public StackPanel PrepareResultStackPanel(LookupResult result, int index, int re
PopupContextMenu,
VerticalAlignment.Center,
new Thickness(2));

_ = bottom.Children.Add(strokeCountTextBlock);
}

if (result.KanjiComposition is not null)
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/Utilities/PopupWindowUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static class PopupWindowUtils

public static TextBlock CreateTextBlock(string name, string text, Brush foregroundBrush, double fontSize, ContextMenu contextMenu, VerticalAlignment verticalAlignment, Thickness margin)
{
return new TextBlock()
return new TextBlock
{
Name = name,
Text = text,
Expand All @@ -38,7 +38,7 @@ public static TextBlock CreateTextBlock(string name, string text, Brush foregrou

public static TouchScreenTextBox CreateTextBox(string name, string text, Brush foregroundBrush, double fontSize, ContextMenu contextMenu, VerticalAlignment verticalAlignment, Thickness margin)
{
return new TouchScreenTextBox()
return new TouchScreenTextBox
{
Name = name,
Text = text,
Expand Down

0 comments on commit 9849cbb

Please sign in to comment.