Advertisement
ivandrofly

WIP: Line Balacing Subtitle Edit

May 2nd, 2024 (edited)
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. NOTE: This is not yet completed (a lot of duplication)
  2.  
  3.         enum BreakType
  4.         {
  5.             None,
  6.             Dialog,
  7.             Command,
  8.             Ending,
  9.         }
  10. public string Split(string input)
  11.         {
  12.             var breakEarlyDialog = true;
  13.            
  14.             var dp = new bool[input.Length];
  15.             var dpBreakTypes = new BreakType[input.Length];
  16.             var hash = new HashSet<char>();
  17.             var comma = new HashSet<char>();
  18.             for (int i = 0; i < input.Length; i++)
  19.             {
  20.                 if (hash.Contains(input[i]))
  21.                 {
  22.                     dp[i] = CanSplit(input, i);
  23.                 }
  24.             }
  25.  
  26.             for (var i = 0; i < dp.Length; i++)
  27.             {
  28.                 if (dpBreakTypes[i] == BreakType.None)
  29.                 {
  30.                     continue;
  31.                 }
  32.                
  33.                 // maybe calculate and get type break type from position
  34.                 // return with break as soon as there is a match
  35.                
  36.                 // note: to get the best from avg move both dir
  37.                 // split from mid and find first BreakType.Dialog and check if it's what we looking for
  38.                 // if true then it will give the best split position
  39.                 // f(x) => breaktype;
  40.                 // f(x+1) => breaktype
  41.                 // f(x-1) => breaktype
  42.  
  43.                 if (dpBreakTypes[i] == BreakType.Dialog && breakEarlyDialog)
  44.                 {
  45.                     return string.Join(Environment.NewLine, input.Substring(0, i), input.Substring(i));
  46.                 }
  47.                 if (dp[i] && breakEarlyDialog && comma.Contains(input[i]))
  48.                 {
  49.                     return string.Join(Environment.NewLine, input.Substring(0, i), input.Substring(i));
  50.                 }
  51.                 if (dp[i] && breakEarlyDialog && comma.Contains(input[i]))
  52.                 {
  53.                     return string.Join(Environment.NewLine, input.Substring(0, i), input.Substring(i));
  54.                 }
  55.                 if (dp[i] && breakEarlyDialog && comma.Contains(input[i]))
  56.                 {
  57.                     return string.Join(Environment.NewLine, input.Substring(0, i), input.Substring(i));
  58.                 }
  59.                 if (dp[i] && breakEarlyDialog && comma.Contains(input[i]))
  60.                 {
  61.                     return string.Join(Environment.NewLine, input.Substring(0, i), input.Substring(i));
  62.                 }
  63.             }
  64.  
  65.             return "";
  66.            
  67.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement