Esempio n. 1
0
        private bool searchEntryForWord(string sourceText, string searchWord)
        {
            // Remove any tags from sourceText.
            sourceText = stripTags.Replace(sourceText, String.Empty);

            CompareInfo myComp = CultureInfo.InvariantCulture.CompareInfo;

            return(myComp.IndexOf(sourceText, searchWord, CompareOptions.IgnoreCase) >= 0);
        }
        private static string CreateCountSQL(string sql)
        {
            const string countSatement = "SELECT COUNT(*) ";
            CompareInfo  Compare       = CultureInfo.InvariantCulture.CompareInfo;
            var          Index         = Compare.IndexOf(sql, "FROM", CompareOptions.IgnoreCase);
            var          countSql      = countSatement + sql.AsSpan().Slice(Index).ToString();

            return(countSql);
        }
Esempio n. 3
0
        public void IndexOf_String(CompareInfo compareInfo, string source, string value, int startIndex, int count, CompareOptions options, int expected, int expectedMatchLength)
        {
            if (value.Length == 1)
            {
                IndexOf_Char(compareInfo, source, value[0], startIndex, count, options, expected);
            }
            if (options == CompareOptions.None)
            {
                // Use IndexOf(string, string, int, int) or IndexOf(string, string)
                if (startIndex == 0 && count == source.Length)
                {
                    // Use IndexOf(string, string)
                    Assert.Equal(expected, compareInfo.IndexOf(source, value));
                }
                // Use IndexOf(string, string, int, int)
                Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, count));
            }
            if (startIndex + count == source.Length)
            {
                // Use IndexOf(string, string, int, CompareOptions) or IndexOf(string, string, CompareOptions)
                if (startIndex == 0)
                {
                    // Use IndexOf(string, string, CompareOptions)
                    Assert.Equal(expected, compareInfo.IndexOf(source, value, options));
                }
                // Use IndexOf(string, string, int, CompareOptions)
                Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, options));
            }
            // Use IndexOf(string, string, int, int, CompareOptions)
            Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, count, options));

            if ((compareInfo == s_invariantCompare) && ((options == CompareOptions.None) || (options == CompareOptions.IgnoreCase)))
            {
                StringComparison stringComparison = (options == CompareOptions.IgnoreCase) ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture;
                // Use int string.IndexOf(string, StringComparison)
                Assert.Equal(expected, source.IndexOf(value, startIndex, count, stringComparison));
                // Use int MemoryExtensions.IndexOf(this ReadOnlySpan<char>, ReadOnlySpan<char>, StringComparison)
                Assert.Equal((expected == -1) ? -1 : (expected - startIndex), source.AsSpan(startIndex, count).IndexOf(value.AsSpan(), stringComparison));
            }

            // Now test the span-based versions - use BoundedMemory to detect buffer overruns

            RunSpanIndexOfTest(compareInfo, source.AsSpan(startIndex, count), value, options, (expected < 0) ? expected : expected - startIndex, expectedMatchLength);
        public void TestExc <T>(CultureInfo culture, string str1, string str2, CompareOptions options)
            where T : Exception
        {
            CompareInfo ci = culture.CompareInfo;

            Assert.Throws <T>(() =>
            {
                int i = ci.IndexOf(str1, str2, options);
            });
        }
        public static object _Internal_ContainsIgnoreCase(object corpus, object pattern)
        {
            var ctx = corpus as string;
            var ptx = pattern as string;

            if (ctx == null || ptx == null)
            {
                return(Undefined.Value);
            }
            return(CompareInfo.IndexOf(ctx, ptx, CompareOptions.OrdinalIgnoreCase) >= 0);
        }
