public int Find(char[] characterSet, int start, int end)
 {
     System.Windows.Forms.NativeMethods.CHARRANGE charrange;
     bool flag = true;
     bool negate = false;
     int textLength = this.TextLength;
     if (characterSet == null)
     {
         throw new ArgumentNullException("characterSet");
     }
     if ((start < 0) || (start > textLength))
     {
         throw new ArgumentOutOfRangeException("start", System.Windows.Forms.SR.GetString("InvalidBoundArgument", new object[] { "start", start, 0, textLength }));
     }
     if ((end < start) && (end != -1))
     {
         throw new ArgumentOutOfRangeException("end", System.Windows.Forms.SR.GetString("InvalidLowBoundArgumentEx", new object[] { "end", end, "start" }));
     }
     if (characterSet.Length == 0)
     {
         return -1;
     }
     int windowTextLength = System.Windows.Forms.SafeNativeMethods.GetWindowTextLength(new HandleRef(this, base.Handle));
     if (start == end)
     {
         start = 0;
         end = windowTextLength;
     }
     if (end == -1)
     {
         end = windowTextLength;
     }
     charrange = new System.Windows.Forms.NativeMethods.CHARRANGE {
         cpMax = charrange.cpMin = start
     };
     System.Windows.Forms.NativeMethods.TEXTRANGE lParam = new System.Windows.Forms.NativeMethods.TEXTRANGE {
         chrg = new System.Windows.Forms.NativeMethods.CHARRANGE()
     };
     lParam.chrg.cpMin = charrange.cpMin;
     lParam.chrg.cpMax = charrange.cpMax;
     System.Windows.Forms.UnsafeNativeMethods.CharBuffer buffer = System.Windows.Forms.UnsafeNativeMethods.CharBuffer.CreateBuffer(0x201);
     lParam.lpstrText = buffer.AllocCoTaskMem();
     if (lParam.lpstrText == IntPtr.Zero)
     {
         throw new OutOfMemoryException();
     }
     try
     {
         bool flag3 = false;
         while (!flag3)
         {
             if (flag)
             {
                 lParam.chrg.cpMin = charrange.cpMax;
                 lParam.chrg.cpMax += 0x200;
             }
             else
             {
                 lParam.chrg.cpMax = charrange.cpMin;
                 lParam.chrg.cpMin -= 0x200;
                 if (lParam.chrg.cpMin < 0)
                 {
                     lParam.chrg.cpMin = 0;
                 }
             }
             if (end != -1)
             {
                 lParam.chrg.cpMax = Math.Min(lParam.chrg.cpMax, end);
             }
             int num3 = (int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x44b, 0, lParam);
             if (num3 == 0)
             {
                 charrange.cpMax = charrange.cpMin = -1;
                 goto Label_02F4;
             }
             buffer.PutCoTaskMem(lParam.lpstrText);
             string str = buffer.GetString();
             if (flag)
             {
                 for (int i = 0; i < num3; i++)
                 {
                     if (this.GetCharInCharSet(str[i], characterSet, negate))
                     {
                         flag3 = true;
                         continue;
                     }
                     charrange.cpMax++;
                 }
             }
             else
             {
                 int num5 = num3;
                 while (num5-- != 0)
                 {
                     if (this.GetCharInCharSet(str[num5], characterSet, negate))
                     {
                         flag3 = true;
                         continue;
                     }
                     charrange.cpMin--;
                 }
             }
         }
     }
     finally
     {
         if (lParam.lpstrText != IntPtr.Zero)
         {
             Marshal.FreeCoTaskMem(lParam.lpstrText);
         }
     }
 Label_02F4:
     return (flag ? charrange.cpMax : charrange.cpMin);
 }
 public int Find(string str, int start, int end, RichTextBoxFinds options)
 {
     int textLength = this.TextLength;
     if (str == null)
     {
         throw new ArgumentNullException("str");
     }
     if ((start < 0) || (start > textLength))
     {
         throw new ArgumentOutOfRangeException("start", System.Windows.Forms.SR.GetString("InvalidBoundArgument", new object[] { "start", start, 0, textLength }));
     }
     if (end < -1)
     {
         throw new ArgumentOutOfRangeException("end", System.Windows.Forms.SR.GetString("RichTextFindEndInvalid", new object[] { end }));
     }
     bool flag = true;
     System.Windows.Forms.NativeMethods.FINDTEXT lParam = new System.Windows.Forms.NativeMethods.FINDTEXT {
         chrg = new System.Windows.Forms.NativeMethods.CHARRANGE(),
         lpstrText = str
     };
     if (end == -1)
     {
         end = textLength;
     }
     if (start > end)
     {
         throw new ArgumentException(System.Windows.Forms.SR.GetString("RichTextFindEndInvalid", new object[] { end }));
     }
     if ((options & RichTextBoxFinds.Reverse) != RichTextBoxFinds.Reverse)
     {
         lParam.chrg.cpMin = start;
         lParam.chrg.cpMax = end;
     }
     else
     {
         lParam.chrg.cpMin = end;
         lParam.chrg.cpMax = start;
     }
     if (lParam.chrg.cpMin == lParam.chrg.cpMax)
     {
         if ((options & RichTextBoxFinds.Reverse) != RichTextBoxFinds.Reverse)
         {
             lParam.chrg.cpMin = 0;
             lParam.chrg.cpMax = -1;
         }
         else
         {
             lParam.chrg.cpMin = textLength;
             lParam.chrg.cpMax = 0;
         }
     }
     int wParam = 0;
     if ((options & RichTextBoxFinds.WholeWord) == RichTextBoxFinds.WholeWord)
     {
         wParam |= 2;
     }
     if ((options & RichTextBoxFinds.MatchCase) == RichTextBoxFinds.MatchCase)
     {
         wParam |= 4;
     }
     if ((options & RichTextBoxFinds.NoHighlight) == RichTextBoxFinds.NoHighlight)
     {
         flag = false;
     }
     if ((options & RichTextBoxFinds.Reverse) != RichTextBoxFinds.Reverse)
     {
         wParam |= 1;
     }
     int startIndex = (int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x438, wParam, lParam);
     if ((startIndex != -1) && flag)
     {
         System.Windows.Forms.NativeMethods.CHARRANGE charrange = new System.Windows.Forms.NativeMethods.CHARRANGE {
             cpMin = startIndex
         };
         char ch = 'ـ';
         string text = this.Text;
         int index = text.Substring(startIndex, str.Length).IndexOf(ch);
         if (index == -1)
         {
             charrange.cpMax = startIndex + str.Length;
         }
         else
         {
             int num5 = index;
             int num6 = startIndex + index;
             while (num5 < str.Length)
             {
                 while ((text[num6] == ch) && (str[num5] != ch))
                 {
                     num6++;
                 }
                 num5++;
                 num6++;
             }
             charrange.cpMax = num6;
         }
         System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x437, 0, charrange);
         base.SendMessage(0xb7, 0, 0);
     }
     return startIndex;
 }
 private void StreamIn(Stream data, int flags)
 {
     if ((flags & 0x8000) == 0)
     {
         System.Windows.Forms.NativeMethods.CHARRANGE lParam = new System.Windows.Forms.NativeMethods.CHARRANGE();
         System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x437, 0, lParam);
     }
     try
     {
         this.editStream = data;
         if ((flags & 2) != 0)
         {
             long position = this.editStream.Position;
             byte[] buffer = new byte[SZ_RTF_TAG.Length];
             this.editStream.Read(buffer, (int) position, SZ_RTF_TAG.Length);
             string str = Encoding.Default.GetString(buffer);
             if (!SZ_RTF_TAG.Equals(str))
             {
                 throw new ArgumentException(System.Windows.Forms.SR.GetString("InvalidFileFormat"));
             }
             this.editStream.Position = position;
         }
         int num2 = 0;
         System.Windows.Forms.NativeMethods.EDITSTREAM es = new System.Windows.Forms.NativeMethods.EDITSTREAM();
         if ((flags & 0x10) != 0)
         {
             num2 = 9;
         }
         else
         {
             num2 = 5;
         }
         if ((flags & 2) != 0)
         {
             num2 |= 0x40;
         }
         else
         {
             num2 |= 0x10;
         }
         es.dwCookie = (IntPtr) num2;
         es.pfnCallback = new System.Windows.Forms.NativeMethods.EditStreamCallback(this.EditStreamProc);
         base.SendMessage(0x435, 0, 0x7fffffff);
         if (IntPtr.Size == 8)
         {
             System.Windows.Forms.NativeMethods.EDITSTREAM64 editstream2 = this.ConvertToEDITSTREAM64(es);
             System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x449, flags, editstream2);
             es.dwError = this.GetErrorValue64(editstream2);
         }
         else
         {
             System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x449, flags, es);
         }
         this.UpdateMaxLength();
         if (!this.GetProtectedError())
         {
             if (es.dwError != 0)
             {
                 throw new InvalidOperationException(System.Windows.Forms.SR.GetString("LoadTextError"));
             }
             base.SendMessage(0xb9, -1, 0);
             base.SendMessage(0xba, 0, 0);
         }
     }
     finally
     {
         this.editStream = null;
     }
 }