Ejemplo n.º 1
0
        public static int GetSamplingRate(this Span <char> span)
        {
            Span <char> sampleS = new Span <char>();

            for (int i = 1; i < span.Length; i++)
            {
                var l = i;

                for (int j = 0; j < l; j++)
                {
                    sampleS.Fill('1');
                }

                for (int j = 0; j < l; j++)
                {
                    sampleS.Fill('0');
                }

                for (int j = 0; j < l; j++)
                {
                    sampleS.Fill('1');
                }

                if (MemoryExtensions.Contains(span, sampleS, StringComparison.Ordinal))
                {
                    return(i);
                }
            }
            return(0);
        }
Ejemplo n.º 2
0
    private static bool MatchQueryParameter(QueryParameterMatchMode matchMode, string requestQueryParameterValue, string metadataQueryParameterValue, bool isCaseSensitive)
    {
        var comparison = isCaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;

        return(matchMode switch
        {
            QueryParameterMatchMode.Exact => MemoryExtensions.Equals(requestQueryParameterValue, metadataQueryParameterValue, comparison),
            QueryParameterMatchMode.Prefix => requestQueryParameterValue != null && metadataQueryParameterValue != null &&
            MemoryExtensions.StartsWith(requestQueryParameterValue, metadataQueryParameterValue, comparison),
            QueryParameterMatchMode.Contains => requestQueryParameterValue != null && metadataQueryParameterValue != null &&
            MemoryExtensions.Contains(requestQueryParameterValue, metadataQueryParameterValue, comparison),
            QueryParameterMatchMode.NotContains => requestQueryParameterValue != null && metadataQueryParameterValue != null &&
            !MemoryExtensions.Contains(requestQueryParameterValue, metadataQueryParameterValue, comparison),
            _ => throw new NotImplementedException(matchMode.ToString()),
        });