src/Foundation/Media/Gimela.Media.Video/MJpegVideoSource.cs
/// <summary>
/// Find subarray in the source array.
/// </summary>
/// <param name="array">Source array to search for needle.</param>
/// <param name="needle">Needle we are searching for.</param>
/// <param name="startIndex">Start index in source array.</param>
/// <param name="sourceLength">Number of bytes in source array, where the needle is searched for.</param>
/// <returns>Returns starting position of the needle if it was found or <b>-1</b> otherwise.</returns>
Find subarray in the source array.
Find subarray in the source array .
private static int Find(byte[] array, byte[] needle, int startIndex, int sourceLength)
    {
      int needleLen = needle.Length;
      int index;
      while (sourceLength >= needleLen)
      {
        index = Array.IndexOf(array, needle[0], startIndex, sourceLength - needleLen + 1);
        if (index == -1)
          return -1;
        int i, p;
        for (i = 0, p = index; i < needleLen; i++, p++)
        {
          if (array[p] != needle[i])
          {
            break;
          }
        }
        if (i == needleLen)
        {
          return index;
        }
        sourceLength -= (index - startIndex + 1);
        startIndex = index + 1;
      }
      return -1;
    }
private static int Find ( byte [ ] array , byte [ ] needle , int startIndex , int sourceLength ) { int needleLen = needle . Length ; int index ; while ( sourceLength >= needleLen ) { index = Array . IndexOf ( array , needle [ 0 ] , startIndex , sourceLength - needleLen + 1 ) ; if ( index == - 1 ) return - 1 ; int i , p ; for ( i = 0 , p = index ; i < needleLen ; i ++ , p ++ ) { if ( array [ p ] != needle [ i ] ) { break ; } } if ( i == needleLen ) { return index ; } sourceLength -= ( index - startIndex + 1 ) ; startIndex = index + 1 ; } return - 1 ; }
Find subarray in the source array.
Find subarray in the source array .
// find needle's starting element // if we did not find even the first element of the needls, then the search is failed // check for needle // needle was found // continue to search for needle
Returns starting position of the needle if it was found or -1
Returns starting position of the needle if it was found or - 1
array
byte[]
Source array to search for needle.
Source array to search for needle .
needle
byte[]
Needle we are searching for.
Needle we are searching for .
startIndex
int
Start index in source array.
Start index in source array .
sourceLength
int
Number of bytes in source array, where the needle is searched for.
Number of bytes in source array where the needle is searched for .