Ejemplo n.º 1
0
        /// <summary>
        /// Validate text box when clicking the "OK" button
        /// </summary>
        /// <param name="sender">object that fired the event</param>
        /// <param name="e">event arguments</param>
        private void BtnOk_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(m_txtName.Text))
            {
                DialogResult = DialogResult.None;
            }
            else
            {
                // Copy text over
                var szText = m_txtName.Text;

                // Find all occurences of *
                var asterisks = SledUtil.IndicesOf(szText, '*');

                // Verify no back to back asterisks
                if (asterisks.Length > 0)
                {
                    var iLast   = -5;
                    var iOffset = 0;

                    foreach (var t in asterisks)
                    {
                        if (t == (iLast + 1))
                        {
                            szText = szText.Remove(t - iOffset++, 1);
                        }

                        iLast = t;
                    }
                }

                // Update text if it differs
                if (string.Compare(szText, m_txtName.Text) != 0)
                {
                    m_txtName.Text = szText;
                }
            }
        }
Ejemplo n.º 2
0
        private bool VarNameFiltered(string name, ICollection <string> lstFilteredNames)
        {
            if (lstFilteredNames.Count <= 0)
            {
                return(false);
            }

            foreach (var filterName in lstFilteredNames)
            {
                // All occurrences of asterisks
                var asterisks = SledUtil.IndicesOf(filterName, '*');

                if (asterisks.Length > 0)
                {
                    // 1 or more asterisks so pattern check

                    // Is first character of filter pattern an asterisk?
                    var bFirst = (asterisks[0] == 0);

                    // Is last character of filter pattern an asterisk?
                    var bLast = (asterisks[asterisks.Length - 1] == (filterName.Length - 1));

                    // Patterns combined are longer than name so name can't contain patterns
                    if ((filterName.Length - asterisks.Length) > name.Length)
                    {
                        continue;
                    }

                    // Check for just asterisk
                    if (bFirst && bLast && (filterName.Length == 1))
                    {
                        return(true);
                    }

                    // Array of patterns
                    var patterns = filterName.Split(m_chPatternSep, StringSplitOptions.RemoveEmptyEntries);
                    if (patterns.Length <= 0)
                    {
                        continue;
                    }

                    var iPos    = -1;
                    var bFailed = false;

                    // Go through checking if all patterns exist in name
                    for (var i = 0; (i < patterns.Length) && !bFailed; i++)
                    {
                        iPos = name.IndexOf(patterns[i], iPos + 1, StringComparison.Ordinal);

                        // Pattern was not found
                        if (iPos == -1)
                        {
                            bFailed = true;
                            continue;
                        }

                        // On first iteration check bFirst condition
                        if ((i == 0) && !bFirst && (iPos != 0))
                        {
                            bFailed = true;
                            continue;
                        }

                        // On last iteration check bLast condition
                        if ((i == (patterns.Length - 1)) && !bLast && (iPos != (name.Length - patterns[patterns.Length - 1].Length)))
                        {
                            bFailed = true;
                        }
                    }

                    if (bFailed)
                    {
                        continue;
                    }

                    return(true);
                }

                // No asterisks so simple name check
                if (name == filterName)
                {
                    return(true);
                }
            }

            return(false);
        }