Fix unicode esc string for new json format - thx Filip :)

This commit is contained in:
niksedk 2021-11-28 20:26:12 +01:00
parent c8cdf62f7a
commit d899af729a
2 changed files with 20 additions and 2 deletions

View File

@ -10,6 +10,7 @@
* Allow add empty waveform for online videos
* Switch positions of textboxes shortcut - thx Leon/darnn
* New subtitle format (json, read only) - thx Dvid
* New subtitle format (json, read only) - thx Filip
* IMPROVED:
* Update Bulgarian translation - thx Калин
* Update Finish translation - thx Teijo

View File

@ -40,18 +40,35 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats
text = text.Replace("\\n", Environment.NewLine);
bool keepNext = false;
var sb = new StringBuilder(text.Length);
foreach (var c in text)
var hexLetters = "01234567890abcdef";
int i = 0;
while (i < text.Length)
{
char c = text[i];
if (c == '\\' && !keepNext)
{
keepNext = true;
if (i + 6 < text.Length && text[i + 1] == 'u' &&
hexLetters.Contains(text[i + 2]) &&
hexLetters.Contains(text[i + 3]) &&
hexLetters.Contains(text[i + 4]) &&
hexLetters.Contains(text[i + 5]))
{
var unicodeString = text.Substring(i, 6);
var unescaped = System.Text.RegularExpressions.Regex.Unescape(unicodeString);
sb.Append(unescaped);
i += 5;
}
}
else
{
sb.Append(c);
keepNext = false;
}
i++;
}
return sb.ToString();
}