public static TvProgram FromHtml(VirtualString html, DateTime day, TvChannel channel) { TvProgram prog; prog = new TvProgram(html, day); prog.Channel = channel; return(prog); }
public void virtual_string_out_of_range_issue_7() { using (Stream stream = new StupidStream()) { var v = new VirtualString(stream, 0, 256); { // Reproduces: https://github.com/Invenietis/CK-Text/issues/7 v.GetText(6810, 1).Should().Be(StupidStream.CharAt(6810).ToString()); v.Invoking(_ => _.GetText(7042, 24)).Should().NotThrow(); } // Since we are here, a little systematic stress test: for (int start = 0; start < 300; ++start) { for (int width = 2; width < 300; ++width) { v.Invoking(_ => _.GetText(start, width)).Should().NotThrow(); } } } }
public void virtual_string_does_not_support_multibyte_characters() { Assume.That(false, "VirtualString does not support multi-byte characters."); var encoding = new UTF8Encoding(false); // i = 0 to 25: Single-byte // i = 26 and 27: Multi-byte // i = 28 to 53: Single-byte string testStr = @"ABCDEFGHIJKLMNOPQRSTUVWXYZüABCDEFGHIJKLMNOPQRSTUVWXYZ"; byte[] utf8bytes = encoding.GetBytes(testStr); using (MemoryStream ms = new MemoryStream()) { ms.Write(utf8bytes); ms.Position = 0; var v = new VirtualString(ms, 0, 256, encoding); { v.Invoking(_ => _.GetText(0, utf8bytes.Length)).Should().NotThrow(); // ArgumentOutOfRangeException } } }
public void virtual_string_does_not_support_multibyte_characters_at_buffer_edge() { Assume.That(false, "VirtualString does not support multi-byte characters."); var encoding = new UTF8Encoding(false); // i = 0 to 25: Single-byte // i = 26 and 27: Multi-byte // i = 28 to 53: Single-byte string testStr = @"ABCDEFGHIJKLMNOPQRSTUVWXYZüABCDEFGHIJKLMNOPQRSTUVWXYZ"; byte[] utf8bytes = encoding.GetBytes(testStr); using (MemoryStream ms = new MemoryStream()) { ms.Write(utf8bytes); ms.Position = 0; var v = new VirtualString(ms, 0, 27, encoding); { // Bug (?): Reading 57 bytes does not read 57 characters, depending on encoding and content v.GetText(0, 27).Should().Be("ABCDEFGHIJKLMNOPQRSTUVWXYZü"); // But is ABCDEFGHIJKLMNOPQRSTUVWXYZ? } } }
internal TvProgram(VirtualString html, DateTime day) { var textHour = html.BetweenS("<strong>Ore ", "</strong>").Split(','); var hour = new TimeSpan(int.Parse(textHour[0]), int.Parse(textHour[1]), 0); var date = day.Add(hour); var title = Utils.TextFromHtml(html.Between("<h2", "</h2>").After(">").AsString); _grayText = html.Between("<h3", "</h3>").After(">").AsString.Trim().Split('\n').Select(x => x.Trim()).Where(x => !string.IsNullOrEmpty(x)).ToArray(); if (StringUtils.UpperCaseLettersProportion(title) > 0.3) { Title = title.ToTitleCase(); } else { Title = title; } Date = date; if (_grayText.Length > 0) { var progType = _grayText[0]; var idx = progType.IndexOf(" - "); if (idx != -1) { progType = progType.Substring(0, idx); Genre = progType; } Type = GetProgramType(progType); if (_grayText.Length >= 2) { var yearString = _grayText[1].TryCapture(@"\((\d{4})\)"); if (yearString != null) { Year = Convert.ToInt32(yearString); } System.Diagnostics.Debug.WriteLine(_grayText[1]); } } var textID = html.BetweenS("dizionario/", "\"", true); if (textID != null) { _id = textID; this.Url = new Uri("http://www.mymovies.it/dizionario/" + _id); var myMoviesId = textID.TryCapture(@"recensione\.asp\?id=(\d+)"); if (myMoviesId != null && MoviesDatabase != null) { var movie = MoviesDatabase.GetMovieInfo(int.Parse(myMoviesId)); if (movie != null) { Genre = MoviesDatabase._genres[movie.Value.GenreId]; IsItalian = movie.Value.IsItalian; if (this.Type == ProgramType.Unknown) { this.Type = ProgramType.Film; } } } } var ratingText = html.Between("valutazione media tra critica e pubblico: ", " stelle", true); if (ratingText != null) { Rating = Single.Parse(ratingText.AsString.Replace(',', '.'), System.Globalization.NumberFormatInfo.InvariantInfo) / 5; } }