internal static int Find(this IList <byte> /*!*/ bytes, IList <byte> /*!*/ sub, int?start) { if (sub == null) { throw PythonOps.TypeError("expected byte or byte array, got NoneType"); } else if (start > bytes.Count) { return(-1); } int iStart; if (start != null) { iStart = PythonOps.FixSliceIndex(start.Value, bytes.Count); } else { iStart = 0; } return(bytes.IndexOf(sub, iStart)); }
private static int FixEnd(IList <byte> bytes, int?end) { int iEnd; if (end != null) { iEnd = PythonOps.FixSliceIndex(end.Value, bytes.Count); } else { iEnd = bytes.Count; } return(iEnd); }
internal static int IndexOfByte(this IList <byte> bytes, int item, int start, int stop) { start = PythonOps.FixSliceIndex(start, bytes.Count); stop = PythonOps.FixSliceIndex(stop, bytes.Count); for (int i = start; i < Math.Min(stop, bytes.Count); i++) { if (bytes[i] == item) { return(i); } } return(-1); }
internal static int IndexOfByte(this IList <byte> /*!*/ bytes, int item, int start, int stop) { start = PythonOps.FixSliceIndex(start, bytes.Count); stop = PythonOps.FixSliceIndex(stop, bytes.Count); for (int i = start; i < Math.Min(stop, bytes.Count); i++) { if (bytes[i] == item) { return(i); } } throw PythonOps.ValueError("bytearray.index(item): item not in bytearray"); }
internal static int CountOf(this IList <byte> bytes, IList <byte> ssub, int start, int end) { if (ssub == null) { throw PythonOps.TypeError("expected bytes or byte array, got NoneType"); } if (start > bytes.Count) { return(0); } start = PythonOps.FixSliceIndex(start, bytes.Count); end = PythonOps.FixSliceIndex(end, bytes.Count); if (ssub.Count == 0) { return(Math.Max((end - start) + 1, 0)); } int count = 0; while (true) { if (end <= start) { break; } int index = bytes.IndexOf(ssub, start, end - start); if (index == -1) { break; } count++; start = index + ssub.Count; } return(count); }
private static int FixStart(IList <byte> bytes, int?start) { return(start != null?PythonOps.FixSliceIndex(start.Value, bytes.Count) : 0); }