public String[] split(CharSequence input, int limit) {
     int index = 0;
     boolean matchLimited = limit > 0;
     ArrayList<String> matchList = new ArrayList<String>();
     Matcher m = matcher(input);
     // Add segments before each match found
     while(m.find()) {
         if (!matchLimited || matchList.size() < limit - 1) {
             String match = input.subSequence(index, m.start()).toString();
             matchList.add(match);
             index = m.end();
         } else if (matchList.size() == limit - 1) { // last one
             String match = input.subSequence(index,
                                              input.length()).toString();
             matchList.add(match);
             index = m.end();
         }
     }
     // If no match was found, return this
     if (index == 0)
         return new String[] {input.toString()};
     // Add remaining segment
     if (!matchLimited || matchList.size() < limit)
         matchList.add(input.subSequence(index, input.length()).toString());
     // Construct result
     int resultSize = matchList.size();
     if (limit == 0)
         while (resultSize > 0 && matchList.get(resultSize-1).equals(""))
             resultSize--;
     String[] result = new String[resultSize];
     return matchList.subList(0, resultSize).toArray(result);
 }
 public Matcher matcher(CharSequence input) {
     if (!compiled) {
         lock(this) {
             if (!compiled)
                 compile();
         }
     }
     Matcher m = new Matcher(this, input);
     return m;
 }
 // Documentation in subclasses because of synchro difference
 public virtual AbstractStringBuilder append(CharSequence s)
 {
     if (s == null)
     s = new String("null");
     /*        if (s is String)
     return this.append((String)s);
     if (s is StringBuffer)
     return this.append((StringBuffer)s);*/
     return this.append(s, 0, s.length());
 }
 internal Matcher(Pattern parent, CharSequence text)
 {
     this.parentPattern = parent;
     this.text = text;
     // Allocate state storage
     int parentGroupCount = Math.max(parent.capturingGroupCount, 10);
     groups = new int[parentGroupCount * 2];
     locals = new int[parent.localCount];
     // Put fields into initial states
     reset();
 }
 public new StringBuffer append(CharSequence s)
 {
     // Note, synchronization achieved via other invocations
     if (s == null)
     s = new String("null");
     /*        if (s is String)
     return this.append((String)s);
     if (s is StringBuffer)
     return this.append((StringBuffer)s);*/
     return this.append(s, 0, s.length());
 }
 public virtual AbstractStringBuilder append(CharSequence s, int start, int end)
 {
     if (s == null)
     s = new String("null");
     if ((start < 0) || (start > end) || (end > s.length()))
     throw new IndexOutOfRangeException(
         "start " + start + ", end " + end + ", s.length() "
         + s.length());
     int len = end - start;
     ensureCapacityInternal(count + len);
     for (int i = start, j = count; i < end; i++, j++)
     value[j] = s.charAt(i);
     count += len;
     return this;
 }
 public new StringBuilder insert(int dstOffset, CharSequence s,
                         int start, int end)
 {
     base.insert(dstOffset, s, start, end);
     return this;
 }
 public new StringBuilder append(CharSequence s, int start, int end)
 {
     base.append(s, start, end);
     return this;
 }
 int check(Matcher matcher, int i, CharSequence seq) {
     int ch;
     boolean left = false;
     int startIndex = matcher.from;
     int endIndex = matcher.to;
     if (matcher.transparentBounds) {
         startIndex = 0;
         endIndex = matcher.getTextLength();
     }
     if (i > startIndex) {
         ch = Character.codePointBefore(seq, i);
         left = (isWord(ch) ||
             ((Character.getType(ch) == Character.NON_SPACING_MARK)
              && hasBaseCharacter(matcher, i-1, seq)));
     }
     boolean right = false;
     if (i < endIndex) {
         ch = Character.codePointAt(seq, i);
         right = (isWord(ch) ||
             ((Character.getType(ch) == Character.NON_SPACING_MARK)
              && hasBaseCharacter(matcher, i, seq)));
     } else {
         // Tried to access char past the end
         matcher._hitEnd = true;
         // The addition of another char could wreck a boundary
         matcher._requireEnd = true;
     }
     return ((left ^ right) ? (right ? LEFT : RIGHT) : NONE);
 }
Exemplo n.º 10
0
 public Matcher reset(CharSequence input)
 {
     text = input;
     return reset();
 }