Esempio n. 6
0
        /// <summary>
        /// 塞选方法 - 返回满足条件的句柄集合
        /// </summary>
        /// <param name="textName">窗口标题 - 为空不匹配标题( 模糊匹配,不区分大小写)</param>
        /// <param name="textClass">窗口类名 - 为空不匹配类名( 模糊匹配,不区分大小写)</param>
        /// <returns></returns>
        public List <int> EnumWindow(string textName, string textClass)
        {
            CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo;
            List <int>  gethwnd = new List <int>();
            //先取得所有句柄
            List <WindowInfo> Listwindows = GetAllDesktopWindows();

            //
            foreach (WindowInfo wdf in Listwindows)
            {
                if (textName != "" && textClass != "")
                {
                    if (Compare.IndexOf(wdf.szClassName.ToUpper(), textClass.ToUpper()) > -1 && Compare.IndexOf(wdf.szWindowName.ToUpper(), textName.ToUpper()) > -1)
                    {
                        gethwnd.Add((int)wdf.hWnd);
                    }
                }
                else if (textName == "" && textClass == "")
                {
                    gethwnd.Add((int)wdf.hWnd);
                    //都返回
                }
                else if (textName == "")
                {
                    //只匹配类名
                    if (Compare.IndexOf(wdf.szClassName.ToUpper(), textClass.ToUpper()) > -1)
                    {
                        gethwnd.Add((int)wdf.hWnd);
                    }
                }
                else if (textClass == "")
                {
                    //只匹配标题
                    if (Compare.IndexOf(wdf.szWindowName.ToUpper(), textName.ToUpper()) > -1)
                    {
                        gethwnd.Add((int)wdf.hWnd);
                    }
                }
            }
            return(gethwnd);
        }
Esempio n. 7
0
        public DataSet GetDataByQuery(string search)
        {
            CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo;

            SQLiteDBHelper db   = new SQLiteDBHelper(path);
            string         outS = "(";
            bool           flag = false;

            search = search.Replace(" ", "");
            using (SQLiteDataReader reader = db.ExecuteReader("select ID,CodeName,Comments from CodeMass order by id", null))
            {
                while (reader.Read())
                {
                    if ((Compare.IndexOf(reader.GetString(1).Replace(" ", ""), search, CompareOptions.IgnoreCase) != -1) ||
                        (Compare.IndexOf(reader.GetString(2).Replace(" ", ""), search, CompareOptions.IgnoreCase) != -1))
                    {
                        outS = outS + reader.GetInt64(0).ToString() + ",";
                        flag = true;
                    }
                }
                if (flag)
                {
                    outS = outS.Substring(0, outS.Length - 1) + ")";
                }
                else
                {
                    outS = "(-1,-2)";
                }
            }

            String connectionString = "Data Source=" + path;
            //String selectCommand = "Select ID, CodeName,Language,AddTime,UpdateTime,Source_Code,Comments from CodeMass";
            //String selectCommand = "select * from CodeMass where CodeName like '%"+ChangeStrToLikeStr(search) + "%'";
            String            selectCommand = "select * from CodeMass where ID in " + outS;
            SQLiteDataAdapter dataAdapter   = new SQLiteDataAdapter(selectCommand, connectionString);

            DataSet ds = new DataSet();

            dataAdapter.Fill(ds, "T_CLASS");
            return(ds);
        }
Esempio n. 8
0
        public void IndexOf(string culture, string source, string value, CompareOptions options)
        {
            CompareInfo compareInfo = CultureInfo.GetCultureInfo(culture).CompareInfo;

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                {
                    compareInfo.IndexOf(source, value, options);
                }
            }
        }
Esempio n. 9
0
        public static int IndexOfCultureIgnoreCaseHelper(ReadOnlySpan <char> span, ReadOnlySpan <char> value, CompareInfo compareInfo)
        {
            Debug.Assert(span.Length != 0);
            Debug.Assert(value.Length != 0);

            if (GlobalizationMode.Invariant)
            {
                return(CompareInfo.InvariantIndexOf(span, value, ignoreCase: true));
            }

            return(compareInfo.IndexOf(span, value, CompareOptions.IgnoreCase));
        }
Esempio n. 10
0
 public static IEnumerable <ComboItem> GetItemsMatching(string itemName, IReadOnlyList <ComboItem> strings)
 {
     foreach (var item in strings)
     {
         var result = Comparer.IndexOf(item.Text, itemName, opt);
         if (result < 0)
         {
             continue;
         }
         yield return(item);
     }
 }
