当前位置: 首页>>代码示例>>C#>>正文


C# ByteString.IndexOf方法代码示例

本文整理汇总了C#中ByteString.IndexOf方法的典型用法代码示例。如果您正苦于以下问题:C# ByteString.IndexOf方法的具体用法?C# ByteString.IndexOf怎么用?C# ByteString.IndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ByteString的用法示例。


在下文中一共展示了ByteString.IndexOf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FromUri

        private static ImapSearchCriteria FromUri(Uri uri,
                                              bool convertLiteral,
                                              bool synchronizedLiteral,
                                              bool splitCharset,
                                              out bool containsLiteral,
                                              out string charset)
        {
            if (uri == null)
            throw new ArgumentNullException("uri");

              containsLiteral = false;
              charset = null;

              var q = uri.Query;

              if (q.Length == 0)
            return null;
              else if (q.Length == 1) // '?'
            return new ImapSearchCriteria(string.Empty);

              /*
               * http://tools.ietf.org/html/rfc5092
               * RFC 5092 - IMAP URL Scheme
               *
               *    Note that quoted strings and non-synchronizing literals [LITERAL+]
               *    are allowed in the <enc-search> content; however, synchronizing
               *    literals are not allowed, as their presence would effectively mean
               *    that the agent interpreting IMAP URLs needs to parse an <enc-search>
               *    content, find all synchronizing literals, and perform proper command
               *    continuation request handling (see Sections 4.3 and 7 of [IMAP4]).
               */
              var query = PercentEncoding.Decode(q.Substring(1), false);
              var len = query.Length;
              var convertedQuery = new ByteStringBuilder(len);

              if (splitCharset) {
            var queryString = new ByteString(query);

            if (queryString.StartsWithIgnoreCase(charsetSpecification)) {
              // CHARSET<SP>astring<SP>
              var posEndOfCharset = queryString.IndexOf(Octets.SP, charsetSpecification.Length);

              if (posEndOfCharset < 0) {
            throw new ArgumentException("search criteria contains invalid charset specification", "uri");
              }
              else {
            charset = queryString.Substring(charsetSpecification.Length,
                                            posEndOfCharset - charsetSpecification.Length).ToString();

            query = queryString.Substring(posEndOfCharset + 1).ByteArray;
            len = query.Length;
              }
            }
              }

              for (var i = 0; i < len;) {
            if (query[i] == ImapOctets.DQuote) {
              /*
               * quoted
               */
              var start = i;

              for (;;) {
            if (++i == len)
              throw new ArgumentException("search criteria contains unclosed quoted string", "uri");

            if (query[i] == ImapOctets.DQuote) {
              break;
            }
            else if (query[i] == ImapOctets.BackSlash) {
              if (++i == len || !(query[i] == ImapOctets.DQuote || query[i] == ImapOctets.BackSlash))
                throw new ArgumentException("search criteria contains invalid quoted string", "uri");
            }
              }

              i++;

              convertedQuery.Append(query, start, i - start);
            }
            else if (query[i] == ImapOctets.OpenBrace) {
              /*
               * literal
               */
              var start = i;
              var isLiteralSynchronizing = false;
              var literalLength = 0;

              for (;;) {
            if (++i == len)
              throw new ArgumentException("search criteria contains incomplete literal", "uri");

            if (Octets.IsDecimalNumber(query[i])) {
              literalLength = literalLength * 10 + (query[i] - 0x30 /* '0' */);
              // TODO: check length
            }
            else if (query[i] == ImapOctets.CloseBrace) {
              // {xxx}
              isLiteralSynchronizing = true;
              break;
            }
//.........这里部分代码省略.........
开发者ID:pengyancai,项目名称:cs-util,代码行数:101,代码来源:ImapSearchCriteria.cs

示例2: ParseText

        private PopResponseText ParseText(byte[] line, int posStatusEnd)
        {
            /*
               * http://tools.ietf.org/html/rfc2449
               * 3. General Command and Response Grammar
               *       single-line  =  status [SP text] CRLF       ;512 octets maximum
               *       status       =  "+OK" / "-ERR"
               *       text         =  *schar / resp-code *CHAR
               *       resp-code    =  "[" resp-level *("/" resp-level) "]"
               *       resp-level   =  1*rchar
               *       schar        =  %x21-5A / %x5C-7F
               *                           ;printable ASCII, excluding "["
               *       rchar        =  %x21-2E / %x30-5C / %x5E-7F
               *                           ;printable ASCII, excluding "/" and "]"
               */
              if (line.Length - 2 == posStatusEnd)
            return new PopResponseText();

              posStatusEnd++; // SP

              var text = new ByteString(line, posStatusEnd, line.Length - (posStatusEnd + 2/*CRLF*/));

              if (text[0] != PopOctets.OpenBracket)
            return new PopResponseText(null, text);

              var respCodeEnd = text.IndexOf(PopOctets.CloseBracket);

              if (respCodeEnd < 0)
            return new PopResponseText(null, text);
              else
            return new PopResponseText(PopResponseCode.GetKnownOrCreate(text.Substring(1/*'['*/, respCodeEnd - 1).ToString()),
                                   text.Substring(respCodeEnd + 1).TrimStart());
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:33,代码来源:PopResponseReciever.cs

示例3: ParseHeader

        private static MimeHeaderCollection ParseHeader(LineOrientedStream stream)
        {
            var headers = new MimeHeaderCollection();
              MimeHeader current = null;

              for (;;) {
            var lineBytes = stream.ReadLine(false);

            if (lineBytes == null)
              break; // unexpected end of stream

            var line = new ByteString(lineBytes);

            if (line.IsEmpty)
              break; // end of headers

            if (line[0] == Octets.HT || line[0] == Octets.SP) { // LWSP-char
              // folding
              if (current == null)
            // ignore incorrect formed header
            continue;

              current.Value += Chars.SP;
              current.Value += line.TrimStart().ToString();
            }
            else {
              // field       =  field-name ":" [ field-body ] CRLF
              // field-name  =  1*<any CHAR, excluding CTLs, SPACE, and ":">
              var delim = line.IndexOf(MimeHeader.NameBodyDelimiter); // ':'

              if (delim < 0) {
            // ignore incorrect formed header
            current = null;
            continue;
              }

              var header = new MimeHeader(line.Substring(0, delim).TrimEnd().ToString(),
                                      line.Substring(delim + 1).TrimStart().ToString());

              headers.Add(header);

              current = header;
            }
              }

              return headers;
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:47,代码来源:Parser.cs

示例4: ParseRespText

        private ImapResponseText ParseRespText(ByteString respText)
        {
            // resp-text       = ["[" resp-text-code "]" SP] text
              if (respText[0] != ImapOctets.OpenBracket)
            // no resp-text-code
            return new ImapResponseText(DecodeRespTextString(respText.Substring(0, respText.Length - 2))); // remove trailing CRLF

              // exists resp-text-code
              var respTextCodeEnd = respText.IndexOf(ImapOctets.CloseBracket);
              var respTextCode    = respText.Substring(1, respTextCodeEnd - 1);
              var codeSep         = respTextCode.IndexOf(Octets.SP);

              ByteString text;

              if (respTextCodeEnd < respText.Length) {
            text = respText.Substring(respTextCodeEnd + 1);
            text = text.Trim(); // remove SP, CRLF
              }
              else {
            text = ByteString.CreateEmpty();
              }

              if (codeSep == -1)
            // no arguments; "READ-ONLY" / "READ-WRITE" / etc...
            return new ImapResponseText(ImapResponseCode.GetKnownOrCreate(respTextCode.ToString()),
                                    new ImapData[] {},
                                    DecodeRespTextString(text));

              // exist arguments; "UIDNEXT" SP nz-number / "UIDVALIDITY" SP nz-number / etc...
              var codeString = respTextCode.Substring(0, codeSep);
              var arguments = ParseDataNonTerminatedText(respTextCode, codeSep + 1);

              if (arguments == null)
            throw new ImapMalformedResponseException("malformed resp-text-code", respTextCode.ToString(codeSep + 1));

              return new ImapResponseText(ImapResponseCode.GetKnownOrCreate(codeString.ToString(), arguments[0]),
                                  arguments,
                                  DecodeRespTextString(text));
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:39,代码来源:ImapResponseReceiver.cs

示例5: ParseResponce

        private ImapResponse ParseResponce(ByteString line, ref IParsingContext parsingContext)
        {
            // response        = *(continue-req / response-data) response-done

              // continue-req    = "+" SP (resp-text / base64) CRLF
              if (line.StartsWith(continueReqMark))
            return new ImapCommandContinuationRequest(line.ToString(2, line.Length - 4)); // remove leading "+" SP and trailing CRLF

              // greeting        = "*" SP (resp-cond-auth / resp-cond-bye) CRLF
              // response-done   = response-tagged / response-fatal
              // response-data   = "*" SP (resp-cond-state / resp-cond-bye /
              //                   mailbox-data / message-data / capability-data) CRLF
              // response-fatal  = "*" SP resp-cond-bye CRLF
              //                     ; Server closes connection immediately
              // response-tagged = tag SP resp-cond-state CRLF

              // ("*" / tag) SP
              var tagSep = line.IndexOf(Octets.SP);

              if (tagSep == -1)
            // response-done and response-data must contain SP
            throw new ImapMalformedResponseException("malformed response-done/response-data", line.ToString());

              var untagged = (tagSep == 1 && line[0] == ImapOctets.Asterisk);

              // ("OK" / "BAD" / "NO" / "BYE" / "PREAUTH" / text) SP
              var respCondSep = line.IndexOf(Octets.SP, tagSep + 1);
              var cond = ImapResponseCondition.Undefined;

              if (respCondSep == -1) {
            if (!untagged)
              throw new ImapMalformedResponseException("malformed response-data", line.ToString());
            //else
              // '* SEARCH\r\n' (mailbox-data which contains no SP)
              }
              else {
            cond = ParseCondition(line.Substring(tagSep + 1, respCondSep - tagSep - 1));
              }

              if (cond != ImapResponseCondition.Undefined || line.StartsWith(respCondMark)) {
            // resp-cond-auth / resp-cond-state / resp-cond-bye
            var responseText = ParseRespText((cond == ImapResponseCondition.Undefined)
                                           ? line.Substring(tagSep + 1)
                                           : line.Substring(respCondSep + 1));

            if (untagged)
              return new ImapUntaggedStatusResponse((ImapResponseCondition)cond,
                                            responseText);
            else
              return new ImapTaggedStatusResponse(line.ToString(0, tagSep),
                                          (ImapResponseCondition)cond,
                                          responseText);
              }

              // mailbox-data / message-data / capability-data etc.
              return ParseDataResponse(line, ref parsingContext);
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:57,代码来源:ImapResponseReceiver.cs

示例6: ParseDataResponse

        private ImapDataResponse ParseDataResponse(ByteString line, ref IParsingContext parsingContext)
        {
            // mailbox-data / message-data / capability-data etc.

              // ("*" / tag) SP
              var offset = (parsingContext == null) ? line.IndexOf(Octets.SP) + 1 : 0;
              var parsedData = ParseData(line, offset, ref parsingContext);

              if (parsedData == null)
            return null;
              else
            return ImapDataResponse.Create(parsedData);
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:13,代码来源:ImapResponseReceiver.cs

示例7: TestIndexOfString

        public void TestIndexOfString()
        {
            var str = new ByteString("ababdabdbdabcab");

              Assert.AreEqual(10, str.IndexOf("abc"));
              Assert.AreEqual(2, str.IndexOf("abd"));
              Assert.AreEqual(-1, str.IndexOf("abe"));

              Assert.AreEqual(0, str.IndexOf("ab"));
              Assert.AreEqual(0, str.IndexOf("ab", 0));
              Assert.AreEqual(2, str.IndexOf("ab", 1));
              Assert.AreEqual(2, str.IndexOf("ab", 2));
              Assert.AreEqual(5, str.IndexOf("ab", 3));
              Assert.AreEqual(5, str.IndexOf("ab", 4));
              Assert.AreEqual(5, str.IndexOf("ab", 5));
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:16,代码来源:ByteString.cs

示例8: TestIndexOf

        public void TestIndexOf()
        {
            var str = new ByteString("ababdabdbdabcab");

              Assert.AreEqual(10, str.IndexOf(new ByteString("abc")));
              Assert.AreEqual("abc", str.Substring(10, 3).ToString());
              Assert.AreEqual(2, str.IndexOf(new ByteString("abd")));
              Assert.AreEqual("abd", str.Substring(2, 3).ToString());
              Assert.AreEqual(-1, str.IndexOf(new ByteString("abe")));

              var substr = new ByteString("ab");

              Assert.AreEqual(0, str.IndexOf(substr));
              Assert.AreEqual(0, str.IndexOf(substr, 0));
              Assert.AreEqual(2, str.IndexOf(substr, 1));
              Assert.AreEqual(2, str.IndexOf(substr, 2));
              Assert.AreEqual(5, str.IndexOf(substr, 3));
              Assert.AreEqual(5, str.IndexOf(substr, 4));
              Assert.AreEqual(5, str.IndexOf(substr, 5));
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:20,代码来源:ByteString.cs


注:本文中的ByteString.IndexOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。