/// <summary> /// IView 表格列 特性 /// </summary> /// <param name="title">标题</param> /// <param name="name">属性名 首字母大写</param> /// <param name="width">宽度 0为平分剩余所有宽度 默认为0</param> /// <param name="align">对齐方式 默认为居中</param> public TableColumnAttribute(string title, string name, int width = 0, TableColumnAlign align = TableColumnAlign.center) { Title = title; NameArray = name.Split(new char[] { '.', ' ' }, StringSplitOptions.RemoveEmptyEntries); CamelList = new(); foreach (string str in NameArray) { CamelList.Add(str.ToCamel()); } Key = string.Join("_", CamelList); Camel = string.Join(".", CamelList); Width = width; Align = align; }
public void AddColumn(int start, int end, TableColumnAlign align) { if (ColumnSlices == null) { ColumnSlices = new List <ColumnSlice>(); } ColumnSlices.Add(new ColumnSlice() { Start = start, End = end, Align = align, }); }
private static bool ParseHeaderString(Inline inline, out TableColumnAlign align) { align = 0; var literal = inline as LiteralInline; if (literal == null) { return(false); } // Work on a copy of the slice var line = literal.Content; if (TableHelper.ParseColumnHeader(ref line, '-', out align)) { if (line.CurrentChar != '\0') { return(false); } return(true); } return(false); }
private List <TableColumnDefinition> FindHeaderRow(List <Inline> delimiters) { bool isValidRow = false; List <TableColumnDefinition> aligns = null; for (int i = 0; i < delimiters.Count; i++) { if (delimiters[i] != null && IsLine(delimiters[i])) { // The last delimiter is always null, for (int j = i + 1; j < delimiters.Count - 1; j++) { var delimiter = delimiters[j]; var nextDelimiter = delimiters[j + 1]; var columnDelimiter = delimiter as PiprTableDelimiterInline; if (j == i + 1 && IsStartOfLineColumnDelimiter(columnDelimiter)) { continue; } // Check the left side of a `|` delimiter TableColumnAlign align = TableColumnAlign.Left; if (delimiter.PreviousSibling != null && !ParseHeaderString(delimiter.PreviousSibling, out align)) { break; } // Create aligns until we may have a header row if (aligns == null) { aligns = new List <TableColumnDefinition>(); } aligns.Add(new TableColumnDefinition() { Alignment = align }); // If this is the last delimiter, we need to check the right side of the `|` delimiter if (nextDelimiter == null) { var nextSibling = columnDelimiter != null ? columnDelimiter.FirstChild : delimiter.NextSibling; if (!ParseHeaderString(nextSibling, out align)) { break; } isValidRow = true; aligns.Add(new TableColumnDefinition() { Alignment = align }); break; } // If we are on a Line delimiter, exit if (IsLine(delimiter)) { isValidRow = true; break; } } break; } } return(isValidRow ? aligns : null); }
public static IElement <TableColumn> Align(this IElement <TableColumn> element, TableColumnAlign align) => element.Attribute("align", align);
/// <summary> /// Parses a column header equivalent to the regexp: <code>\s*:\s*[delimiterChar]+\s*:\s*</code> /// </summary> /// <param name="slice">The text slice.</param> /// <param name="delimiterChar">The delimiter character (either `-` or `=`). If `\0`, it will detect the character (either `-` or `=`)</param> /// <param name="align">The alignment of the column.</param> /// <returns> /// <c>true</c> if parsing was successfull /// </returns> public static bool ParseColumnHeaderDetect(ref StringSlice slice, ref char delimiterChar, out TableColumnAlign align) { align = TableColumnAlign.Left; // Work on a copy of the slice slice.TrimStart(); var c = slice.CurrentChar; bool hasLeft = false; bool hasRight = false; if (c == ':') { hasLeft = true; slice.NextChar(); } slice.TrimStart(); c = slice.CurrentChar; // if we want to automatically detect if (delimiterChar == '\0') { if (c == '=' || c == '-') { delimiterChar = c; } else { return(false); } } int count = 0; while (c == delimiterChar) { c = slice.NextChar(); count++; } if (count == 0) { return(false); } slice.TrimStart(); c = slice.CurrentChar; if (c == ':') { hasRight = true; slice.NextChar(); } slice.TrimStart(); align = hasLeft && hasRight ? TableColumnAlign.Center : hasRight ? TableColumnAlign.Right : TableColumnAlign.Left; return(true); }
/// <summary> /// Parses a column header equivalent to the regexp: <code>\s*:\s*[delimiterChar]+\s*:\s*</code> /// </summary> /// <param name="slice">The text slice.</param> /// <param name="delimiterChar">The delimiter character (either `-` or `=`).</param> /// <param name="align">The alignment of the column.</param> /// <returns> /// <c>true</c> if parsing was successfull /// </returns> public static bool ParseColumnHeaderAuto(ref StringSlice slice, out char delimiterChar, out TableColumnAlign align) { delimiterChar = '\0'; return(ParseColumnHeaderDetect(ref slice, ref delimiterChar, out align)); }