Esempio n. 11
0
    public static void IndexOf(string localeName, string source, string value, int expectedResult, CompareOptions options)
    {
        CompareInfo ci = CompareInfo.GetCompareInfo(localeName);

        Assert.Equal(expectedResult, ci.IndexOf(source, value, options));

        if (value.Length == 1)
        {
            Assert.Equal(expectedResult, ci.IndexOf(source, value[0], options));
        }

        if (options == CompareOptions.None)
        {
            Assert.Equal(expectedResult, ci.IndexOf(source, value));
        }

        if (value.Length == 1 && options == CompareOptions.None)
        {
            Assert.Equal(expectedResult, ci.IndexOf(source, value[0]));
        }
    }
Esempio n. 12
0
        /// <summary>
        /// Return true if the specified URL is from a LinkMe domain.
        /// </summary>
        private static bool IsInternalUrl(string host, string absoluteUri)
        {
            CompareInfo compare = CultureInfo.CurrentCulture.CompareInfo;

            // Compare against the current request.

            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                if (compare.Compare(host, context.Request.Url.Host, CompareOptions.IgnoreCase) == 0)
                {
                    return(true);
                }
            }

            return((compare.IndexOf(absoluteUri, InsecureRootUrl, CompareOptions.IgnoreCase) == 0) ||
                   (compare.IndexOf(absoluteUri, SecureRootUrl, CompareOptions.IgnoreCase) == 0) ||
                   (compare.Compare(host, "localhost", CompareOptions.IgnoreCase) == 0) ||
                   (compare.Compare(host, Dns.GetHostName(), CompareOptions.IgnoreCase) == 0));
        }
Esempio n. 13
0
        /// <summary>
        /// 指定した文字列内の指定した文字列を別の文字列に置換する。
        /// </summary>
        /// <param name="input">置換する文字列のある文字列。</param>
        /// <param name="oldValue">検索文字列。</param>
        /// <param name="newValue">置換文字列。</param>
        /// <param name="count">置換する回数。負の数が指定されたときは、すべて置換する。</param>
        /// <param name="compInfo">文字列の検索に使用するCompareInfo。</param>
        /// <param name="compOptions">文字列の検索に使用するCompareOptions。</param>
        /// <returns>置換された結果の文字列。</returns>
        public static string ReplaceByForwardCount(string input, string oldValue, string newValue, int count,
                                                   CompareInfo compInfo, CompareOptions compOptions)
        {
            if (input == null || input.Length == 0 ||
                oldValue == null || oldValue.Length == 0 ||
                count == 0)
            {
                return(input);
            }

            if (compInfo == null)
            {
                compInfo    = CultureInfo.InvariantCulture.CompareInfo;
                compOptions = CompareOptions.Ordinal;
            }

            int           inputLen    = input.Length;
            int           oldValueLen = oldValue.Length;
            StringBuilder buf         = new StringBuilder(inputLen);

            int currentPoint = 0;
            int foundPoint   = -1;
            int currentCount = 0;

            do
            {
                //文字列を検索する
                foundPoint = compInfo.IndexOf(input, oldValue, currentPoint, compOptions);
                if (foundPoint < 0)
                {
                    buf.Append(input.Substring(currentPoint));
                    break;
                }

                //見つかった文字列を新しい文字列に換える
                buf.Append(input.Substring(currentPoint, foundPoint - currentPoint));
                buf.Append(newValue);

                //次の検索開始位置を取得
                currentPoint = foundPoint + oldValueLen;

                //指定回数置換したか調べる
                currentCount++;
                if (currentCount == count)
                {
                    buf.Append(input.Substring(currentPoint));
                    break;
                }
            }while (currentPoint < inputLen);

            return(buf.ToString());
        }
        private byte[] BytesFromBase64String(string base64string)
        {
            CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
            int         index       = compareInfo.IndexOf(base64string, ";base64,", CompareOptions.Ordinal);

            if (index < 0)
            {
                return(null);
            }
            var base64clean = base64string.Substring(index + ";base64,".Length);

            return(Convert.FromBase64String(base64clean));
        }
