コード例 #1
0
ファイル: HttpUtil.cs プロジェクト: yyjdelete/SpanNetty
        public static ICharSequence GetCharsetAsSequence(ICharSequence contentTypeValue)
        {
            if (contentTypeValue is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.contentTypeValue);
            }
            int indexOfCharset = AsciiString.IndexOfIgnoreCaseAscii(contentTypeValue, CharsetEquals, 0);

            if ((uint)indexOfCharset >= NIndexNotFound)
            {
                return(null);
            }
            int indexOfEncoding = indexOfCharset + CharsetEquals.Count;

            if (indexOfEncoding < contentTypeValue.Count)
            {
                var charsetCandidate = contentTypeValue.SubSequence(indexOfEncoding, contentTypeValue.Count);
                int indexOfSemicolon = AsciiString.IndexOfIgnoreCaseAscii(charsetCandidate, Semicolon, 0);
                if ((uint)indexOfSemicolon >= NIndexNotFound)
                {
                    return(charsetCandidate);
                }

                return(charsetCandidate.SubSequence(0, indexOfSemicolon));
            }
            return(null);
        }
コード例 #2
0
 public void IndexOfIgnoreCaseAscii()
 {
     Assert.Equal(-1, AsciiString.IndexOfIgnoreCaseAscii(null, (AsciiString)"abc", 1));
     Assert.Equal(-1, AsciiString.IndexOfIgnoreCaseAscii((AsciiString)"abc", null, 1));
     Assert.Equal(0, AsciiString.IndexOfIgnoreCaseAscii((AsciiString)"", (StringCharSequence)"", 0));
     Assert.Equal(0, AsciiString.IndexOfIgnoreCaseAscii((StringCharSequence)"aabaabaa", (AsciiString)"A", 0));
     Assert.Equal(2, AsciiString.IndexOfIgnoreCaseAscii((AsciiString)"aabaabaa", (StringCharSequence)"B", 0));
     Assert.Equal(1, AsciiString.IndexOfIgnoreCaseAscii((StringCharSequence)"aabaabaa", (StringCharSequence)"AB", 0));
     Assert.Equal(5, AsciiString.IndexOfIgnoreCaseAscii((StringCharSequence)"aabaabaa", (AsciiString)"B", 3));
     Assert.Equal(-1, AsciiString.IndexOfIgnoreCaseAscii((AsciiString)"aabaabaa", (StringCharSequence)"B", 9));
     Assert.Equal(2, AsciiString.IndexOfIgnoreCaseAscii((AsciiString)"aabaabaa", new AsciiString("B"), -1));
     Assert.Equal(2, AsciiString.IndexOfIgnoreCaseAscii((StringCharSequence)"aabaabaa", (AsciiString)"", 2));
     Assert.Equal(-1, AsciiString.IndexOfIgnoreCaseAscii((AsciiString)"abc", (StringCharSequence)"", 9));
 }
コード例 #3
0
ファイル: HttpUtil.cs プロジェクト: yyjdelete/SpanNetty
        public static ICharSequence GetMimeType(ICharSequence contentTypeValue)
        {
            if (contentTypeValue is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.contentTypeValue);
            }
            int indexOfSemicolon = AsciiString.IndexOfIgnoreCaseAscii(contentTypeValue, Semicolon, 0);

            if ((uint)indexOfSemicolon < NIndexNotFound)
            {
                return(contentTypeValue.SubSequence(0, indexOfSemicolon));
            }

            return((uint)contentTypeValue.Count > 0u ? contentTypeValue : null);
        }
コード例 #4
0
        public static ICharSequence GetMimeType(ICharSequence contentTypeValue)
        {
            if (contentTypeValue == null)
            {
                throw new ArgumentException(nameof(contentTypeValue));
            }
            int indexOfSemicolon = AsciiString.IndexOfIgnoreCaseAscii(contentTypeValue, Semicolon, 0);

            if (indexOfSemicolon != AsciiString.IndexNotFound)
            {
                return(contentTypeValue.SubSequence(0, indexOfSemicolon));
            }

            return(contentTypeValue.Count > 0 ? contentTypeValue : null);
        }
コード例 #5
0
        public static ICharSequence GetCharsetAsSequence(ICharSequence contentTypeValue)
        {
            if (contentTypeValue == null)
            {
                throw new ArgumentException(nameof(contentTypeValue));
            }
            int indexOfCharset = AsciiString.IndexOfIgnoreCaseAscii(contentTypeValue, CharsetEquals, 0);

            if (indexOfCharset != AsciiString.IndexNotFound)
            {
                int indexOfEncoding = indexOfCharset + CharsetEquals.Count;
                if (indexOfEncoding < contentTypeValue.Count)
                {
                    return(contentTypeValue.SubSequence(indexOfEncoding, contentTypeValue.Count));
                }
            }
            return(null);
        }