Exemplo n.º 11
0
 public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
 {
 }
Exemplo n.º 12
0
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     int savedTo = matcher.to;
     boolean conditionMatched = false;
     // Relax transparent region boundaries for lookahead
     if (matcher.transparentBounds)
         matcher.to = matcher.getTextLength();
     try {
         conditionMatched = cond.match(matcher, i, seq);
     } finally {
         // Reinstate region boundaries
         matcher.to = savedTo;
     }
     return conditionMatched && next.match(matcher, i, seq);
 }
 public virtual AbstractStringBuilder insert(int dstOffset, CharSequence s)
 {
     if (s == null)
     s = new String("null");
     /*        if (s is String)
     return this.insert(dstOffset, (String)s);*/
     return this.insert(dstOffset, s, 0, s.length());
 }
Exemplo n.º 14
0
 public static boolean matches(String regex, CharSequence input) {
     Pattern p = Pattern.compile(regex);
     Matcher m = p.matcher(input);
     return m.matches();
 }
Exemplo n.º 15
0
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     int savedFrom = matcher.from;
     boolean conditionMatched = false;
     int startIndex = (!matcher.transparentBounds) ?
                      matcher.from : 0;
     int from = Math.max(i - rmax, startIndex);
     // Set end boundary
     int savedLBT = matcher.lookbehindTo;
     matcher.lookbehindTo = i;
     // Relax transparent region boundaries for lookbehind
     if (matcher.transparentBounds)
         matcher.from = 0;
     for (int j = i - rmin; !conditionMatched && j >= from; j--) {
         conditionMatched = cond.match(matcher, j, seq);
     }
     matcher.from = savedFrom;
     matcher.lookbehindTo = savedLBT;
     return conditionMatched && next.match(matcher, i, seq);
 }
Exemplo n.º 16
0
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     int[] src = buffer;
     int patternLength = src.Length;
     int last = matcher.to - lengthInChars;
     // Loop over all possible match positions in text
     while (i <= last) {
         // Loop over pattern from right to left
         int ch;
         for (int j = countChars(seq, i, patternLength), x = patternLength - 1;
              j > 0; j -= Character.charCount(ch), x--) {
             ch = Character.codePointBefore(seq, i+j);
             if (ch != src[x]) {
                 // Shift search to the right by the maximum of the
                 // bad character shift and the good suffix shift
                 int n = Math.max(x + 1 - lastOcc[ch&0x7F], optoSft[x]);
                 i += countChars(seq, i, n);
                 goto continue5;
             }
         }
         // Entire pattern matched starting at i
         matcher.first = i;
         boolean ret = next.match(matcher, i + lengthInChars, seq);
         if (ret) {
             matcher.first = i;
             matcher.groups[0] = matcher.first;
             matcher.groups[1] = matcher.last;
             return true;
         }
         i += countChars(seq, i, 1);
     continue5:
         ;
     }
     matcher._hitEnd = true;
     return false;
 }
Exemplo n.º 17
0
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     int[] src = buffer;
     int patternLength = src.Length;
     int last = matcher.to - patternLength;
     // Loop over all possible match positions in text
     while (i <= last) {
         // Loop over pattern from right to left
         for (int j = patternLength - 1; j >= 0; j--) {
             int ch = seq.charAt(i+j);
             if (ch != src[j]) {
                 // Shift search to the right by the maximum of the
                 // bad character shift and the good suffix shift
                 i += Math.max(j + 1 - lastOcc[ch&0x7F], optoSft[j]);
                 goto continue4;
             }
         }
         // Entire pattern matched starting at i
         matcher.first = i;
         boolean ret = next.match(matcher, i + patternLength, seq);
         if (ret) {
             matcher.first = i;
             matcher.groups[0] = matcher.first;
             matcher.groups[1] = matcher.last;
             return true;
         }
         i++;
     continue4:
         ;
     }
     // BnM is only used as the leading node in the unanchored case,
     // and it replaced its Start() which always searches to the end
     // if it doesn't find what it's looking for, so hitEnd is true.
     matcher._hitEnd = true;
     return false;
 }