Esempio n. 15
0
        /// <summary>
        /// 获取符合条件的所有最小数据
        /// </summary>
        /// <param name="strInfo">需要进行查找的字符串</param>
        /// <param name="stMark">开始标识</param>
        /// <param name="edMark">结束标识</param>
        /// <param name="isSelf">是否包含开始结束标识</param>
        /// <returns>开始与结束标识之间的内容</returns>
        public static List <string> GetStringList(string strInfo, string stMark, string edMark, bool isSelf)
        {
            CompareInfo   Compare  = CultureInfo.InvariantCulture.CompareInfo;
            List <string> strList  = new List <string>();
            int           index    = 0;
            int           endIndex = 0;

            while (index > -1 && strInfo.Length > 0)
            {
                index = Compare.IndexOf(strInfo, stMark, CompareOptions.IgnoreCase);//忽略大小写
                if (index > -1)
                {
                    if (isSelf)
                    {
                        strInfo  = strInfo.Substring(index);
                        endIndex = Compare.IndexOf(strInfo, edMark, stMark.Length, CompareOptions.IgnoreCase);//忽略大小写
                    }
                    else
                    {
                        strInfo  = strInfo.Substring(index + stMark.Length);
                        endIndex = Compare.IndexOf(strInfo, edMark, CompareOptions.IgnoreCase);//忽略大小写
                    }
                    if (endIndex > -1)
                    {
                        if (isSelf)
                        {
                            strList.Add(strInfo.Substring(0, endIndex + edMark.Length));
                        }
                        else
                        {
                            strList.Add(strInfo.Substring(0, endIndex));
                        }
                        strInfo = strInfo.Substring(endIndex + edMark.Length);
                    }
                    index = endIndex;
                }
            }
            return(strList);
        }
Esempio n. 16
0
        /// <summary>
        /// Output the field string adding delimiters and any required quotes
        /// </summary>
        /// <param name="sb">buffer to add field to</param>
        /// <param name="fieldValue">value object to add</param>
        /// <param name="isLast">Indicates if we are processing last field</param>
        internal override void CreateFieldString(StringBuilder sb, object fieldValue, bool isLast)
        {
            string field = base.CreateFieldString(fieldValue);

            bool hasNewLine = mCompare.IndexOf(field, StringHelper.NewLine, CompareOptions.Ordinal) >= 0;

            // If have a new line and this is not allowed.  We throw an exception
            if (hasNewLine &&
                (QuoteMultiline == MultilineMode.AllowForRead ||
                 QuoteMultiline == MultilineMode.NotAllow))
            {
                throw new BadUsageException("One value for the field " + this.FieldInfo.Name +
                                            " has a new line inside. To allow write this value you must add a FieldQuoted attribute with the multiline option in true.");
            }

            // Add Quotes If:
            //     -  optional == false
            //     -  is optional and contains the separator
            //     -  is optional and contains a new line

            if ((QuoteChar != '\0') &&
                (QuoteMode == QuoteMode.AlwaysQuoted ||
                 QuoteMode == QuoteMode.OptionalForRead ||
                 ((QuoteMode == QuoteMode.OptionalForWrite || QuoteMode == QuoteMode.OptionalForBoth) &&
                  mCompare.IndexOf(field, mSeparator, CompareOptions.Ordinal) >= 0) || hasNewLine))
            {
                StringHelper.CreateQuotedString(sb, field, QuoteChar);
            }
            else
            {
                sb.Append(field);
            }

            if (isLast == false)
            {
                sb.Append(mSeparator);
            }
        }
Esempio n. 17
0
        public static bool Contains(string str1, string str2)
        {
            if (string.IsNullOrWhiteSpace(str2))
            {
                return(true);
            }
            if (string.IsNullOrWhiteSpace(str1))
            {
                return(false);
            }
            CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;

            return(compareInfo.IndexOf(str1, str2, CompareOptions.IgnoreCase | CompareOptions.IgnoreSymbols | CompareOptions.IgnoreNonSpace) > -1);
        }
