private State General( string line, char delimiter, ref ScratchPad scratchPad )
        {
            if ( line.StartsWith( @"#Date" ) )
            {
                return DateTime( line, delimiter, ref scratchPad );
            }
            else if ( line == @"#Scores" )
            {
                return State.ScoreHeaders;
            }

            return State.General;
        }
Exemple #2
0
        internal void ValidateCharset(bool charsetWasDefaulted, Stream contentStream)
        {
            bool strongDefault = !charsetWasDefaulted && this.charset.CodePage != 20127;
            FeInboundCharsetDetector feInboundCharsetDetector = new FeInboundCharsetDetector(this.charset.CodePage, strongDefault, true, true, true);

            byte[] byteBuffer = ScratchPad.GetByteBuffer(1024);
            int    num        = 0;
            int    num2       = 0;

            while (num2 < 4096 && (num = contentStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
            {
                feInboundCharsetDetector.AddBytes(byteBuffer, 0, num, false);
                num2 += num;
            }
            if (num == 0)
            {
                feInboundCharsetDetector.AddBytes(byteBuffer, 0, 0, true);
            }
            int codePageChoice = feInboundCharsetDetector.GetCodePageChoice();

            if (codePageChoice != this.charset.CodePage)
            {
                this.charset = Charset.GetCharset(codePageChoice);
            }
        }
Exemple #3
0
        private State ScoreHeaders(string line, char delimiter, ref ScratchPad scratchPad)
        {
            string[] tokens = line.Split(delimiter);

            for (int i = 0; i < tokens.Length; ++i)
            {
                if (tokens[i] == "Position")
                {
                    scratchPad.PositionColumn = i;
                    Debug.Print("Found position column: {0}", scratchPad.PositionColumn);
                }
                else if (tokens[i] == "Name1")
                {
                    scratchPad.Player1Column = i;
                    Debug.Print("Found player 1 column: {0}", scratchPad.Player1Column);
                }
                else if (tokens[i] == "Name2")
                {
                    scratchPad.Player2Column = i;
                    Debug.Print("Found player 2 column: {0}", scratchPad.Player2Column);
                }
                else if (tokens[i] == "Score")
                {
                    scratchPad.ScoreColumn = i;
                    Debug.Print("Found score column: {0}", scratchPad.ScoreColumn);
                }
            }

            Debug.Print("Header search complete");
            return(State.Scores);
        }
Exemple #4
0
        //--------
        //-------- Constructor
        //--------

        /// <summary> Memory bank contstuctor.  Requires reference to the OneWireContainer
        /// this memory bank resides on.
        /// </summary>
        public MemoryBankNVCRC(OneWireContainer ibutton, ScratchPad scratch) : base(ibutton, scratch)
        {
            // initialize attributes of this memory bank
            pageAutoCRC          = true;
            readContinuePossible = true;
            numVerifyBytes       = 0;
        }
Exemple #5
0
 private void luaScratchpadToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (ScratchPad == null)
     {
         ScratchPad = new ScratchPad();
     }
     ScratchPad.Show(dockPanel, DockState.Document);
 }
Exemple #6
0
        private State DateTime(string line, char delimiter, ref ScratchPad scratchPad)
        {
            string[] tokens = line.Split(delimiter);

            if (tokens[0] != @"#Date")
            {
                //TODO: Throw exception
            }

            scratchPad.DateTime = System.DateTime.Parse(tokens[1]);

            return(State.General);
        }
Exemple #7
0
        private State General(string line, char delimiter, ref ScratchPad scratchPad)
        {
            if (line.StartsWith(@"#Date"))
            {
                return(DateTime(line, delimiter, ref scratchPad));
            }
            else if (line == @"#Scores")
            {
                return(State.ScoreHeaders);
            }

            return(State.General);
        }
        private State DateTime( string line, char delimiter, ref ScratchPad scratchPad )
        {
            string[] tokens = line.Split( delimiter );

            if ( tokens[ 0 ] != @"#Date" )
            {
                //TODO: Throw exception
            }

            scratchPad.DateTime = System.DateTime.Parse( tokens[ 1 ] );

            return State.General;
        }
        // Token: 0x060004A4 RID: 1188 RVA: 0x0001A7C4 File Offset: 0x000189C4
        public override string ToString()
        {
            int count = this.Count;

            if (count <= 1)
            {
                return(this.first.ToString());
            }
            StringBuilder stringBuilder = ScratchPad.GetStringBuilder(this.Length);

            for (int i = 0; i < count; i++)
            {
                MimeString mimeString = this[i];
                string     value      = ByteString.BytesToString(mimeString.Data, mimeString.Offset, mimeString.Length, true);
                stringBuilder.Append(value);
            }
            ScratchPad.ReleaseStringBuilder();
            return(stringBuilder.ToString());
        }
        public ActionResult AddQuestion(string Name, string comment)
        {
            string userid   = User.Identity.Name;
            string username = dbContext.Users.Where(x => x.Email == userid).FirstOrDefault().Name;

            var _scratchpad = new ScratchPad()
            {
                ParentId    = 0,
                CommentText = comment,
                Username    = username,
                MesgFrom    = username,
                MesgTo      = Name,
                CommentDate = DateTime.Now
            };

            context.ScratchPads.Add(_scratchpad);
            context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #11
0
        //--------
        //-------- Constructor
        //--------

        /// <summary> Memory bank contstuctor.  Requires reference to the OneWireContainer
        /// this memory bank resides on.  Requires reference to memory banks used
        /// in OTP operations.
        /// </summary>
        public MemoryBankEEPROM(OneWireContainer ibutton, ScratchPad scratch)
        {
            // keep reference to ibutton where memory bank is
            ib = ibutton;

            // keep reference to scratchPad bank
            sp = scratch;

            // get references to MemoryBanks used in OTP operations, assume locking
            mbLock = null;
            lockPage_Renamed_Field = true;

            // initialize attributes of this memory bank - DEFAULT: Main memory DS2431
            generalPurposeMemory = true;
            bankDescription      = "Main memory";
            numberPages          = 4;
            size                   = 128;
            pageLength             = 32;
            maxPacketDataLength    = 29;
            readWrite              = true;
            writeOnce              = false;
            readOnly               = false;
            nonVolatile            = true;
            pageAutoCRC            = false;
            lockPage_Renamed_Field = true;
            programPulse           = false;
            powerDelivery          = true;
            extraInfo              = false;
            extraInfoLength        = 0;
            extraInfoDescription   = null;
            writeVerification      = false;
            startPhysicalAddress   = 0;
            doSetSpeed             = true;
            scratchPadSize         = 8;

            // create the ffblock (used for faster 0xFF fills)
            for (int i = 0; i < 500; i++)
            {
                ffBlock[i] = (byte)SupportClass.Identity(0xFF);
            }
        }
Exemple #12
0
        private void ParseLine(ref State state, string line, char delimiter, ref ScratchPad scratchPad)
        {
            switch (state)
            {
            case State.General:
                state = General(line, delimiter, ref scratchPad);
                break;

            case State.DateTime:
                state = DateTime(line, delimiter, ref scratchPad);
                break;

            case State.ScoreHeaders:
                state = ScoreHeaders(line, delimiter, ref scratchPad);
                break;

            case State.Scores:
                state = Scores(line, delimiter, ref scratchPad);
                break;
            }
        }
Exemple #13
0
        private void ParseLine( ref State state, string line, char delimiter, ref ScratchPad scratchPad )
        {
            switch ( state )
            {
            case State.General:
                state = General( line, delimiter, ref scratchPad );
                break;

            case State.DateTime:
                state = DateTime( line, delimiter, ref scratchPad );
                break;

            case State.ScoreHeaders:
                state = ScoreHeaders( line, delimiter, ref scratchPad );
                break;

            case State.Scores:
                state = Scores( line, delimiter, ref scratchPad );
                break;
            }
        }
Exemple #14
0
        public JsonResult addNewComment(commentDTO comment)
        {
            try
            {
                string userid   = User.Identity.Name;
                string username = dbContext.Users.Where(x => x.Email == userid).FirstOrDefault().Name;

                var _comment = new ScratchPad()
                {
                    ParentId    = comment.parentId,
                    MesgFrom    = "Reply",
                    MesgTo      = username,
                    CommentText = comment.commentText,
                    Username    = username,
                    CommentDate = DateTime.Now
                };

                context.ScratchPads.Add(_comment);
                context.SaveChanges();
                var model = context.sp_GetMessages(username: username, commentID: _comment.CommentID)
                            .Select(x => new commentViewModel
                {
                    commentId   = x.CommentID,
                    commentText = x.CommentText,
                    parentId    = x.ParentId,
                    commentDate = x.CommentDate,
                    username    = x.Username,
                    ImgUrl      = x.ImgUrl
                }).FirstOrDefault();

                return(Json(new { error = false, result = model }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                //Handle Error here..
                string exception = ex.Message.ToString();
            }

            return(Json(new { error = true }, JsonRequestBehavior.AllowGet));
        }
Exemple #15
0
        public void Parse( string file, char delimiter )
        {
            Debug.Print( "Parsing file '{0}' using delimiter: '{1}'", file, delimiter );

            State state = State.General;
            ScratchPad scratchPad = new ScratchPad()
            {
                Players = new List<Player>()
            };

            string[] lines = File.ReadAllLines( System.IO.Path.ChangeExtension( file, ".csv" ) );

            foreach ( string line in lines )
            {
                ParseLine( ref state, line, delimiter, ref scratchPad );
            }

            foreach ( Player player in scratchPad.Players )
            {
                Debug.Print( "Found player {0} with score {1} (Position {2}) for date: {3}", player.Name, player.Scores[ 0 ].Points, player.Scores[ 0 ].Position, player.Scores[ 0 ].DateTime );
            }
        }
Exemple #16
0
        public void Parse(string file, char delimiter)
        {
            Debug.Print("Parsing file '{0}' using delimiter: '{1}'", file, delimiter);

            State      state      = State.General;
            ScratchPad scratchPad = new ScratchPad()
            {
                Players = new List <Player>()
            };

            string[] lines = File.ReadAllLines(System.IO.Path.ChangeExtension(file, ".csv"));

            foreach (string line in lines)
            {
                ParseLine(ref state, line, delimiter, ref scratchPad);
            }

            foreach (Player player in scratchPad.Players)
            {
                Debug.Print("Found player {0} with score {1} (Position {2}) for date: {3}", player.Name, player.Scores[0].Points, player.Scores[0].Position, player.Scores[0].DateTime);
            }
        }
        private void ConvertRawFragment(ValuePosition start, ValuePosition end, Decoder decoder, bool allowControlCharacters, ref char[] charBuffer, StringBuilder sb)
        {
            ValueIterator valueIterator = new ValueIterator(this.iterator.Lines, this.iterator.LinesMask, start, end);

            if (!valueIterator.Eof)
            {
                if (charBuffer == null)
                {
                    charBuffer = ScratchPad.GetCharBuffer(Math.Min(1024, this.iterator.TotalLength));
                }
                int  length;
                int  num;
                bool flag;
                do
                {
                    decoder.Convert(valueIterator.Bytes, valueIterator.Offset, valueIterator.Length, charBuffer, 0, charBuffer.Length, false, out length, out num, out flag);
                    if (num != 0)
                    {
                        if (!allowControlCharacters)
                        {
                            ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, num);
                        }
                        sb.Append(charBuffer, 0, num);
                    }
                    valueIterator.Get(length);
                }while (!flag || !valueIterator.Eof);
                decoder.Convert(MimeString.EmptyByteArray, 0, 0, charBuffer, 0, charBuffer.Length, true, out length, out num, out flag);
                if (num != 0)
                {
                    if (!allowControlCharacters)
                    {
                        ValueDecoder.RemoveProhibitedControlCharacters(charBuffer, 0, num);
                    }
                    sb.Append(charBuffer, 0, num);
                }
            }
        }
Exemple #18
0
        private State Scores(string line, char delimiter, ref ScratchPad scratchPad)
        {
            if (line[0] == '#')
            {
                State state = State.General;
                ParseLine(ref state, line, delimiter, ref scratchPad);
                return(state);
            }

            string[] tokens = line.Split(delimiter);

            Score score = new Score()
            {
                DateTime = scratchPad.DateTime,
                Points   = float.Parse(tokens[scratchPad.ScoreColumn]),
                Position = int.Parse(tokens[scratchPad.PositionColumn])
            };

            Player player1 = new Player()
            {
                Name = tokens[scratchPad.Player1Column]
            };

            Player player2 = new Player()
            {
                Name = tokens[scratchPad.Player2Column]
            };

            player1.Scores.Add(score);
            player2.Scores.Add(score);

            scratchPad.Players.Add(player1);
            scratchPad.Players.Add(player2);

            return(State.Scores);
        }
Exemple #19
0
        //--------
        //-------- Constructor
        //--------

        /// <summary> Memory bank contstuctor.  Requires reference to the OneWireContainer
        /// this memory bank resides on. DEFAULT: DS1993 main memory
        ///
        /// </summary>
        /// <param name="ibutton">ibutton container that this memory bank resides in
        /// </param>
        /// <param name="scratchPad">memory bank referece for scratchpad, used when writing
        /// </param>
        public MemoryBankNV(OneWireContainer ibutton, ScratchPad scratch)
        {
            // keep reference to ibutton where memory bank is
            ib = ibutton;

            // keep reference to scratchPad bank
            sp = scratch;

            // initialize attributes of this memory bank - DEFAULT: DS1993 main memory
            bankDescription      = "Main Memory";
            generalPurposeMemory = true;
            startPhysicalAddress = 0;
            size                 = 512;
            readWrite            = true;
            writeOnce            = false;
            readOnly             = false;
            nonVolatile          = true;
            programPulse         = false;
            powerDelivery        = false;
            writeVerification    = true;
            numberPages          = 16;
            pageLength           = 32;
            maxPacketDataLength  = 29;
            pageAutoCRC          = false;
            extraInfo            = false;
            extraInfoLength      = 0;
            extraInfoDescription = null;

            // create the ffblock (used for faster 0xFF fills)
            ffBlock = new byte[96];

            for (int i = 0; i < 96; i++)
            {
                ffBlock[i] = (byte)SupportClass.Identity(0xFF);
            }
        }
        // Token: 0x06000252 RID: 594 RVA: 0x0000AF40 File Offset: 0x00009140
        internal static MimeStringList EncodeValue(string value, EncodingOptions encodingOptions, ValueEncodingStyle style)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(MimeStringList.Empty);
            }
            if (!MimeCommon.IsEncodingRequired(value, encodingOptions.AllowUTF8))
            {
                return(new MimeStringList(new MimeString(value)));
            }
            MimeStringList result = default(MimeStringList);
            Charset        encodingCharset;

            if (encodingOptions.CharsetName != null)
            {
                encodingCharset = encodingOptions.GetEncodingCharset();
            }
            else
            {
                OutboundCodePageDetector outboundCodePageDetector = new OutboundCodePageDetector();
                outboundCodePageDetector.AddText(value);
                int codePage = outboundCodePageDetector.GetCodePage();
                if (!Charset.TryGetCharset(codePage, out encodingCharset))
                {
                    encodingCharset = MimeCommon.DefaultEncodingOptions.GetEncodingCharset();
                }
            }
            ByteEncoder.Tables.CharClasses charClasses = ByteEncoder.Tables.CharClasses.QEncode;
            if (style == ValueEncodingStyle.Phrase)
            {
                charClasses |= ByteEncoder.Tables.CharClasses.QPhraseUnsafe;
            }
            else if (style == ValueEncodingStyle.Comment)
            {
                charClasses |= ByteEncoder.Tables.CharClasses.QCommentUnsafe;
            }
            bool allowQEncoding = false;

            MimeCommon.CalculateMethodAndChunkSize calculateMethodAndChunkSize;
            if (encodingCharset.Kind == CodePageKind.Sbcs)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeSbcs;
                if (encodingCharset.AsciiSupport >= CodePageAsciiSupport.Fine)
                {
                    allowQEncoding = true;
                }
            }
            else if (encodingCharset.Kind == CodePageKind.Dbcs)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeDbcs;
                if (encodingCharset.AsciiSupport >= CodePageAsciiSupport.Fine)
                {
                    allowQEncoding = true;
                }
            }
            else if (encodingCharset.CodePage == 65001)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeUtf8;
                allowQEncoding = true;
            }
            else if (encodingCharset.CodePage == 1200 || encodingCharset.CodePage == 1201)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeUnicode16;
            }
            else if (encodingCharset.CodePage == 12000 || encodingCharset.CodePage == 12001)
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeUnicode32;
            }
            else
            {
                calculateMethodAndChunkSize = MimeCommon.calculateMethodAndChunkSizeMbcs;
            }
            int num  = 75;
            int num2 = 7 + encodingCharset.Name.Length;
            int num3 = num - num2;

            if (num3 < 32)
            {
                num  = num2 + 32;
                num3 = 32;
            }
            byte[]   byteBuffer = ScratchPad.GetByteBuffer(num3);
            Encoding encoding   = encodingCharset.GetEncoding();

            byte[] array = new byte[5 + encodingCharset.Name.Length];
            int    num4  = 0;

            array[num4++] = 61;
            array[num4++] = 63;
            num4         += ByteString.StringToBytes(encodingCharset.Name, array, num4, false);
            array[num4++] = 63;
            array[num4++] = 88;
            array[num4++] = 63;
            MimeString mimeString = new MimeString(array);
            int        num5       = 0;

            byte[] array2 = null;
            int    num6   = 0;
            int    num7   = num3 / 4;

            while (num5 != value.Length)
            {
                byte b;
                int  num8;
                calculateMethodAndChunkSize(allowQEncoding, charClasses, encoding, value, num5, num3, out b, out num8);
                int bytes;
                int num10;
                for (;;)
                {
                    for (;;)
                    {
                        try
                        {
                            bytes = encoding.GetBytes(value, num5, num8, byteBuffer, 0);
                        }
                        catch (ArgumentException)
                        {
                            if (num8 < 2)
                            {
                                throw;
                            }
                            num8 -= ((num8 > 10) ? 3 : 1);
                            if (MimeCommon.IsLowSurrogate(value[num5 + num8]) && MimeCommon.IsHighSurrogate(value[num5 + num8 - 1]))
                            {
                                num8--;
                            }
                            break;
                        }
                        if (bytes == 0)
                        {
                            goto IL_424;
                        }
                        if (array2 == null || array2.Length - num6 < num + 1)
                        {
                            if (array2 != null)
                            {
                                result.Append(new MimeString(array2, 0, num6));
                                num6 = 0;
                            }
                            int val  = ((value.Length - num5) / num8 + 1) * (num + 1);
                            int num9 = Math.Min(val, 4096 / (num + 1) * (num + 1));
                            array2 = new byte[num9];
                        }
                        num10 = num6;
                        if (result.Count > 0 || num10 > 0)
                        {
                            array2[num10++] = 32;
                        }
                        num10            += mimeString.CopyTo(array2, num10);
                        array2[num10 - 2] = b;
                        if (b != 81)
                        {
                            goto IL_3F5;
                        }
                        int num11 = num10;
                        int num12 = 0;
                        while (num12 < bytes && num10 - num11 + 1 <= num3)
                        {
                            byte b2 = byteBuffer[num12];
                            if (MimeCommon.QEncodingRequired((char)b2, charClasses))
                            {
                                if (num10 - num11 + 3 > num3)
                                {
                                    break;
                                }
                                array2[num10++] = 61;
                                array2[num10++] = ByteEncoder.NibbleToHex[b2 >> 4];
                                array2[num10++] = ByteEncoder.NibbleToHex[(int)(b2 & 15)];
                            }
                            else
                            {
                                if (b2 == 32)
                                {
                                    b2 = 95;
                                }
                                array2[num10++] = b2;
                            }
                            num12++;
                        }
                        if (num12 == bytes)
                        {
                            goto IL_408;
                        }
                        if (num8 < 2)
                        {
                            goto Block_26;
                        }
                        num8 -= ((num8 > 10) ? 3 : 1);
                        if (MimeCommon.IsLowSurrogate(value[num5 + num8]) && MimeCommon.IsHighSurrogate(value[num5 + num8 - 1]))
                        {
                            num8--;
                        }
                    }
                }
IL_424:
                num5 += num8;
                continue;
Block_26:
                throw new InvalidOperationException("unexpected thing just happened");
IL_408:
                array2[num10++] = 63;
                array2[num10++] = 61;
                num6            = num10;
                goto IL_424;
IL_3F5:
                num10 += MimeCommon.Base64EncodeChunk(byteBuffer, 0, bytes, array2, num10);
                goto IL_408;
            }
            if (array2 != null)
            {
                result.Append(new MimeString(array2, 0, num6));
            }
            return(result);
        }