Exemplo n.º 18
0
 private static boolean hasBaseCharacter(Matcher matcher, int i,
                                         CharSequence seq)
 {
     int start = (!matcher.transparentBounds) ?
         matcher.from : 0;
     for (int x=i; x >= start; x--) {
         int ch = Character.codePointAt(seq, x);
         if (Character.isLetterOrDigit(ch))
             return true;
         if (Character.getType(ch) == Character.NON_SPACING_MARK)
             continue;
         return false;
     }
     return false;
 }
Exemplo n.º 19
0
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     return (check(matcher, i, seq) & type) > 0
         && next.match(matcher, i, seq);
 }
 public StringBuilder(CharSequence seq)
     : base(seq.length() + 16)
 {
     append(seq);
 }
 public new StringBuilder append(CharSequence s)
 {
     if (s == null)
     s = new String("null");
     //if (s is String)
     //    return this.append((String)s);
     //if (s is StringBuffer)
     //    return this.append((StringBuffer)s);
     //if (s is StringBuilder)
     //    return this.append((StringBuilder)s);
     return this.append(s, 0, s.length());
 }
Exemplo n.º 22
0
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     int savedTo = matcher.to;
     boolean conditionMatched = false;
     // Relax transparent region boundaries for lookahead
     if (matcher.transparentBounds)
         matcher.to = matcher.getTextLength();
     try {
         if (i < matcher.to) {
             conditionMatched = !cond.match(matcher, i, seq);
         } else {
             // If a negative lookahead succeeds then more input
             // could cause it to fail!
             matcher._requireEnd = true;
             conditionMatched = !cond.match(matcher, i, seq);
         }
     } finally {
         // Reinstate region boundaries
         matcher.to = savedTo;
     }
     return conditionMatched && next.match(matcher, i, seq);
 }
 public virtual AbstractStringBuilder insert(int dstOffset, CharSequence s,
                                  int start, int end)
 {
     if (s == null)
     s = new String("null");
     if ((dstOffset < 0) || (dstOffset > this.length()))
     throw new IndexOutOfRangeException("dstOffset "+dstOffset);
     if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
     throw new IndexOutOfRangeException(
         "start " + start + ", end " + end + ", s.length() "
         + s.length());
     int len = end - start;
     ensureCapacityInternal(count + len);
     Array.Copy(value, dstOffset, value, dstOffset + len,
                  count - dstOffset);
     for (int i=start; i<end; i++)
     value[dstOffset++] = s.charAt(i);
     count += len;
     return this;
 }
Exemplo n.º 24
0
 /// <summary>
 /// Wraps a string into a buffer.
 /// </summary>
 public static CharBuffer wrap(CharSequence csq)
 {
     return default(CharBuffer);
 }
Exemplo n.º 25
0
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     if (cond.match(matcher, i, seq)) {
         return yes.match(matcher, i, seq);
     } else {
         return not.match(matcher, i, seq);
     }
 }
        public XFoo(CharSequence e)
        {

        }
Exemplo n.º 27
0
 /// <summary>
 /// Resets this matcher with a new input sequence.
 /// </summary>
 public Matcher reset(CharSequence input)
 {
     return default(Matcher);
 }
        public static void invoke(CharSequence e)
        {

        }
Exemplo n.º 29
0
 /// <summary>
 /// Wraps a character sequence into a buffer.
 /// </summary>
 public static CharBuffer wrap(CharSequence csq, int start, int end)
 {
     return default(CharBuffer);
 }
Exemplo n.º 30
0
 internal override boolean match(Matcher matcher, int i, CharSequence seq)
 {
     int rmaxChars = countChars(seq, i, -rmax);
     int rminChars = countChars(seq, i, -rmin);
     int savedFrom = matcher.from;
     int savedLBT = matcher.lookbehindTo;
     boolean conditionMatched = false;
     int startIndex = (!matcher.transparentBounds) ?
                      matcher.from : 0;
     int from = Math.max(i - rmaxChars, startIndex);
     matcher.lookbehindTo = i;
     // Relax transparent region boundaries for lookbehind
     if (matcher.transparentBounds)
         matcher.from = 0;
     for (int j = i - rminChars;
          !conditionMatched && j >= from;
          j -= j>from ? countChars(seq, j, -1) : 1) {
         conditionMatched = cond.match(matcher, j, seq);
     }
     //Reinstate region boundaries
     matcher.from = savedFrom;
     matcher.lookbehindTo = savedLBT;
     return !conditionMatched && next.match(matcher, i, seq);
 }