Esempio n. 18
0
        public static Controller.Find FindString(TextEditor Editor, string SearchQuery, int lastIndex, bool IgnoreCase)
        {
            Controller.Find find   = new Controller.Find();
            CompareInfo     myComp = CultureInfo.InvariantCulture.CompareInfo;

            string Text = Editor.Text;

            if (SearchQuery.Length > 0 && Text.Length > 0)
            {
                find.Index = myComp.IndexOf(Text, SearchQuery, lastIndex, (IgnoreCase == true) ? CompareOptions.IgnoreCase : CompareOptions.None);
                find.Line  = (find.Index == -1) ? -1 : Editor.TextArea.Document.GetLineByOffset(find.Index).LineNumber;
                return(find);
            }
            return(null);
        }
Esempio n. 19
0
        public static string SubstringBefore(this string source, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(value);
            }
            CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
            int         index       = compareInfo.IndexOf(source, value, CompareOptions.OrdinalIgnoreCase);

            if (index < 0)
            {
                return(string.Empty);
            }
            return(source.Substring(0, index));
        }
Esempio n. 20
0
    public static void Main()
    {
        CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

        string s1 = "ani\u00ADmal";
        string s2 = "animal";

        int position = 0;

        // Find the index of the soft hyphen.
        position = ci.IndexOf(s1, 'n');
        Console.WriteLine("'n' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.IndexOf(s1, '\u00AD', position, s1.Length - position));
        }

        position = ci.IndexOf(s2, 'n');
        Console.WriteLine("'n' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.IndexOf(s2, '\u00AD', position, s2.Length - position));
        }
    }
Esempio n. 21
0
        /// <summary>
        /// Modified from Oleg Tkachenko's SubstringBefore and SubstringAfter extension functions
        /// @ http://www.tkachenko.com/blog/archives/000684.html
        /// This will be moved into an appropriate class once I have the time.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string SubstringAfter(this string source, string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(source);
            }
            CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
            int         index       = compareInfo.IndexOf(source, value, CompareOptions.Ordinal);

            if (index < 0)
            {
                //No such substring
                return(string.Empty);
            }
            return(source.Substring(index + value.Length));
        }
        private DataTable Ara(string aranan, DataTable dt, string arananStun)
        {
            arananDt = dt.Copy();
            arananDt.Clear();
            CompareInfo karsilastirma = CultureInfo.InvariantCulture.CompareInfo;

            foreach (DataRow row in dt.Rows)
            {
                if (karsilastirma.IndexOf(row[arananStun].ToString(), aranan, CompareOptions.IgnoreCase) == 0)
                {
                    arananDt.ImportRow(row);
                }
            }

            return arananDt;
        }
        public static string SubstringBefore(this string aText, string aSearchedSubstring)
        {
            if (string.IsNullOrEmpty(aSearchedSubstring))
            {
                return(aSearchedSubstring);
            }

            CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
            int         index       = compareInfo.IndexOf(aText, aSearchedSubstring, CompareOptions.Ordinal);

            if (index < 0)
            {
                return(string.Empty); //No such substring
            }
            return(aText.Substring(0, index));
        }
