com.google.clearsilver.jsilver.functions.escape
Class SimpleEscapingFunction

java.lang.Object
  extended by com.google.clearsilver.jsilver.functions.escape.SimpleEscapingFunction
All Implemented Interfaces:
TextFilter
Direct Known Subclasses:
HtmlEscapeFunction, JsEscapeFunction

public abstract class SimpleEscapingFunction
extends Object
implements TextFilter

Base class to make writing fast, simple escaping functions easy. A simple escaping function is one where each character in the input is treated independently and there is no runtime state. The only decision you make is whether the current character should be escaped into some different string or not. The only serious limitation on using this class it that only low valued characters can be escaped. This is because (for speed) we use an array of escaped strings, indexed by character value. In future this limitation may be lifted if there's a call for it.


Constructor Summary
protected SimpleEscapingFunction()
           
protected SimpleEscapingFunction(char[] ESCAPE_CHARS)
          Creates an instance to escape the given set of characters.
 
Method Summary
 void filter(String in, Appendable out)
          Algorithm is as follows: Scan block for contiguous unescaped sequences Append unescaped sequences to output Append escaped string to output (if found) Rinse & Repeat
protected abstract  String getEscapeString(char c)
          Given one of the escape characters supplied to this instance's constructor, return the escape string for it.
protected  void setEscapeChars(char[] ESCAPE_CHARS)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleEscapingFunction

protected SimpleEscapingFunction(char[] ESCAPE_CHARS)
Creates an instance to escape the given set of characters.


SimpleEscapingFunction

protected SimpleEscapingFunction()
Method Detail

setEscapeChars

protected void setEscapeChars(char[] ESCAPE_CHARS)
                       throws AssertionError
Throws:
AssertionError

getEscapeString

protected abstract String getEscapeString(char c)
Given one of the escape characters supplied to this instance's constructor, return the escape string for it. This method does not need to be efficient.


filter

public void filter(String in,
                   Appendable out)
            throws IOException
Algorithm is as follows:
  1. Scan block for contiguous unescaped sequences
  2. Append unescaped sequences to output
  3. Append escaped string to output (if found)
  4. Rinse & Repeat

Specified by:
filter in interface TextFilter
Throws:
IOException


Copyright © 2010-2012 Google. All Rights Reserved.