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


C# ByteString.StartsWith方法代码示例

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


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

示例1: 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

示例2: ParseBody

        private static MimeMessage ParseBody(LineOrientedStream stream, MimeHeaderCollection headers)
        {
            var message = new MimeMessage(headers);

              ParseContentType(message);
              ParseContentTransferEncoding(message);
              ParseContentDisposition(message);

              // read and parse content
              MemoryStream contentStream;

              if (message.MimeType == null || !message.MimeType.TypeEquals("multipart")) {
            contentStream = new MemoryStream(1024);

            stream.CopyTo(contentStream, MimeFormat.Standard.Folding);

            message.Content = contentStream;

            return message;
              }

              // multipart/*
              var parts = new List<MimeMessage>();
              var delimiter = new ByteString("--" + message.Boundary);
              var closeDelimiter = new ByteString("--" + message.Boundary + "--");
              MemoryStream body = null;
              ByteString line = null;
              ByteString lastLine = null;

              contentStream = new MemoryStream(1024);

              for (;;) {
            if (lastLine != null)
              contentStream.Write(lastLine.ByteArray, 0, lastLine.Length);

            var l = stream.ReadLine();

            if (l == null)
              break;

            lastLine = line;
            line = new ByteString(l);

            if (line.StartsWith(delimiter)) {
              if (lastLine != null) {
            if (lastLine.EndsWith(Octets.CRLF))
              // CRLF "--" boundary
              contentStream.Write(lastLine.ByteArray, 0, lastLine.Length - 2);
            else
              // LF "--" boundary or CR "--" boundary
              contentStream.Write(lastLine.ByteArray, 0, lastLine.Length - 1);
              }

              contentStream.Position = 0;

              if (body == null)
            body = contentStream;
              else
            parts.Add(Parse(contentStream));

              if (line.StartsWith(closeDelimiter))
            break;
              else
            contentStream = new MemoryStream(1024);

              lastLine = null;
            }
              }

              message.Content = body;
              message.SubParts.AddRange(parts);

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

示例3: TestStartsWithString

        public void TestStartsWithString()
        {
            var str = new ByteString("abcde");

              Assert.IsTrue(str.StartsWith("abc"));
              Assert.IsTrue(str.StartsWith("abcde"));
              Assert.IsFalse(str.StartsWith("abd"));
              Assert.IsFalse(str.StartsWith("abcdef"));
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:9,代码来源:ByteString.cs


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