Esempio n. 24
0
        // Token: 0x06002E72 RID: 11890 RVA: 0x000D26DC File Offset: 0x000D08DC
        private static bool _FoundOnPage(string pageString, string findPattern, CultureInfo cultureInfo, CompareOptions compareOptions)
        {
            CompareInfo compareInfo = cultureInfo.CompareInfo;

            string[] array = findPattern.Split(null);
            if (array != null)
            {
                foreach (string value in array)
                {
                    if (!string.IsNullOrEmpty(value) && compareInfo.IndexOf(pageString, value, compareOptions) == -1)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 25
0
    public static void Main()
    {
        CompareInfo ci = CultureInfo.CurrentCulture.CompareInfo;

        string s1 = "ani\u00ADmal";
        string s2 = "animal";

        int position = 0;

        // Find the index of the soft hyphen using culture-sensitive comparison.
        position = ci.IndexOf(s1, 'n');
        Console.WriteLine("'n' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.IndexOf(s1, '\u00AD', position,
                                         s1.Length - position, CompareOptions.IgnoreCase));
        }

        position = ci.IndexOf(s2, 'n');
        Console.WriteLine("'n' at position {0}", position);
        if (position >= 0)
        {
            Console.WriteLine(ci.IndexOf(s2, '\u00AD', position,
                                         s2.Length - position, CompareOptions.IgnoreCase));
        }

        // Find the index of the soft hyphen using ordinal comparison.
        position = ci.IndexOf(s1, 'n');
        Console.WriteLine("'n' at position {0}", position, CompareOptions.Ordinal);
        if (position >= 0)
        {
            Console.WriteLine(ci.IndexOf(s1, '\u00AD', position,
                                         s1.Length - position, CompareOptions.Ordinal));
        }

        position = ci.IndexOf(s2, 'n');
        Console.WriteLine("'n' at position {0}", position, CompareOptions.Ordinal);
        if (position >= 0)
        {
            Console.WriteLine(ci.IndexOf(s2, '\u00AD', position,
                                         s2.Length - position, CompareOptions.Ordinal));
        }
    }
Esempio n. 26
0
        // Returns the index and length of the first or last occurance of one string
        // within another string.
        private static int StandardMatchIndexCalculation(string textString, string findPattern, bool matchWholeWord, bool matchLast, bool ignoreCase, CompareInfo compareInfo, bool hasPreceedingSeparatorChar, bool hasFollowingSeparatorChar, out int matchLength)
        {
            CompareOptions options      = ignoreCase ? CompareOptions.IgnoreCase : 0;
            int            matchIndex   = -1;
            int            searchStart  = 0;
            int            searchLength = textString.Length;

            matchLength = 0;

            while (searchLength > 0)
            {
                matchIndex = matchLast ?
                             compareInfo.LastIndexOf(textString, findPattern, searchStart + searchLength - 1, searchLength, options) :
                             compareInfo.IndexOf(textString, findPattern, searchStart, searchLength, options);

                matchLength = findPattern.Length;

                if (matchIndex == -1)
                {
                    break;
                }

                if (!matchWholeWord || IsAtWordBoundary(textString, matchIndex, matchLength, hasPreceedingSeparatorChar, hasFollowingSeparatorChar))
                {
                    break;
                }

                if (matchLast)
                {
                    searchStart  = 0;
                    searchLength = matchIndex + matchLength - 1;
                }
                else
                {
                    searchStart  = matchIndex + 1;
                    searchLength = textString.Length - searchStart;
                }

                matchIndex = -1;
            }

            return(matchIndex);
        }
Esempio n. 27
0
        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;
            HttpResponse    response    = context.Response;
            string          path        = context.Request.FilePath;

            //重写后的URL地址
            if (path.IndexOf("member") > -1 || path.IndexOf("menu") > -1 ||
                path.IndexOf("orders") > -1 || path.IndexOf("syspage") > -1 ||
                path.IndexOf("sysparam") > -1 || path.IndexOf("sysuser") > -1 ||
                path.IndexOf("control") > -1)
            {
                CompareInfo Compare = CultureInfo.InvariantCulture.CompareInfo;
                if (Compare.IndexOf(path, "images", CompareOptions.IgnoreCase) == -1)
                {
                    //...
                }
            }
        }
        public static string StringReplace(
            [DekiScriptParam("string value")] string text,
            [DekiScriptParam("old value")] string before,
            [DekiScriptParam("new value")] string after,
            [DekiScriptParam("ignore case (default: false)", true)] bool?ignorecase
            )
        {
            // check for the degenarate case
            if (before.Length == 0)
            {
                // nothing to do
                return(text);
            }

            // check if we're doing a case-insensitve replace
            if (ignorecase ?? false)
            {
                StringBuilder result = new StringBuilder();

                // use culture specific comparer
                CompareInfo compare = GetCulture().CompareInfo;
                int         start   = 0;
                while (true)
                {
                    int index = compare.IndexOf(text, before, start, CompareOptions.IgnoreCase);
                    if (index < 0)
                    {
                        // append the end of the string and we're done
                        result.Append(text, start, text.Length - start);
                        break;
                    }

                    // append the part we skipped over, then the replacement
                    result.Append(text, start, index - start);
                    result.Append(after);
                    start = index + before.Length;
                }
                return(result.ToString());
            }
            return(text.Replace(before, after));
        }
