com.petebevin.markdown
Class TextEditor

java.lang.Object
  extended by com.petebevin.markdown.TextEditor

public class TextEditor
extends Object

Mutable String with common operations used in Markdown processing.


Constructor Summary
TextEditor(CharSequence text)
          Create a new TextEditor based on the contents of a String or StringBuffer.
 
Method Summary
 void append(CharSequence s)
          Add a string to the end of the buffer.
 TextEditor deleteAll(String pattern)
          Remove all occurrences of the given regex pattern, replacing them with the empty string.
 TextEditor detabify()
          Convert tabs to spaces given the default tab width of 4 spaces.
 TextEditor detabify(int tabWidth)
          Convert tabs to spaces.
 TextEditor indent(int spaces)
          Introduce a number of spaces at the start of each line.
 boolean isEmpty()
          Find out whether the buffer is empty.
 TextEditor outdent()
          Remove one tab width (4 spaces) from the start of each line.
 TextEditor outdent(int spaces)
          Remove a number of spaces at the start of each line.
 void prepend(CharSequence s)
          Add a string to the start of the first line of the buffer.
 TextEditor replaceAll(Pattern pattern, Replacement replacement)
          Replace all occurrences of the Pattern.
 TextEditor replaceAll(String regex, String replacement)
          Replace all occurrences of the regular expression with the replacement.
 TextEditor replaceAllLiteral(String regex, String replacement)
          Same as replaceAll(String, String), but does not interpret $1, $2 etc.
 Collection<HTMLToken> tokenizeHTML()
          Parse HTML tags, returning a Collection of HTMLToken objects.
 String toString()
          Give up the contents of the TextEditor.
 TextEditor trim()
          Remove leading and trailing space from the start and end of the buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextEditor

public TextEditor(CharSequence text)
Create a new TextEditor based on the contents of a String or StringBuffer.

Parameters:
text -
Method Detail

toString

public String toString()
Give up the contents of the TextEditor.

Overrides:
toString in class Object
Returns:

replaceAll

public TextEditor replaceAll(String regex,
                             String replacement)
Replace all occurrences of the regular expression with the replacement. The replacement string can contain $1, $2 etc. referring to matched groups in the regular expression.

Parameters:
regex -
replacement -
Returns:

replaceAllLiteral

public TextEditor replaceAllLiteral(String regex,
                                    String replacement)
Same as replaceAll(String, String), but does not interpret $1, $2 etc. in the replacement string.

Parameters:
regex -
replacement -
Returns:

replaceAll

public TextEditor replaceAll(Pattern pattern,
                             Replacement replacement)
Replace all occurrences of the Pattern. The Replacement object's replace() method is called on each match, and it provides a replacement, which is placed literally (i.e., without interpreting $1, $2 etc.)

Parameters:
pattern -
replacement -
Returns:

deleteAll

public TextEditor deleteAll(String pattern)
Remove all occurrences of the given regex pattern, replacing them with the empty string.

Parameters:
pattern - Regular expression
Returns:
See Also:
Pattern

detabify

public TextEditor detabify()
Convert tabs to spaces given the default tab width of 4 spaces.

Returns:

detabify

public TextEditor detabify(int tabWidth)
Convert tabs to spaces.

Parameters:
tabWidth - Number of spaces per tab.
Returns:

outdent

public TextEditor outdent(int spaces)
Remove a number of spaces at the start of each line.

Parameters:
spaces -
Returns:

outdent

public TextEditor outdent()
Remove one tab width (4 spaces) from the start of each line.

Returns:

trim

public TextEditor trim()
Remove leading and trailing space from the start and end of the buffer. Intermediate lines are not affected.

Returns:

indent

public TextEditor indent(int spaces)
Introduce a number of spaces at the start of each line.

Parameters:
spaces -
Returns:

append

public void append(CharSequence s)
Add a string to the end of the buffer.

Parameters:
s -

tokenizeHTML

public Collection<HTMLToken> tokenizeHTML()
Parse HTML tags, returning a Collection of HTMLToken objects.

Returns:

prepend

public void prepend(CharSequence s)
Add a string to the start of the first line of the buffer.

Parameters:
s -

isEmpty

public boolean isEmpty()
Find out whether the buffer is empty.

Returns:


Copyright © 2011. All Rights Reserved.