|
@@ -19,6 +19,9 @@ namespace BeatLyrics.Tool.Utils
|
|
|
|
|
|
private static readonly Regex RegexSplitPattern1 = new Regex(@"^(\p{IsCJKUnifiedIdeographs}+)(\p{IsHiragana}+)(\p{IsCJKUnifiedIdeographs}+)$", RegexOptions.Compiled);
|
|
private static readonly Regex RegexSplitPattern1 = new Regex(@"^(\p{IsCJKUnifiedIdeographs}+)(\p{IsHiragana}+)(\p{IsCJKUnifiedIdeographs}+)$", RegexOptions.Compiled);
|
|
private static readonly Regex RegexSplitPattern2 = new Regex(@"^(\p{IsHiragana}+)(\p{IsCJKUnifiedIdeographs}+)$", RegexOptions.Compiled);
|
|
private static readonly Regex RegexSplitPattern2 = new Regex(@"^(\p{IsHiragana}+)(\p{IsCJKUnifiedIdeographs}+)$", RegexOptions.Compiled);
|
|
|
|
+ private static readonly Regex RegexSplitPattern3 = new Regex(@"^(\p{IsCJKUnifiedIdeographs}+)(\p{IsHiragana}+)$", RegexOptions.Compiled);
|
|
|
|
+ private static readonly Regex RegexSplitPattern4 = new Regex(@"^(\p{IsHiragana}+)(\p{IsCJKUnifiedIdeographs}+)(\p{IsHiragana}+)$", RegexOptions.Compiled);
|
|
|
|
+ private static readonly Regex RegexSplitPattern5 = new Regex(@"^(\p{IsCJKUnifiedIdeographs}+)(\p{IsHiragana}+)(\p{IsCJKUnifiedIdeographs}+)(\p{IsHiragana}+)$", RegexOptions.Compiled);
|
|
|
|
|
|
static JapanesePhonetic()
|
|
static JapanesePhonetic()
|
|
{
|
|
{
|
|
@@ -44,6 +47,12 @@ namespace BeatLyrics.Tool.Utils
|
|
foreach (var item in ret)
|
|
foreach (var item in ret)
|
|
{
|
|
{
|
|
var displayText = GetDisplayText(item);
|
|
var displayText = GetDisplayText(item);
|
|
|
|
+ if (displayText == " ")
|
|
|
|
+ {
|
|
|
|
+ lst.Add(new TextTuple { Text = " ", Ruby = " " });
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
var yomiText = GetYomiText(item);
|
|
var yomiText = GetYomiText(item);
|
|
|
|
|
|
{
|
|
{
|
|
@@ -91,6 +100,55 @@ namespace BeatLyrics.Tool.Utils
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ {
|
|
|
|
+ var match = RegexSplitPattern3.Match(displayText);
|
|
|
|
+ if (match.Success)
|
|
|
|
+ {
|
|
|
|
+ var hira = match.Groups[2].Value;
|
|
|
|
+ var split = yomiText.Split(new[] { hira }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
+
|
|
|
|
+ lst.Add(new TextTuple { Text = match.Groups[1].Value, Ruby = split[0] });
|
|
|
|
+ lst.Add(new TextTuple { Text = hira, Ruby = hira });
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ var match = RegexSplitPattern4.Match(displayText);
|
|
|
|
+ if (match.Success)
|
|
|
|
+ {
|
|
|
|
+ var leadingHira = match.Groups[1].Value;
|
|
|
|
+ var suffixHira = match.Groups[3].Value;
|
|
|
|
+
|
|
|
|
+ var split = yomiText.Substring(leadingHira.Length);
|
|
|
|
+ split = split.Substring(0, split.Length - suffixHira.Length);
|
|
|
|
+
|
|
|
|
+ lst.Add(new TextTuple { Text = leadingHira, Ruby = leadingHira });
|
|
|
|
+ lst.Add(new TextTuple { Text = match.Groups[2].Value, Ruby = split });
|
|
|
|
+ lst.Add(new TextTuple { Text = suffixHira, Ruby = suffixHira });
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ {
|
|
|
|
+ var match = RegexSplitPattern5.Match(displayText);
|
|
|
|
+ if (match.Success)
|
|
|
|
+ {
|
|
|
|
+ var kan1 = match.Groups[1].Value;
|
|
|
|
+ var hira1 = match.Groups[2].Value;
|
|
|
|
+ var kan2 = match.Groups[3].Value;
|
|
|
|
+ var hira2 = match.Groups[4].Value;
|
|
|
|
+
|
|
|
|
+ var split = yomiText.Split(new[] { hira1, hira2 }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
+
|
|
|
|
+ lst.Add(new TextTuple { Text = kan1, Ruby = split[0] });
|
|
|
|
+ lst.Add(new TextTuple { Text = hira1, Ruby = hira1 });
|
|
|
|
+ lst.Add(new TextTuple { Text = kan2, Ruby = split[1] });
|
|
|
|
+ lst.Add(new TextTuple { Text = hira2, Ruby = hira2 });
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
lst.Add(new TextTuple { Text = displayText, Ruby = yomiText });
|
|
lst.Add(new TextTuple { Text = displayText, Ruby = yomiText });
|
|
}
|
|
}
|
|
|
|
|