private void button1_Click(object sender, System.EventArgs e) { TextStyle.TextStyleCollection tsc; string input = textBox1.Text; try { input = HTMLParser.QuoteAttributes(ref input); TextStyle sTextStyle = new TextStyle(); tsc = HTMLParser.ParseHTML(ref input, ref sTextStyle); } catch { TextStyle ts = new TextStyle(); tsc = new TextStyle.TextStyleCollection(); ts.Text = HTMLParser.RemoveHTMLTags(input); tsc.Add(ts); } textBox3.Text = ""; foreach(TextStyle ts in tsc) { textBox3.Text += ts.ToString() + "\r\n\r\n"; } }
public TextStyle(TextStyle copy) { ForeColor = copy.ForeColor; Text = copy.Text; bold = copy.bold; italic = copy.italic; underline = copy.underline; superscript = copy.superscript; subscript = copy.subscript; }
public static TextStyle.TextStyleCollection ParseHTML(ref string html, ref TextStyle defaultStyle) { TextStyle.TextStyleCollection tsc = new TextStyle.TextStyleCollection(); string text = "<html>" + html + "</html>"; XmlDocument xdf = new XmlDocument(); xdf.LoadXml(text); foreach(XmlNode node in xdf.ChildNodes[0].ChildNodes) { ParseNode(node, ref defaultStyle, ref tsc); } return tsc; }
private void Grow() { if (NeedsGrowth()) { ++m_version; TextStyle[] temp = new TextStyle[m_count * 2]; Array.Copy(m_array, temp, m_array.Length); m_array = temp; } }
/// <summary> /// Removes the first occurrence of a specific <see cref="TextStyle"/> from the <c>TextStyleCollection</c>. /// </summary> /// <param name="item">The <see cref="TextStyle"/> to remove from the <c>TextStyleCollection</c>.</param> /// <exception cref="ArgumentException"> /// The specified <see cref="TextStyle"/> was not found in the <c>TextStyleCollection</c>. /// </exception> public virtual void Remove(TextStyle item) { int i = IndexOf(item); if (i < 0) throw new System.ArgumentException("Cannot remove the specified item because it was not found in the specified Collection."); ++m_version; RemoveAt(i); }
private void Grow(int newItems) { if (NeedsGrowth(newItems)) { ++m_version; TextStyle[] temp = new TextStyle[m_count + newItems]; Array.Copy(m_array, temp, m_array.Length); m_array = temp; } }
public override void Remove(TextStyle x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
public override int IndexOf(TextStyle x) { lock(this.m_root) return m_collection.IndexOf(x); }
public override bool Contains(TextStyle x) { return m_collection.Contains(x); }
public override void CopyTo(TextStyle[] array, int start) { m_collection.CopyTo(array,start); }
/// <summary> /// Adds the elements of a <see cref="TextStyle"/> array to the current <c>TextStyleCollection</c>. /// </summary> /// <param name="x">The <see cref="TextStyle"/> array whose elements should be added to the end of the <c>TextStyleCollection</c>.</param> /// <returns>The new <see cref="TextStyleCollection.Count"/> of the <c>TextStyleCollection</c>.</returns> public virtual int AddRange(TextStyle[] x) { ++m_version; Grow(x.Length); Array.Copy(x, 0, m_array, m_count, x.Length); m_count += x.Length; return m_count; }
/// <summary> /// Determines whether a given <see cref="TextStyle"/> is in the <c>TextStyleCollection</c>. /// </summary> /// <param name="item">The <see cref="TextStyle"/> to check for.</param> /// <returns><c>true</c> if <paramref name="item"/> is found in the <c>TextStyleCollection</c>; otherwise, <c>false</c>.</returns> public virtual bool Contains(TextStyle item) { for (int i=0; i != m_count; ++i) if (m_array[i].Equals(item)) return true; return false; }
public override bool Contains(TextStyle x) { lock(this.m_root) return m_collection.Contains(x); }
/// <summary> /// Adds a <see cref="TextStyle"/> to the end of the <c>TextStyleCollection</c>. /// </summary> /// <param name="item">The <see cref="TextStyle"/> to be added to the end of the <c>TextStyleCollection</c>.</param> /// <returns>The index at which the value has been added.</returns> public virtual int Add(TextStyle item) { ++m_version; Grow(); m_array[m_count] = item; return m_count++; }
/// <summary> /// Initializes a new instance of the <c>TextStyleCollection</c> class /// that contains elements copied from the specified <see cref="TextStyle"/> array. /// </summary> /// <param name="a">The <see cref="TextStyle"/> array whose elements are copied to the new list.</param> public TextStyleCollection(TextStyle[] a) { m_array = new TextStyle[a.Length]; AddRange(a); }
public override void Remove(TextStyle x) { lock(this.m_root) m_collection.Remove(x); }
public override void Insert(int pos, TextStyle x) { lock(this.m_root) m_collection.Insert(pos,x); }
private void Trim() { if (NeedsTrimming()) { ++m_version; TextStyle[] temp = new TextStyle[m_count]; Array.Copy(m_array, temp, m_array.Length); m_array = temp; } }
/// <summary> /// Copies the entire <c>TextStyleCollection</c> to a one-dimensional /// string array. /// </summary> /// <param name="array">The one-dimensional <see cref="TextStyle"/> array to copy to.</param> public virtual void CopyTo(TextStyle[] array) { this.CopyTo(array, 0); }
public override int AddRange(TextStyle[] x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
private static void ParseNode(XmlNode node, ref TextStyle defaultStyle, ref TextStyle.TextStyleCollection tsc) { TextStyle style = new TextStyle(defaultStyle); System.Diagnostics.Trace.WriteLine(node.Name); System.Diagnostics.Trace.Indent(); switch(node.Name.ToLower()) { case "font": if( node.Attributes != null ) { foreach( XmlAttribute attribute in node.Attributes) { System.Diagnostics.Trace.WriteLine(attribute.Name + "=" + attribute.Value, "Attribute"); switch(attribute.Name.ToLower()) { case "color": try { if( attribute.Value[0] != '#' ) style.ForeColor = Color.FromName(attribute.Value); else style.ForeColor = Color.FromArgb( Int32.Parse(attribute.Value.Substring(1,2), System.Globalization.NumberStyles.HexNumber ), Int32.Parse(attribute.Value.Substring(3,2), System.Globalization.NumberStyles.HexNumber ), Int32.Parse(attribute.Value.Substring(5,2), System.Globalization.NumberStyles.HexNumber ) ); } catch {} break; } } } break; case "b": case "strong": style.Bold = true; break; case "i": case "em": style.Italic = true; break; case "u": style.Underline = true; break; case "sup": style.Superscript = true; break; case "sub": style.Subscript = true; break; } if( node.Name == "#text" ) { TextStyle ts = new TextStyle(style); ts.Text = node.Value; tsc.Add(ts); } if( node.HasChildNodes ) { foreach(XmlNode childNode in node.ChildNodes) { ParseNode(childNode, ref style, ref tsc); } } System.Diagnostics.Trace.Unindent(); System.Diagnostics.Trace.WriteLine("/" + node.Name ); }
public override void CopyTo(TextStyle[] array) { m_collection.CopyTo(array); }
public override int AddRange(TextStyle[] x) { lock(this.m_root) return m_collection.AddRange(x); }
public override int IndexOf(TextStyle x) { return m_collection.IndexOf(x); }
/// <summary> /// Inserts an element into the <c>TextStyleCollection</c> at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param> /// <param name="item">The <see cref="TextStyle"/> to insert.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <para><paramref name="index"/> is less than zero</para> /// <para>-or-</para> /// <para><paramref name="index"/> is equal to or greater than <see cref="TextStyleCollection.Count"/>.</para> /// </exception> public virtual void Insert(int index, TextStyle item) { ValidateIndex(index, true); // throws ++m_version; Grow(); for (int i=m_count; i > index; --i) m_array[i] = m_array[i-1]; m_array[index] = item; m_count++; }
/// <summary> /// Copies the entire <c>TextStyleCollection</c> to a one-dimensional /// <see cref="TextStyle"/> array, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="TextStyle"/> array to copy to.</param> /// <param name="start">The zero-based index in <paramref name="array"/> at which copying begins.</param> public virtual void CopyTo(TextStyle[] array, int start) { if (m_count > array.GetUpperBound(0) + 1 - start) throw new System.ArgumentException("Destination array was not long enough."); Array.Copy(m_array, start, array, 0, m_count); }
public override void CopyTo(TextStyle[] array, int start) { lock(this.m_root) m_collection.CopyTo(array,start); }
public static void MainContents(string[] args) { bool bIsFinished = false; while (!bIsFinished) { string cChoice = ""; DisplayContents (ref cChoice); if (cChoice == "1") { InternetPageReader sInternetPageReader = new CVA.InternetPageReader (); DateTime ss = System.DateTime.Now; FileParser sFileParser = new CVA.FileParser (); for (int i = 1; i <= 2; ++i) { string cWebsite = "http://www.officialworldgolfranking.com/rankings/default.sps?region=world&PageCount=" + i; string cFileName = "/Users/alexhum49/Documents/Workspace/CVA/CVATools/Input/OfficialWorldGolfRankingHomePage" + i + ".htm"; sInternetPageReader.ToTextFile (ref cWebsite, ref cFileName); // Parse file of WorldRanking sFileParser.ParseWorldRanking (ref cFileName); } Console.WriteLine ("Elasped time : " + (System.DateTime.Now - ss)); ss = DateTime.Now; // Do not delete files any more string cDirectoryHTM = "/Users/alexhum49/Documents/Workspace/CVA/CVATools/Input/Golf/PlayersHTM/"; Console.WriteLine ("Do you want to delete existing files ?"); string cDelete = System.Console.ReadLine (); if (cDelete == "Y" || cDelete == "y") { Console.WriteLine ("Deleting already existing files"); FileDeleter sFiles = new FileDeleter (ref cDirectoryHTM); sFiles.Delete (); System.Console.WriteLine ("Deleting done in " + (DateTime.Now - ss)); ss = System.DateTime.Now; } string nameprefix = "name=", rankprefix = "&Rank=", totalpoint = "&TotalPt"; foreach (string c in sFileParser.FutureWebsites) { // Find the player name to have the correct file name before parsing it int iFirstNamePlayer = c.IndexOf (nameprefix) + nameprefix.Length, iRankPlayerFirst = c.IndexOf (rankprefix), iRankPlayerLast = iRankPlayerFirst + rankprefix.Length, iTotalPointFirst = c.IndexOf (totalpoint); string cFutureWebsiteToBeCalled = c; string cFileNamePlayer = c.Substring (iFirstNamePlayer, iRankPlayerFirst - iFirstNamePlayer) + "_" + c.Substring (iRankPlayerLast, iTotalPointFirst - iRankPlayerLast); string cPathToFileNamePlayer = cDirectoryHTM + cFileNamePlayer + ".htm"; sInternetPageReader.ToTextFile (ref cFutureWebsiteToBeCalled, ref cPathToFileNamePlayer); } Console.WriteLine ("Elapsed time to get all files : " + (DateTime.Now - ss)); bIsFinished = IsFinish (); } else if (cChoice == "2") { // do something Console.WriteLine ("Not yet implemented"); bIsFinished = true; } else if (cChoice == "3") { Console.WriteLine ("Test of HTML Parser"); string cLine = "<b><i>blabla</i> <u> blibli </u></b> bloblo"; TextStyle sDefaultStyle = new TextStyle (); TextStyle.TextStyleCollection tsc = HTMLParser.ParseHTML (ref cLine, ref sDefaultStyle); Console.WriteLine (tsc.ToString ()); TextStyle[] sTextStyleArray = new TextStyle[16]; tsc.CopyTo (sTextStyleArray); for (int i = 0; i < sTextStyleArray.Length; i++) { if (sTextStyleArray [i] != null) { Console.WriteLine ("i = " + i + " : "); Console.WriteLine (sTextStyleArray [i].ToString ()); } else { Console.WriteLine ("i = " + i + " : null"); } } bIsFinished = true; } else if (cChoice == "4") { string cFileName = "/Users/alexhum49/Documents/Workspace/CVA/CVATools/Input/Golf/Players/Adam_Scott.csv"; var lines = File.ReadAllLines (cFileName).Select (a => a.Split (';')); var csv = from line in lines select (from piece in line select piece); foreach (var element in csv) { foreach (var element2 in element) { Console.Write (element2 + " ; "); } Console.WriteLine (""); } bIsFinished = true; } else if (cChoice == "5") { List<double> X = new List<double> (), Y = new List<double> (); X.Add (0); X.Add (0); X.Add (1); X.Add (1); Y.Add (0); Y.Add (1); Y.Add (1); Y.Add (0); Interpolator sInterp = new Interpolator (ref X, ref Y); //double x = 1.1; for (double x = -0.1; x < 1.2; x += 0.1) { Console.WriteLine (x + " : " + sInterp.Interp (x)); } bIsFinished = true; } else if (cChoice == "6") { DateTime start = DateTime.Today, end = DateTime.Today.AddYears (3); Coverage sCoverage = new Coverage (); Console.WriteLine ("Start : " + start); Console.WriteLine ("Start Ticks : " + start.Ticks); Console.WriteLine ("End : " + end); Console.WriteLine ("End Ticks : " + end.Ticks); Console.WriteLine ("Coverage (ACT365FIXED) : " + sCoverage.YearFraction (ref start, ref end, EnumBasis.ACT365FIXED)); Console.WriteLine ("Coverage (BONDBASIS EURO) : " + sCoverage.YearFraction (ref start, ref end, EnumBasis.THIRTY360EURO)); Console.WriteLine ("Coverage (ACTACT) : " + sCoverage.YearFraction (ref start, ref end, EnumBasis.ACTACT)); bIsFinished = true; } else if (cChoice == "7") { FileParser sFileParser = new FileParser(); string cFilePath = "/Users/alexhum49/Documents/Workspace/CVA/CVATools/Input/Golf/PlayersHTM/Adam_2.htm"; //sFileParser.ParsePlayerNew (ref cFilePath); sFileParser.ParsePlayerNewNew (ref cFilePath); } else { bIsFinished = true; } } Console.WriteLine ("Good bye !"); }
/// <summary> /// Returns the zero-based index of the first occurrence of a <see cref="TextStyle"/> /// in the <c>TextStyleCollection</c>. /// </summary> /// <param name="item">The <see cref="TextStyle"/> to locate in the <c>TextStyleCollection</c>.</param> /// <returns> /// The zero-based index of the first occurrence of <paramref name="item"/> /// in the entire <c>TextStyleCollection</c>, if found; otherwise, -1. /// </returns> public virtual int IndexOf(TextStyle item) { for (int i=0; i != m_count; ++i) if (m_array[i].Equals(item)) return i; return -1; }