OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / win / C# / Parsing / Subtitle.cs
index 343806a..6d83d26 100644 (file)
@@ -1,13 +1,19 @@
 using System;\r
 using System.Collections.Generic;\r
-using System.Text;\r
 using System.IO;\r
+using System.Text.RegularExpressions;\r
 \r
 namespace Handbrake.Parsing\r
 {\r
+    /// <summary>\r
+    /// An object that represents a subtitle associated with a Title, in a DVD\r
+    /// </summary>\r
     public class Subtitle\r
     {\r
         private int m_trackNumber;\r
+        /// <summary>\r
+        /// The track number of this Subtitle\r
+        /// </summary>\r
         public int TrackNumber\r
         {\r
             get\r
@@ -17,6 +23,9 @@ namespace Handbrake.Parsing
         }\r
 \r
         private string m_language;\r
+        /// <summary>\r
+        /// The language (if detected) of this Subtitle\r
+        /// </summary>\r
         public string Language\r
         {\r
             get\r
@@ -25,20 +34,24 @@ namespace Handbrake.Parsing
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Override of the ToString method to make this object easier to use in the UI\r
+        /// </summary>\r
+        /// <returns>A string formatted as: {track #} {language}</returns>\r
         public override string ToString()\r
         {\r
             return string.Format("{0} {1}", this.m_trackNumber, this.m_language);\r
         }\r
 \r
-        public static Subtitle Parse(StreamReader output)\r
+        public static Subtitle Parse(StringReader output)\r
         {\r
             string curLine = output.ReadLine();\r
-            if (!curLine.Contains("HandBrake has exited."))\r
+            Match m = Regex.Match(curLine, @"^    \+ ([0-9]*), ([A-Za-z]*) \((.*)\)");\r
+            if (m.Success && !curLine.Contains("HandBrake has exited."))\r
             {\r
                 Subtitle thisSubtitle = new Subtitle();\r
-                string[] splitter = curLine.Split(new string[] { "    + ", ", " }, StringSplitOptions.RemoveEmptyEntries);\r
-                thisSubtitle.m_trackNumber = int.Parse(splitter[0]);\r
-                thisSubtitle.m_language = splitter[1];\r
+                thisSubtitle.m_trackNumber = int.Parse(m.Groups[1].Value.Trim().ToString());\r
+                thisSubtitle.m_language = m.Groups[2].Value;\r
                 return thisSubtitle;\r
             }\r
             else\r
@@ -47,12 +60,13 @@ namespace Handbrake.Parsing
             }\r
         }\r
 \r
-        public static Subtitle[] ParseList(StreamReader output)\r
+        public static Subtitle[] ParseList(StringReader output)\r
         {\r
             List<Subtitle> subtitles = new List<Subtitle>();\r
-            while ((char)output.Peek() != '+') // oh glorious hack, serve me well\r
+            while ((char)output.Peek() != '+')\r
             {\r
                 Subtitle thisSubtitle = Subtitle.Parse(output);\r
+\r
                 if (thisSubtitle != null)\r
                 {\r
                     subtitles.Add(thisSubtitle);\r