1234567891011121314151617181920212223242526272829303132333435363738 |
- namespace BeatLyrics.Tool.Models
- {
- public class TextTuple
- {
- public string Text { get; set; }
- public string Ruby { get; set; }
- public override string ToString()
- {
- var left = 0;
- var regexKata = new System.Text.RegularExpressions.Regex("^[\\p{IsKatakana}]+$");
- if (regexKata.IsMatch(Text)) return Text;
- if (Ruby == Text) return Text;
- if (false == string.IsNullOrWhiteSpace(Ruby))
- {
- for (int i = 0; i < Ruby.Length; i++)
- {
- if (Text[Text.Length - 1 - i] == Ruby[Ruby.Length - 1 - i]) continue;
- left = i;
- break;
- }
- var textLeft = Text.Substring(0, Text.Length - left);
- var textRight = Text.Substring(Text.Length - left);
- var midRuby = Ruby.Substring(0, Ruby.Length - left);
- return $"{textLeft}({midRuby}){textRight}";
- }
- return Text + (Text == Ruby || string.IsNullOrWhiteSpace(Ruby) ? "" : $"({Ruby})");
- }
- }
- }
|