tests/NuGetGallery.Facts/Services/PackageMetadataValidationServiceFacts.cs
/// <summary>
/// A (quite ineffective) method to search for a sequence in an array
/// </summary>
/// <param name="searchItem">byte sequence to search for.</param>
/// <param name="whereToSearch">the array to search in.</param>
/// <param name="startIndex">Index in the <paramref name="whereToSearch"/> to start searching from.</param>
/// <returns>Index of the first byte of the sequence. -1 if not found.</returns>
A (quite ineffective) method to search for a sequence in an array
A ( quite ineffective ) method to search for a sequence in an array
private static int FindSequenceIndex(byte[] searchItem, byte[] whereToSearch, int startIndex = 0)
            {
                Assert.True(whereToSearch.Length - startIndex >= searchItem.Length);
                for (int start = startIndex; start < whereToSearch.Length - searchItem.Length; ++start)
                {
                    int searchIndex = 0;
                    while (searchIndex < searchItem.Length && searchItem[searchIndex] == whereToSearch[start + searchIndex])
                    {
                        ++searchIndex;
                    }
                    if (searchIndex == searchItem.Length)
                    {
                        return start;
                    }
                }
                return -1;
            }
private static int FindSequenceIndex ( byte [ ] searchItem , byte [ ] whereToSearch , int startIndex = 0 ) { Assert . True ( whereToSearch . Length - startIndex >= searchItem . Length ) ; for ( int start = startIndex ; start < whereToSearch . Length - searchItem . Length ; ++ start ) { int searchIndex = 0 ; while ( searchIndex < searchItem . Length && searchItem [ searchIndex ] == whereToSearch [ start + searchIndex ] ) { ++ searchIndex ; } if ( searchIndex == searchItem . Length ) { return start ; } } return - 1 ; }
A (quite ineffective) method to search for a sequence in an array
A ( quite ineffective ) method to search for a sequence in an array
Index of the first byte of the sequence. -1 if not found.
Index of the first byte of the sequence . - 1 if not found .
searchItem
byte[]
byte sequence to search for.
byte sequence to search for .
whereToSearch
byte[]
the array to search in.
the array to search in .
startIndex
int
Index in the  to start searching from.
Index in the to start searching from .