Beispiel #1
0
            /// <summary>
            /// See <see cref="AWnd.Child"/>.
            /// </summary>
            /// <exception cref="ArgumentException">See <see cref="Child"/>.</exception>
            public ChildFinder(
                [ParamString(PSFormat.AWildex)] string name = null,
                [ParamString(PSFormat.AWildex)] string cn   = null,
                WCFlags flags = 0, Func <AWnd, bool> also = null, int skip = 0)
            {
                if (cn != null)
                {
                    if (cn.Length == 0)
                    {
                        throw new ArgumentException("Class name cannot be \"\". Use null.");
                    }
                    _className = cn;
                }
                if (name != null)
                {
                    switch (AStringUtil.ParseParam3Stars(ref name, "id", "text", "accName", "wfName" /*, "label"*/))
                    {
                    case -1: throw new ArgumentException("Invalid name prefix. Can be: \"***id \", \"***text \", \"***accName \", \"***wfName \".");                     //, \"***label \"

                    case 1: _nameIs = _NameIs.id; _id = name.ToInt(); break;

                    case 2: _nameIs = _NameIs.text; break;

                    case 3: _nameIs = _NameIs.accName; break;

                    case 4: _nameIs = _NameIs.wfName; break;
                        //case 5: _nameIs = _NameIs.label; break;
                    }
                    if (_nameIs != _NameIs.id)
                    {
                        _name = name;
                    }
                }
                _flags     = flags;
                _also      = also;
                _skipCount = skip;
            }
Beispiel #2
0
        /// <param name="wildcardExpression">
        /// [Wildcard expression](xref:wildcard_expression).
        /// Cannot be null (throws exception).
        /// "" will match "".
        /// </param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException">Invalid <c>"**options "</c> or regular expression.</exception>
        public AWildex([ParamString(PSFormat.AWildex)] string wildcardExpression)
        {
            var w = wildcardExpression;

            if (w == null)
            {
                throw new ArgumentNullException();
            }
            _type       = WXType.Wildcard;
            _ignoreCase = true;
            string[] split = null;

            if (w.Length >= 3 && w[0] == '*' && w[1] == '*')
            {
                for (int i = 2, j; i < w.Length; i++)
                {
                    switch (w[i])
                    {
                    case 't': _type = WXType.Text; break;

                    case 'r': _type = WXType.RegexPcre; break;

                    case 'R': _type = WXType.RegexNet; break;

                    case 'm': _type = WXType.Multi; break;

                    case 'c': _ignoreCase = false; break;

                    case 'n': _not = true; break;

                    case ' ': w = w.Substring(i + 1); goto g1;

                    case '(':
                        if (w[i - 1] != 'm')
                        {
                            goto ge;
                        }
                        for (j = ++i; j < w.Length; j++)
                        {
                            if (w[j] == ')')
                            {
                                break;
                            }
                        }
                        if (j >= w.Length || j == i)
                        {
                            goto ge;
                        }
                        split = new string[] { w.Substring(i, j - i) };
                        i     = j;
                        break;

                    default: goto ge;
                    }
                }
ge:
                throw new ArgumentException("Invalid \"**options \" in wildcard expression.");
g1:
                switch (_type)
                {
                case WXType.RegexNet:
                    var ro = _ignoreCase ? (RegexOptions.IgnoreCase | RegexOptions.CultureInvariant) : RegexOptions.CultureInvariant;
                    _o = new Regex(w, ro);
                    return;

                case WXType.RegexPcre:
                    _o = new ARegex(w);
                    return;

                case WXType.Multi:
                    var a     = w.Split(split ?? _splitMulti, StringSplitOptions.None);
                    var multi = new AWildex[a.Length];
                    for (int i = 0; i < a.Length; i++)
                    {
                        multi[i] = new AWildex(a[i]);
                    }
                    _o = multi;
                    return;
                }
            }

            if (_type == WXType.Wildcard && !HasWildcardChars(w))
            {
                _type = WXType.Text;
            }
            _o = w;
        }