Esempio n. 29
0
        private static string SubstringAfter(this string str, string separator)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(str);
            }
            if (separator == null)
            {
                return(string.Empty);
            }

            CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
            int         index       = compareInfo.IndexOf(str, separator, CompareOptions.Ordinal);

            if (index < 0)
            {
                //No such substring
                return(string.Empty);
            }
            return(str.Substring(index + separator.Length));
        }
Esempio n. 30
0
        private void FillList()
        {
            // first finish edit opeation
            FinishEdit();

            lvwMessages.Items.Clear();
            Array values = Enum.GetValues(typeof(NativeMethods.Msgs));

            Array.Sort(values);

            string filter = txtFilter.Text;

            if (filter.Equals(Properties.Resources.Filter_Key))
            {
                filter = string.Empty;
            }
            filter = filter.ToUpper(CultureInfo.InvariantCulture);

            bool        onlyWatched = chkOnlyWactheds.Checked;
            CompareInfo info        = CompareInfo.GetCompareInfo(1033);

            for (int i = 0; i < values.Length; i++)
            {
                NativeMethods.Msgs msg = (NativeMethods.Msgs)values.GetValue(i);
                if ((onlyWatched && !_Watchs.ContainsKey(msg)) ||
                    info.IndexOf(msg.ToString().ToUpper(CultureInfo.InvariantCulture), filter) == -1)
                {
                    continue;
                }
                lvwMessages.Items.Add(msg);
            }

            foreach (KeyValuePair <NativeMethods.Msgs, FormMain.MessageBreakpoint> watch in _Watchs)
            {
                if (Array.IndexOf(values, watch.Key) == -1)
                {
                    lvwMessages.Items.Add(watch.Key);
                }
            }
        }
        public void IndexOfTest(CompareInfo compareInfo, string source, string value, int startIndex, int indexOfExpected, int lastIndexOfExpected)
        {
            Assert.Equal(indexOfExpected, compareInfo.IndexOf(source, value, startIndex));
            if (value.Length > 0)
            {
                Assert.Equal(indexOfExpected, compareInfo.IndexOf(source, value[0], startIndex));
            }

            Assert.Equal(lastIndexOfExpected, compareInfo.LastIndexOf(source, value, startIndex));
            if (value.Length > 0)
            {
                Assert.Equal(lastIndexOfExpected, compareInfo.LastIndexOf(source, value[0], startIndex));
            }
        }
 public void IndexOf_Char(CompareInfo compareInfo, string source, char value, int startIndex, int count, CompareOptions options, int expected)
 {
     if (options == CompareOptions.None)
     {
         // Use IndexOf(string, char, int, int) or IndexOf(string, char)
         if (startIndex == 0 && count == source.Length)
         {
             // Use IndexOf(string, char)
             Assert.Equal(expected, compareInfo.IndexOf(source, value));
         }
         // Use IndexOf(string, char, int, int)
         Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, count));
     }
     if (startIndex + count == source.Length)
     {
         // Use IndexOf(string, char, int, CompareOptions) or IndexOf(string, char, CompareOptions)
         if (startIndex == 0)
         {
             // Use IndexOf(string, char, CompareOptions)
             Assert.Equal(expected, compareInfo.IndexOf(source, value, options));
         }
         // Use IndexOf(string, char, int, CompareOptions)
         Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, options));
     }
     // Use IndexOf(string, char, int, int, CompareOptions)
     Assert.Equal(expected, compareInfo.IndexOf(source, value, startIndex, count, options));
 }