/// <summary> /// Initializes a new instance of the <see cref="ColumnInfo"/> struct. /// </summary> /// <param name="width">The width of the column in (fixed-width) characters.</param> /// <param name="content">The content of this column.</param> /// <param name="alignment">The alignment to use for this column.</param> /// <param name="verticalAlignment">The vertical alignment to use for this column</param> /// <param name="method">The word wrapping method to use for this column</param> public ColumnInfo(int width, string content, Alignment alignment, VerticalAlignment verticalAlignment, WordWrappingMethod method) { m_width = width; m_content = content; m_alignment = alignment; m_verticalAlignment = verticalAlignment; m_workdWrappingMethod = method; }
/// <summary> /// Initializes a new instance of the <see cref="ColumnInfo"/> struct. /// </summary> /// <param name="width">The width of the column in (fixed-width) characters.</param> /// <param name="content">The content of this column.</param> /// <param name="alignment">The alignment to use for this column.</param> /// <param name="verticalAlignment">The vertical alignment to use for this column</param> /// <param name="method">The word wrapping method to use for this column</param> public ColumnInfo(int width, string content, Alignment alignment, VerticalAlignment verticalAlignment, WordWrappingMethod method) { mWidth = width; mContent = content; mAlignment = alignment; mVerticalAlignment = verticalAlignment; mWordWrappingMethod = method; }
/// <summary> /// Performs word wrapping on the specified string, making it fit within the specified width and additionally aligns each line /// according to the <see cref="Alignment"/> specified. /// </summary> /// <param name="str">The string to word wrap and align.</param> /// <param name="width">The width of the field in which to fit the string.</param> /// <param name="method">The method to use for word wrapping.</param> /// <param name="alignment">The alignment to use for each line of the resulting string.</param> /// <param name="padCharacter">The character to use for padding lines that are shorter than the specified width.</param> /// <returns>A word wrapped version of the original string aligned and padded as specified.</returns> /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception> /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception> public static string WordWrap(string str, int width, WordWrappingMethod method, Alignment alignment, char padCharacter) { return StringFormatter.Align(WordWrap(str, width, method), width, alignment, Cropping.Left, "", padCharacter); }
/// <summary> /// Performs word wrapping on the specified string, making it fit within the specified width and additionally aligns each line /// according to the <see cref="Alignment"/> specified. /// </summary> /// <param name="str">The string to word wrap and align.</param> /// <param name="width">The width of the field in which to fit the string.</param> /// <param name="method">The method to use for word wrapping.</param> /// <param name="alignment">The alignment to use for each line of the resulting string.</param> /// <returns>A word wrapped version of the original string aligned and padded as specified.</returns> /// <remarks>If padding is required, the normal simple white space character (' ') will be used.</remarks> /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception> /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception> public static string WordWrap(string str, int width, WordWrappingMethod method, Alignment alignment) { return WordWrap(str, width, method, alignment, ' '); }
/// <summary> /// Performs word wrapping on the specified string, making it fit within the specified width. /// </summary> /// <param name="str">The string to word wrap.</param> /// <param name="width">The width of the field in which to fit the string.</param> /// <param name="method">The method to use for word wrapping.</param> /// <returns>A word wrapped version of the original string aligned and padded as specified.</returns> /// <remarks>No padding will be performed on strings that are shorter than the specified width, and each line will be /// left aligned.</remarks> /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception> /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception> public static string WordWrap(string str, int width, WordWrappingMethod method) { if (str == null) throw new ArgumentNullException("str"); if (width <= 0) throw new ArgumentOutOfRangeException("width"); if (method == WordWrappingMethod.Optimal) return new OptimalWordWrappedString(str, width).ToString(); // Simple word wrapping method that simply fills lines as // much as possible and then breaks. Creates a not so nice // layout. StringBuilder dest = new StringBuilder(str.Length); StringBuilder word = new StringBuilder(); int spaceLeft = width; StringReader reader = new StringReader(str); int ch; do { while ((ch = reader.Read()) != -1 && ch != ' ') { word.Append((char)ch); if (ch == '\n') spaceLeft = width; } if (word.Length > spaceLeft) { while (word.Length > width) { dest.Append('\n'); dest.Append(word.ToString(0, width)); word.Remove(0, width); spaceLeft = width; } dest.Append('\n'); dest.Append(word); spaceLeft = width - word.Length; word.Length = 0; } else { dest.Append(word); spaceLeft -= word.Length; word.Length = 0; } if (ch != -1 && spaceLeft > 0) { dest.Append(' '); spaceLeft--; } } while (ch != -1); reader.Close(); return dest.ToString(); }
/// <summary> /// Performs word wrapping on the specified string, making it fit within the specified width and additionally aligns each line /// according to the <see cref="Alignment"/> specified. /// </summary> /// <param name="str">The string to word wrap and align.</param> /// <param name="width">The width of the field in which to fit the string.</param> /// <param name="method">The method to use for word wrapping.</param> /// <param name="alignment">The alignment to use for each line of the resulting string.</param> /// <param name="padCharacter">The character to use for padding lines that are shorter than the specified width.</param> /// <returns>A word wrapped version of the original string aligned and padded as specified.</returns> /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception> /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception> public static string WordWrap(string str, int width, WordWrappingMethod method, Alignment alignment, char padCharacter) { return(StringFormatter.Align(WordWrap(str, width, method), width, alignment, Cropping.Left, "", padCharacter)); }
/// <summary> /// Performs word wrapping on the specified string, making it fit within the specified width and additionally aligns each line /// according to the <see cref="Alignment"/> specified. /// </summary> /// <param name="str">The string to word wrap and align.</param> /// <param name="width">The width of the field in which to fit the string.</param> /// <param name="method">The method to use for word wrapping.</param> /// <param name="alignment">The alignment to use for each line of the resulting string.</param> /// <returns>A word wrapped version of the original string aligned and padded as specified.</returns> /// <remarks>If padding is required, the normal simple white space character (' ') will be used.</remarks> /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception> /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception> public static string WordWrap(string str, int width, WordWrappingMethod method, Alignment alignment) { return(WordWrap(str, width, method, alignment, ' ')); }
/// <summary> /// Performs word wrapping on the specified string, making it fit within the specified width. /// </summary> /// <param name="str">The string to word wrap.</param> /// <param name="width">The width of the field in which to fit the string.</param> /// <param name="method">The method to use for word wrapping.</param> /// <returns>A word wrapped version of the original string aligned and padded as specified.</returns> /// <remarks>No padding will be performed on strings that are shorter than the specified width, and each line will be /// left aligned.</remarks> /// <exception cref="ArgumentNullException"><paramref name="str"/> was a null reference (<b>Nothing</b> in Visual Basic)</exception> /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="width"/> was less than, or equal to zero.</exception> public static string WordWrap(string str, int width, WordWrappingMethod method) { if (str == null) { return(""); } if (width <= 0) { throw new ArgumentOutOfRangeException("width"); } if (method == WordWrappingMethod.Optimal) { return(new OptimalWordWrappedString(str, width).ToString()); } // Simple word wrapping method that simply fills lines as // much as possible and then breaks. Creates a not so nice // layout. StringBuilder dest = new StringBuilder(str.Length); StringBuilder word = new StringBuilder(); int spaceLeft = width; using (StringReader reader = new StringReader(str)) { int ch; do { while ((ch = reader.Read()) != -1 && ch != ' ') { word.Append((char)ch); if (ch == '\n') { spaceLeft = width; } } if (word.Length > spaceLeft) { while (word.Length > width) { dest.Append('\n'); dest.Append(word.ToString(0, width)); word.Remove(0, width); spaceLeft = width; } dest.Append('\n'); dest.Append(word); spaceLeft = width - word.Length; word.Length = 0; } else { dest.Append(word); spaceLeft -= word.Length; word.Length = 0; } if (ch != -1 && spaceLeft > 0) { dest.Append(' '); spaceLeft--; } }while (ch != -1); } return(dest.ToString()); }
/// <summary> /// Returns the hash code for this instance. /// </summary> /// <returns> /// A 32-bit signed integer that is the hash code for this instance. /// </returns> public override int GetHashCode() { return(Width.GetHashCode() ^ Content.GetHashCode() ^ Alignment.GetHashCode() ^ WordWrappingMethod.GetHashCode()); }
/// <summary> /// Indicates whether this instance and a specified object are equal. /// </summary> /// <param name="obj">Another object to compare to.</param> /// <returns> /// true if obj and this instance are the same type and represent the same value; otherwise, false. /// </returns> public override bool Equals(object obj) { if (!(obj is ColumnInfo)) { return(false); } ColumnInfo ci = (ColumnInfo)obj; return(Width.Equals(ci.Width) && Content.Equals(ci.Content) && Alignment.Equals(ci.Alignment) && WordWrappingMethod.Equals(ci.WordWrappingMethod)); }
public bool Equals(ColumnInfo other) { return(Width.Equals(other.Width) && Content.Equals(other.Content) && Alignment.Equals(other.Alignment) && WordWrappingMethod.Equals(other.WordWrappingMethod)); }