System.Net.Cache.Rfc2616.Common.GetBytesRange C# (CSharp) Method

GetBytesRange() public static method

public static GetBytesRange ( string ranges, long &start, long &end, long &total, bool isRequest ) : bool
ranges string
start long
end long
total long
isRequest bool
return bool
            public static bool GetBytesRange(string ranges, ref long start, ref long end, ref long total, bool isRequest) {

                ranges = ranges.ToLower(CultureInfo.InvariantCulture);

                int idx = 0;
                while (idx < ranges.Length && ranges[idx] == ' ') {
                    ++idx;
                }

                idx+=5;
                // The "ranges" string is already in lowercase
                if( idx >= ranges.Length || ranges[idx-5] != 'b' || ranges[idx-4] != 'y' || ranges[idx-3] != 't' || ranges[idx-2] != 'e' || ranges[idx-1] != 's')
                {
                    if(Logging.On)Logging.PrintError(Logging.RequestCache, SR.GetString(SR.net_log_cache_only_byte_range_implemented));
                    return false;
                }

                if (isRequest) {
                    while (idx < ranges.Length && ranges[idx] == ' ') {
                        ++idx;
                    }
                    if (ranges[idx] != '=') {
                        return false;
                    }
                }
                else {
                    if (ranges[idx] != ' ') {
                        return false;
                    }
                }

                char ch = (char)0;
                while (++idx < ranges.Length && (ch=ranges[idx]) == ' ') {
                    ;
                }

                start = -1;
                if (ch != '-') {
                    // parsing start
                    if (idx < ranges.Length && ch >= '0' && ch <= '9') {
                        start = ch-'0';
                        while(++idx < ranges.Length && (ch = ranges[idx]) >= '0' && ch <= '9') {
                            start = start*10 + (ch-'0');
                        }
                    }

                    while (idx < ranges.Length && ch == ' ') {ch = ranges[++idx];}
                    if (ch != '-') {return false;}
                }

                // parsing end
                while (idx < ranges.Length && (ch = ranges[++idx]) == ' ') {
                    ;
                }

                end = -1;
                if (idx < ranges.Length && ch >= '0' && ch <= '9') {
                    end = ch-'0';
                    while(++idx < ranges.Length && (ch = ranges[idx]) >= '0' && ch <= '9') {
                        end = end*10 + (ch-'0');
                    }
                }
                if (isRequest) {
                    while (idx < ranges.Length) {
                        if (ranges[idx++] != ' ') {
                            if(Logging.On)Logging.PrintError(Logging.RequestCache, SR.GetString(SR.net_log_cache_multiple_complex_range_not_implemented));
                            return false;
                        }
                    }
                }
                else {
                    // parsing total
                    while (idx < ranges.Length && (ch = ranges[idx]) == ' ') {
                        ++idx;
                    }

                    if (ch != '/') {
                        return false;
                    }
                    while (++idx < ranges.Length && (ch=ranges[idx]) == ' ') {
                        ;
                    }

                    total = -1;
                    if (ch != '*') {
                        if (idx < ranges.Length && ch >= '0' && ch <= '9') {
                            total = ch-'0';
                            while (++idx < ranges.Length && (ch = ranges[idx]) >= '0' && ch <= '9') {
                                total = total*10 + (ch-'0');
                            }
                        }
                    }
                }

                if (!isRequest && (start == -1 || end == -1)) {
                    return false;
                }
                return true;
            }
        }