private int[][] CompileSlotMap(string slotMapString, int srcSlotCount) { var parts = ReadOnlyMemoryUtils.Split(slotMapString.AsMemory(), new[] { ';' }).ToArray(); var slotMap = new int[parts.Length][]; for (int i = 0; i < slotMap.Length; i++) { var slotIndices = ReadOnlyMemoryUtils.Split(parts[i], new[] { ',' }).ToArray(); var slots = new int[slotIndices.Length]; slotMap[i] = slots; for (int j = 0; j < slots.Length; j++) { int index; if (!int.TryParse(slotIndices[j].ToString(), out index) || index < 0 || index >= srcSlotCount) { throw Host.Except("Unexpected slot index '{1}' in group {0}. Expected 0 to {2}", i, slotIndices[j], srcSlotCount - 1); } slots[j] = index; } if (slots.Distinct().Count() < slots.Length) { throw Host.Except("Group '{0}' has duplicate slot indices", parts[i]); } } return(slotMap); }
private void Evaluate(IndentedTextWriter wrt, Delegate del, DataViewType typeRes, DataViewType[] types, string text, int ichMin, int ichLim) { Contracts.AssertValue(del); Contracts.AssertNonEmpty(types); var args = new object[types.Length]; var getters = new Func <ReadOnlyMemory <char>, bool> [types.Length]; for (int i = 0; i < getters.Length; i++) { getters[i] = GetGetter(i, types[i], args); } StringBuilder sb = new StringBuilder(); Action <object> printer = GetPrinter(typeRes, sb); ReadOnlyMemory <char> chars = text.AsMemory().Slice(ichMin, ichLim - ichMin); for (bool more = true; more;) { ReadOnlyMemory <char> line; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { more = ReadOnlyMemoryUtils.SplitOne(chars, '\x0D', out line, out chars); } else { more = ReadOnlyMemoryUtils.SplitOne(chars, '\x0A', out line, out chars); } line = ReadOnlyMemoryUtils.TrimWhiteSpace(line); if (line.IsEmpty) { continue; } // Note this "hack" to map _ to empty. It's easier than fully handling quoting and is sufficient // for these tests. var vals = ReadOnlyMemoryUtils.Split(line, new char[] { ',' }) .Select(x => ReadOnlyMemoryUtils.TrimWhiteSpace(x)) .Select(x => ReadOnlyMemoryUtils.EqualsStr("_", x) ? ReadOnlyMemory <char> .Empty : x) .ToArray(); Contracts.Assert(vals.Length == getters.Length); for (int i = 0; i < getters.Length; i++) { if (!getters[i](vals[i])) { wrt.Write("*** Parsing {0} Failed *** ", vals[i]); } } var res = del.DynamicInvoke(args); printer(res); wrt.WriteLine(sb); } }