Beispiel #1
0
        /// <summary>Construct a new pattern matching filter.</summary>
        /// <remarks>Construct a new pattern matching filter.</remarks>
        /// <param name="pattern">
        /// text of the pattern. Callers may want to surround their
        /// pattern with ".*" on either end to allow matching in the
        /// middle of the string.
        /// </param>
        /// <param name="innerString">
        /// should .* be wrapped around the pattern of ^ and $ are
        /// missing? Most users will want this set.
        /// </param>
        /// <param name="rawEncoding">
        /// should
        /// <see cref="ForceToRaw(string)">ForceToRaw(string)</see>
        /// be applied to the pattern
        /// before compiling it?
        /// </param>
        /// <param name="flags">
        /// flags from
        /// <see cref="Sharpen.Pattern">Sharpen.Pattern</see>
        /// to control how matching performs.
        /// </param>
        protected internal PatternMatchRevFilter(string pattern, bool innerString, bool rawEncoding
			, int flags)
        {
            if (pattern.Length == 0)
            {
                throw new ArgumentException(JGitText.Get().cannotMatchOnEmptyString);
            }
            patternText = pattern;
            if (innerString)
            {
                if (!pattern.StartsWith("^") && !pattern.StartsWith(".*"))
                {
                    pattern = ".*" + pattern;
                }
                if (!pattern.EndsWith("$") && !pattern.EndsWith(".*"))
                {
                    pattern = pattern + ".*";
                }
            }
            string p = rawEncoding ? ForceToRaw(pattern) : pattern;
            compiledPattern = Sharpen.Pattern.Compile(p, flags).Matcher(string.Empty);
        }
Beispiel #2
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
 private static Dispatch2 GetResultArray(bool matched, RegExpNI _this, Matcher m)
 {
     Dispatch2 array = TJS.CreateArrayObject();
     if (matched)
     {
         if (_this.RegEx == null)
         {
             Variant val = new Variant(string.Empty);
             array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, 0, val, array);
         }
         else
         {
             if (m != null)
             {
                 bool isMatch = m.Matches();
                 Variant val;
                 if (isMatch)
                 {
                     val = new Variant(m.Group(0));
                     array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, 0, val, array);
                 }
                 int size = m.GroupCount();
                 for (int i = 0; i < size; i++)
                 {
                     val = new Variant(m.Group(i + 1));
                     array.PropSetByNum(Interface.MEMBERENSURE | Interface.IGNOREPROP, i + 1, val, array
                         );
                 }
             }
         }
     }
     return array;
 }