Esempio n. 1
0
        private void AddTerms(ReadOnlyMemory <char> txt, char[] separators, List <ReadOnlyMemory <char> > terms)
        {
            Host.AssertNonEmpty(separators);

            var rest = txt;

            if (separators.Length > 1)
            {
                while (!rest.IsEmpty)
                {
                    ReadOnlyMemory <char> term;
                    ReadOnlyMemoryUtils.SplitOne(rest, separators, out term, out rest);
                    term = ReadOnlyMemoryUtils.TrimSpaces(term);
                    if (!term.IsEmpty)
                    {
                        terms.Add(term);
                    }
                }
            }
            else
            {
                var separator = separators[0];
                while (!rest.IsEmpty)
                {
                    ReadOnlyMemory <char> term;
                    ReadOnlyMemoryUtils.SplitOne(rest, separator, out term, out rest);
                    term = ReadOnlyMemoryUtils.TrimSpaces(term);
                    if (!term.IsEmpty)
                    {
                        terms.Add(term);
                    }
                }
            }
        }
        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);
        }
Esempio n. 3
0
 /// <summary>
 /// Returns the set of column ids which match the value of specified metadata kind.
 /// The metadata type should be of type text.
 /// </summary>
 public static IEnumerable <int> GetColumnSet(this Schema schema, string metadataKind, string value)
 {
     for (int col = 0; col < schema.Count; col++)
     {
         var columnType = schema.GetMetadataTypeOrNull(metadataKind, col);
         if (columnType != null && columnType.IsText)
         {
             ReadOnlyMemory <char> val = default;
             schema.GetMetadata(metadataKind, col, ref val);
             if (ReadOnlyMemoryUtils.EqualsStr(value, val))
             {
                 yield return(col);
             }
         }
     }
 }