예제 #1
0
        public void TestParseLineEvent()
        {
            string          path    = TestDataSample.GetTextPath("utf8.txt");
            ParserContext   context = new ParserContext(path);
            PlainTextParser parser  = (PlainTextParser)ParserFactory.CreateText(context);

            parser.ParseLine += (sender, args) =>
            {
                if (args.LineNumber == 0)
                {
                    Assert.AreEqual("hello world", args.Text);
                }
                else if (args.LineNumber == 1)
                {
                    Assert.AreEqual("a2", args.Text);
                }
                else if (args.LineNumber == 2)
                {
                    Assert.AreEqual("a3", args.Text);
                }
                else if (args.LineNumber == 3)
                {
                    Assert.AreEqual("bbb4", args.Text);
                }
            };
            string text = parser.Parse();

            Assert.IsNotNullOrEmpty(text);
        }
        public void ConUnaUrlNoExcedeLongitud()
        {
            string plainText = "en un lugar de la mancha http://katayunos.com/ del cual blah blah.";
            string expected = "en un lugar de la mancha http://kcy.me/abcde del cual blah blah.";

            string espectedUrl = "http://kcy.me/abcde";
            PlainTextParser parser = new PlainTextParser(urlShortener);

            var result = parser.Parse(plainText, 140);

            Assert.AreEqual(expected, result.Text);
            Assert.AreEqual(espectedUrl, result.MainUrl);
        }
예제 #3
0
        private Subtitles ParsedSubtitlesPlain(string path, Encoding fileEncoding, string text, bool withCharacterNames, TimingMode timingMode, string lineSeparator)
        {
            SubtitleCollection collection        = null;
            PlainTextParser    plainParser       = new PlainTextParser(withCharacterNames, lineSeparator);
            ParsingProperties  parsingProperties = plainParser.Parse(text, timingMode, fileEncoding, out collection);

            SubtitleProperties subtitleProperties = new SubtitleProperties(parsingProperties);

            collection.SetPropertiesForAll(subtitleProperties);

            Subtitles subtitles = new Subtitles(collection, subtitleProperties);

            CompleteTimingsAfterParsing(subtitles, parsingProperties);

            fileProperties = new FileProperties(path, fileEncoding, parsingProperties.TimingMode);

            Logger.Info("[SubtitleFactory] Opened {0} with encoding {1}", path, fileEncoding);
            return(subtitles);
        }