Beispiel #1
0
        public void TestIndexOfNot()
        {
            ByteString str;

              str = new ByteString("aaabbb");

              Assert.AreEqual(3, str.IndexOfNot('a'));
              Assert.AreEqual(3, str.IndexOfNot(0x61));
              Assert.AreEqual(3, str.IndexOfNot('a', 3));
              Assert.AreEqual(3, str.IndexOfNot(0x61, 3));
              Assert.AreEqual(5, str.IndexOfNot('a', 5));
              Assert.AreEqual(5, str.IndexOfNot(0x61, 5));
              Assert.AreEqual(0, str.IndexOfNot('b'));
              Assert.AreEqual(0, str.IndexOfNot(0x62));
              Assert.AreEqual(-1, str.IndexOfNot('b', 3));
              Assert.AreEqual(-1, str.IndexOfNot(0x62, 3));
              Assert.AreEqual(-1, str.IndexOfNot('b', 5));
              Assert.AreEqual(-1, str.IndexOfNot(0x62, 5));
        }
Beispiel #2
0
        protected ImapData[] ParseData(ByteString line, int offset, ref IParsingContext context)
        {
            var index = offset;
              var c = context as ParsingContext;

              if (c == null) {
            context = c = new ParsingContext();
              }
              else {
            if (line.Length - index == 2/*CRLF*/) {
              if (c.ParenthesesClosed) {
            // end of data
            context = null;
            return c.GetParsed();
              }
              else {
            throw new ImapMalformedDataException("unclosed parenthesis");
              }
            }
            else if (line[index] == Octets.SP) {
              index++;
            }
              }

              var bytes = line.ByteArray;

              for (;;) {
            if (bytes[index] == Octets.SP)
              // skip SP
              index = line.IndexOfNot(Octets.SP, index);

            switch (bytes[index]) {
              case ImapOctets.DQuote: {
            // quoted
            c.AddData(ImapData.CreateTextData(ParseQuotedString(line, ref index)));
            break;
              }

              case ImapOctets.OpenParen: {
            // parenthesized begin
            c.OpenParenthesis();
            index++; // '('
            break;
              }

              case ImapOctets.CloseParen: {
            // parenthesized end
            c.CloseParenthesis();
            index++; // ')'
            break;
              }

              case ImapOctets.OpenBrace:
              case ImapOctets.Tilde: {
            // literal/literal8
            ImapData parsed;

            var isLiteral = ParseLiteral((bytes[index] == ImapOctets.Tilde), line, ref index, out parsed);

            c.AddData(parsed);

            if (isLiteral)
              return null; // incomplete
            else
              break;
              }

              default: {
            // non-quoted
            var text = ParseNonQuotedString(line, ref index);

            if (nil.EqualsIgnoreCase(text))
              c.AddData(ImapData.CreateNilData());
            else
              c.AddData(ImapData.CreateTextData(text));

            break;
              }
            }

            if (line.Length - index == 2/*CRLF*/) {
              if (c.ParenthesesClosed) {
            // end of data
            context = null;
            return c.GetParsed();
              }
              else {
            return null; // incomplete
              }
            }
            else {
              if (bytes[index] == Octets.SP)
            index++;
            }
              } // for
        }