Exemplo n.º 1
0
        public static string[] split(java.util.regex.Pattern pattern, string re, string input
                                     , int limit)
        {
            string[] fastResult = fastSplit(re, input, limit);
            if (fastResult != null)
            {
                return(fastResult);
            }
            // Unlike Perl, which considers the result of splitting the empty string to be the empty
            // array, Java returns an array containing the empty string.
            if (string.IsNullOrEmpty(input))
            {
                return(new string[] { string.Empty });
            }
            // Collect text preceding each occurrence of the separator, while there's enough space.
            java.util.ArrayList <string> list = new java.util.ArrayList <string>();
            int maxSize = limit <= 0 ? int.MaxValue : limit;

            java.util.regex.Matcher matcher = new java.util.regex.Matcher(pattern, java.lang.CharSequenceProxy.Wrap
                                                                              (input));
            int begin = 0;

            while (matcher.find() && list.size() + 1 < maxSize)
            {
                list.add(Sharpen.StringHelper.Substring(input, begin, matcher.start()));
                begin = matcher.end();
            }
            return(finishSplit(list, input, begin, maxSize, limit));
        }
Exemplo n.º 2
0
        /**
         * Converts the original query string to a collection of Lucene Tokens.
         * @param original the original query string
         * @return a Collection of Lucene Tokens
         */
        public override Collection /*<Token>*/ convert(string original)
        {
            if (original == null) // this can happen with q.alt = and no query
            {
                return(Collections.emptyList());
            }
            Collection /*<Token>*/ result = new ArrayList/*<Token>*/ ();
            //TODO: Extract the words using a simple regex, but not query stuff, and then analyze them to produce the token stream
            Matcher     matcher = QUERY_REGEX.matcher(original);
            TokenStream stream;

            while (matcher.find())
            {
                string word = matcher.group(0);
                if (word.Equals("AND") == false && word.Equals("OR") == false)
                {
                    try {
                        stream = analyzer.reusableTokenStream("", new StringReader(word));
                        // TODO: support custom attributes
                        TermAttribute              termAtt    = (TermAttribute)stream.addAttribute(typeof(TermAttribute));
                        FlagsAttribute             flagsAtt   = (FlagsAttribute)stream.addAttribute(typeof(FlagsAttribute));
                        TypeAttribute              typeAtt    = (TypeAttribute)stream.addAttribute(typeof(TypeAttribute));
                        PayloadAttribute           payloadAtt = (PayloadAttribute)stream.addAttribute(typeof(PayloadAttribute));
                        PositionIncrementAttribute posIncAtt  = (PositionIncrementAttribute)stream.addAttribute(typeof(PositionIncrementAttribute));
                        stream.reset();
                        while (stream.incrementToken())
                        {
                            Token token = new Token();
                            token.setTermBuffer(termAtt.termBuffer(), 0, termAtt.termLength());
                            token.setStartOffset(matcher.start());
                            token.setEndOffset(matcher.end());
                            token.setFlags(flagsAtt.getFlags());
                            token.setType(typeAtt.type());
                            token.setPayload(payloadAtt.getPayload());
                            token.setPositionIncrement(posIncAtt.getPositionIncrement());
                            result.add(token);
                        }
                    }
#pragma warning disable 168
                    catch (IOException e)
                    {
                    }
#pragma warning restore 168
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 public GroupCollection(Match match, java.util.regex.Matcher matcher, string input)
 {
     this.match = match;
     if (matcher == null)
     {
         elements = new Group[0];
     }
     else
     {
         int n = matcher?.groupCount() ?? 0;
         elements = new Group[n + 1];
         for (int i = 0; i <= n; i++)
         {
             elements[i] = new Group(i, input, matcher.start(i), matcher.end(i));
         }
     }
 }
Exemplo n.º 4
0
		public static string[] split(java.util.regex.Pattern pattern, string re, string input
			, int limit)
		{
			string[] fastResult = fastSplit(re, input, limit);
			if (fastResult != null)
			{
				return fastResult;
			}
			// Unlike Perl, which considers the result of splitting the empty string to be the empty
			// array, Java returns an array containing the empty string.
			if (string.IsNullOrEmpty(input))
			{
				return new string[] { string.Empty };
			}
			// Collect text preceding each occurrence of the separator, while there's enough space.
			java.util.ArrayList<string> list = new java.util.ArrayList<string>();
			int maxSize = limit <= 0 ? int.MaxValue : limit;
			java.util.regex.Matcher matcher = new java.util.regex.Matcher(pattern, java.lang.CharSequenceProxy.Wrap
				(input));
			int begin = 0;
			while (matcher.find() && list.size() + 1 < maxSize)
			{
				list.add(Sharpen.StringHelper.Substring(input, begin, matcher.start()));
				begin = matcher.end();
			}
			return finishSplit(list, input, begin, maxSize, limit);
		}
Exemplo n.º 5
0
 public Match(java.util.regex.Matcher matcher, string input)
     : base(0, input, matcher.start(), matcher.end())
 {
     groupCollection = new GroupCollection(this, matcher, input);
 }