org.umber.core.text.splitters
Class BraceMatchSplitter

java.lang.Object
  extended byorg.umber.core.text.splitters.BraceMatchSplitter
All Implemented Interfaces:
ITextSplitter

public class BraceMatchSplitter
extends java.lang.Object
implements ITextSplitter

Text splitter which divides a text document according to matching pairs of open/close brace tokens. The splitter manages nested braces to ensure it finds the proper closing brace. For example, given the text document "one (two (three) four) five)", and braces of "(" and ")", the brace matcher would split the text into the fragments "one ", "(two (three) four)", and " five)". It would not match the nested closing brace after "three", nor the unpaired brace after "five".

Author:
jsheets

Constructor Summary
BraceMatchSplitter()
          Creates a new instance of BraceMatchSplitter.
BraceMatchSplitter(java.lang.String openBrace, java.lang.String closeBrace)
          Creates a new instance of BraceMatchSplitter with custom braces.
 
Method Summary
 java.lang.String[] splitText(java.lang.String text)
          Extracts fragments of text from the input text document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BraceMatchSplitter

public BraceMatchSplitter()
Creates a new instance of BraceMatchSplitter.


BraceMatchSplitter

public BraceMatchSplitter(java.lang.String openBrace,
                          java.lang.String closeBrace)
Creates a new instance of BraceMatchSplitter with custom braces. Braces will typically be parentheses, curly braces, or something similar, but can technically be anything, including multicharacter strings.

Parameters:
openBrace - the starting brace token
closeBrace - the ending brace token
Method Detail

splitText

public java.lang.String[] splitText(java.lang.String text)
Extracts fragments of text from the input text document.

This implementation extracts one fragment of text for each parenthetical regular expression group. If the expression has no groups, this method will return an empty array.

Specified by:
splitText in interface ITextSplitter
Parameters:
text - input text document
Returns:
extracted text fragments