Exemple #21
0
        private State ScoreHeaders( string line, char delimiter, ref ScratchPad scratchPad )
        {
            string[] tokens = line.Split( delimiter );

            for ( int i = 0; i < tokens.Length; ++i )
            {
                if ( tokens[ i ] == "Position" )
                {
                    scratchPad.PositionColumn = i;
                    Debug.Print( "Found position column: {0}", scratchPad.PositionColumn );
                }
                else if ( tokens[ i ] == "Name1" )
                {
                    scratchPad.Player1Column = i;
                    Debug.Print( "Found player 1 column: {0}", scratchPad.Player1Column );
                }
                else if ( tokens[ i ] == "Name2" )
                {
                    scratchPad.Player2Column = i;
                    Debug.Print( "Found player 2 column: {0}", scratchPad.Player2Column );
                }
                else if ( tokens[ i ] == "Score" )
                {
                    scratchPad.ScoreColumn = i;
                    Debug.Print( "Found score column: {0}", scratchPad.ScoreColumn );
                }
            }

            Debug.Print( "Header search complete" );
            return State.Scores;
        }
Exemple #22
0
        private State Scores( string line, char delimiter, ref ScratchPad scratchPad )
        {
            if ( line[ 0 ] == '#' )
            {
                State state = State.General;
                ParseLine( ref state, line, delimiter, ref scratchPad );
                return state;
            }

            string[] tokens = line.Split( delimiter );

            Score score = new Score()
            {
                DateTime = scratchPad.DateTime,
                Points = float.Parse( tokens[ scratchPad.ScoreColumn ] ),
                Position = int.Parse( tokens[ scratchPad.PositionColumn ] )
            };

            Player player1 = new Player()
            {
                Name = tokens[ scratchPad.Player1Column ]
            };

            Player player2 = new Player()
            {
                Name = tokens[ scratchPad.Player2Column ]
            };

            player1.Scores.Add( score );
            player2.Scores.Add( score );

            scratchPad.Players.Add( player1 );
            scratchPad.Players.Add( player2 );

            return State.Scores;
        }
        private void DecodeEncodedWord(byte bOrQ, Decoder decoder, ValuePosition encodedWordContentStart, ValuePosition encodedWordContentEnd, bool allowControlCharacters, ref byte[] byteBuffer, ref char[] charBuffer, StringBuilder sb)
        {
            ValueIterator valueIterator = new ValueIterator(this.iterator.Lines, this.iterator.LinesMask, encodedWordContentStart, encodedWordContentEnd);

            if (charBuffer == null)
            {
                charBuffer = ScratchPad.GetCharBuffer(Math.Min(1024, this.iterator.TotalLength));
            }
            if (byteBuffer == null)
            {
                byteBuffer = ScratchPad.GetByteBuffer(Math.Max(this.maxCharsetNameLength + 1, Math.Min(1024, this.iterator.TotalLength)));
            }
            int num = 0;

            if (bOrQ == 66)
            {
                int num2 = 0;
                int num3 = 0;
                while (!valueIterator.Eof)
                {
                    byte b = (byte)(valueIterator.Get() - 32);
                    if ((int)b < ByteEncoder.Tables.Base64ToByte.Length)
                    {
                        b = ByteEncoder.Tables.Base64ToByte[(int)b];
                        if (b < 64)
                        {
                            num3 = (num3 << 6 | (int)b);
                            num2++;
                            if (num2 == 4)
                            {
                                byteBuffer[num++] = (byte)(num3 >> 16);
                                byteBuffer[num++] = (byte)(num3 >> 8);
                                byteBuffer[num++] = (byte)num3;
                                num2 = 0;
                                if (num + 3 >= byteBuffer.Length)
                                {
                                    this.FlushDecodedBytes(byteBuffer, num, decoder, allowControlCharacters, charBuffer, sb);
                                    num = 0;
                                }
                            }
                        }
                    }
                }
                if (num2 != 0)
                {
                    if (num2 == 2)
                    {
                        num3 <<= 12;
                        byteBuffer[num++] = (byte)(num3 >> 16);
                    }
                    else if (num2 == 3)
                    {
                        num3 <<= 6;
                        byteBuffer[num++] = (byte)(num3 >> 16);
                        byteBuffer[num++] = (byte)(num3 >> 8);
                    }
                }
            }
            else
            {
                while (!valueIterator.Eof)
                {
                    byte b2 = (byte)valueIterator.Get();
                    if (b2 == 61)
                    {
                        int num4 = valueIterator.Get();
                        int num5 = valueIterator.Get();
                        num4 = (int)((num4 < 0) ? byte.MaxValue : ByteEncoder.Tables.NumFromHex[num4]);
                        num5 = (int)((num5 < 0) ? byte.MaxValue : ByteEncoder.Tables.NumFromHex[num5]);
                        if (num4 == 255 || num5 == 255)
                        {
                            b2 = 61;
                        }
                        else
                        {
                            b2 = (byte)(num4 << 4 | num5);
                        }
                    }
                    else if (b2 == 95)
                    {
                        b2 = 32;
                    }
                    byteBuffer[num++] = b2;
                    if (num >= byteBuffer.Length)
                    {
                        this.FlushDecodedBytes(byteBuffer, num, decoder, allowControlCharacters, charBuffer, sb);
                        num = 0;
                    }
                }
            }
            if (num != 0)
            {
                this.FlushDecodedBytes(byteBuffer, num, decoder, allowControlCharacters, charBuffer, sb);
            }
        }
        private bool ParseEncodedWord(string lastEncodedWordCharsetName, string lastEncodedWordLanguage, ref byte[] byteBuffer, out string encodedWordCharsetName, out string encodedWordLanguage, out byte bOrQ, out ValuePosition encodedWordContentStart, out ValuePosition encodedWordContentEnd)
        {
            encodedWordCharsetName = null;
            encodedWordLanguage    = null;
            bOrQ = 0;
            ValuePosition valuePosition = default(ValuePosition);

            encodedWordContentEnd   = valuePosition;
            encodedWordContentStart = (encodedWordContentEnd = valuePosition);
            int num = this.iterator.Get();

            if (this.iterator.Get() != 63)
            {
                return(false);
            }
            if (byteBuffer == null)
            {
                byteBuffer = ScratchPad.GetByteBuffer(Math.Max(this.maxCharsetNameLength + 1, Math.Min(1024, this.iterator.TotalLength)));
            }
            int num2 = -1;
            int i;

            for (i = 0; i < this.maxCharsetNameLength + 1; i++)
            {
                num = this.iterator.Get();
                if (!ValueDecoder.Is2047Token((byte)num))
                {
                    break;
                }
                byteBuffer[i] = (byte)num;
                if (num2 == -1 && num == 42)
                {
                    num2 = i;
                }
            }
            if (i == this.maxCharsetNameLength + 1 || num != 63 || i == 0 || num2 == 0)
            {
                return(false);
            }
            num  = this.iterator.Get();
            bOrQ = ((num == 66 || num == 98) ? 66 : ((num == 81 || num == 113) ? 81 : 0));
            if (bOrQ == 0 || this.iterator.Get() != 63)
            {
                return(false);
            }
            if (num2 != -1)
            {
                int num3 = num2 + 1;
                int num4 = i - (num2 + 1);
                i = num2;
                if (num4 != 0)
                {
                    if (lastEncodedWordLanguage != null && num4 == lastEncodedWordLanguage.Length)
                    {
                        int num5 = 0;
                        while (num5 < num4 && lastEncodedWordLanguage[num5] == (char)byteBuffer[num3 + num5])
                        {
                            num5++;
                        }
                        if (num5 != num4)
                        {
                            encodedWordLanguage = ByteString.BytesToString(byteBuffer, num3, num4, false);
                        }
                        else
                        {
                            encodedWordLanguage = lastEncodedWordLanguage;
                        }
                    }
                    else
                    {
                        encodedWordLanguage = ByteString.BytesToString(byteBuffer, num3, num4, false);
                    }
                }
            }
            if (lastEncodedWordCharsetName != null && i == lastEncodedWordCharsetName.Length)
            {
                int num6 = 0;
                while (num6 < i && lastEncodedWordCharsetName[num6] == (char)byteBuffer[num6])
                {
                    num6++;
                }
                if (num6 != i)
                {
                    encodedWordCharsetName = ByteString.BytesToString(byteBuffer, 0, i, false);
                }
                else
                {
                    encodedWordCharsetName = lastEncodedWordCharsetName;
                }
            }
            else
            {
                encodedWordCharsetName = ByteString.BytesToString(byteBuffer, 0, i, false);
            }
            encodedWordContentStart = this.iterator.CurrentPosition;
            bool flag = false;

            for (;;)
            {
                encodedWordContentEnd = this.iterator.CurrentPosition;
                num = this.iterator.Get();
                if (num == -1)
                {
                    break;
                }
                if (MimeScan.IsLWSP((byte)num))
                {
                    flag = true;
                }
                else
                {
                    if (num == 63)
                    {
                        num = this.iterator.Get();
                        if (num == -1)
                        {
                            return(false);
                        }
                        if (num == 61)
                        {
                            return(true);
                        }
                        this.iterator.Unget();
                        if (bOrQ != 81)
                        {
                            return(false);
                        }
                    }
                    else if (num == 61 && flag)
                    {
                        num = this.iterator.Get();
                        if (num == -1)
                        {
                            return(false);
                        }
                        if (num == 63)
                        {
                            goto Block_33;
                        }
                        this.iterator.Unget();
                    }
                    flag = false;
                }
            }
            return(false);

Block_33:
            this.iterator.Unget();
            this.iterator.Unget();
            return(false);
        }
        public bool TryDecodeValue(Charset defaultCharset, bool enableFallback, bool allowControlCharacters, bool enable2047, bool enableJisDetection, bool enableUtf8Detection, bool enableDbcsDetection, out string charsetName, out string cultureName, out EncodingScheme encodingScheme, out string value)
        {
            charsetName    = null;
            cultureName    = null;
            encodingScheme = EncodingScheme.None;
            value          = null;
            StringBuilder stringBuilder = ScratchPad.GetStringBuilder(Math.Min(1024, this.iterator.TotalLength));

            char[]        array           = null;
            byte[]        array2          = null;
            ValuePosition currentPosition = this.iterator.CurrentPosition;
            bool          flag            = false;
            bool          flag2           = false;

            if (defaultCharset != null && (enableJisDetection || enableUtf8Detection || (enableDbcsDetection && FeInboundCharsetDetector.IsSupportedFarEastCharset(defaultCharset))))
            {
                defaultCharset = this.DetectValueCharset(defaultCharset, enableJisDetection, enableUtf8Detection, enableDbcsDetection, out encodingScheme);
                flag2          = true;
            }
            Decoder decoder = null;
            string  text    = null;

            if (!enable2047)
            {
                this.iterator.SkipToEof();
            }
            else
            {
                string  lastEncodedWordLanguage = null;
                Charset charset  = null;
                Decoder decoder2 = null;
                bool    flag3    = true;
                string  text2;
                for (;;)
                {
                    this.ParseRawFragment(ref flag);
                    if (this.iterator.Eof)
                    {
                        goto IL_217;
                    }
                    ValuePosition currentPosition2 = this.iterator.CurrentPosition;
                    string        text3;
                    byte          bOrQ;
                    ValuePosition encodedWordContentStart;
                    ValuePosition encodedWordContentEnd;
                    if (!this.ParseEncodedWord(text, lastEncodedWordLanguage, ref array2, out text2, out text3, out bOrQ, out encodedWordContentStart, out encodedWordContentEnd))
                    {
                        flag = false;
                    }
                    else
                    {
                        if (text == null)
                        {
                            encodingScheme = EncodingScheme.Rfc2047;
                            charsetName    = text2;
                            cultureName    = text3;
                        }
                        text = text2;
                        if (currentPosition != currentPosition2 && !flag)
                        {
                            if (!flag3)
                            {
                                this.FlushDecoder(decoder2, allowControlCharacters, ref array2, ref array, stringBuilder);
                                flag3 = true;
                            }
                            if (decoder == null)
                            {
                                if (defaultCharset == null || !defaultCharset.IsAvailable)
                                {
                                    if (!enableFallback)
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    decoder = defaultCharset.GetEncoding().GetDecoder();
                                }
                            }
                            if (decoder != null)
                            {
                                this.ConvertRawFragment(currentPosition, currentPosition2, decoder, allowControlCharacters, ref array, stringBuilder);
                            }
                            else
                            {
                                this.ZeroExpandFragment(currentPosition, currentPosition2, allowControlCharacters, stringBuilder);
                            }
                        }
                        Charset charset2;
                        if (!Charset.TryGetCharset(text2, out charset2))
                        {
                            if (!flag3)
                            {
                                this.FlushDecoder(decoder2, allowControlCharacters, ref array2, ref array, stringBuilder);
                                flag3 = true;
                            }
                            if (!enableFallback)
                            {
                                goto Block_19;
                            }
                            decoder2 = null;
                        }
                        else if (charset2 != charset)
                        {
                            if (!flag3)
                            {
                                this.FlushDecoder(decoder2, allowControlCharacters, ref array2, ref array, stringBuilder);
                                flag3 = true;
                            }
                            if (!charset2.IsAvailable)
                            {
                                if (!enableFallback)
                                {
                                    goto Block_23;
                                }
                                decoder2 = null;
                            }
                            else
                            {
                                decoder2 = charset2.GetEncoding().GetDecoder();
                                charset  = charset2;
                            }
                        }
                        if (decoder2 != null)
                        {
                            this.DecodeEncodedWord(bOrQ, decoder2, encodedWordContentStart, encodedWordContentEnd, allowControlCharacters, ref array2, ref array, stringBuilder);
                            flag3 = false;
                        }
                        else
                        {
                            this.ZeroExpandFragment(currentPosition2, this.iterator.CurrentPosition, allowControlCharacters, stringBuilder);
                        }
                        currentPosition = this.iterator.CurrentPosition;
                        flag            = true;
                    }
                }
                charsetName = ((defaultCharset == null) ? null : defaultCharset.Name);
                return(false);

Block_19:
                charsetName = text2;
                return(false);

Block_23:
                charsetName = text2;
                return(false);

IL_217:
                if (!flag3)
                {
                    this.FlushDecoder(decoder2, allowControlCharacters, ref array2, ref array, stringBuilder);
                }
            }
            if (currentPosition != this.iterator.CurrentPosition)
            {
                if (text == null)
                {
                    if (flag2 && encodingScheme == EncodingScheme.None && defaultCharset != null && !defaultCharset.IsSevenBit && defaultCharset.AsciiSupport == CodePageAsciiSupport.Complete)
                    {
                        charsetName = Charset.ASCII.Name;
                    }
                    else
                    {
                        charsetName = ((defaultCharset == null) ? null : defaultCharset.Name);
                    }
                }
                if (decoder == null)
                {
                    if (defaultCharset == null || !defaultCharset.IsAvailable)
                    {
                        if (!enableFallback)
                        {
                            charsetName = ((defaultCharset == null) ? null : defaultCharset.Name);
                            return(false);
                        }
                        decoder = null;
                    }
                    else
                    {
                        decoder = defaultCharset.GetEncoding().GetDecoder();
                    }
                }
                if (decoder != null)
                {
                    this.ConvertRawFragment(currentPosition, this.iterator.CurrentPosition, decoder, allowControlCharacters, ref array, stringBuilder);
                }
                else
                {
                    this.ZeroExpandFragment(currentPosition, this.iterator.CurrentPosition, allowControlCharacters, stringBuilder);
                }
            }
            ScratchPad.ReleaseStringBuilder();
            value = stringBuilder.ToString();
            return(true);
        }