SourceCodeSubstitutions.java
/**
*
*/
package edu.odu.cs.cowem.documents;
/**
* A collection of text substitutions, used primarily for
* mark up of source code with highlighting and callouts.
*
* @author zeil
*
*/
public class SourceCodeSubstitutions implements TextSubstitutions {
/**
* HTML code to close a span.
*/
private static final String CLOSE_SPAN = "</span>";
/**
* Special substitutions defined for this website processing. These deal
* mainly with highlighting and inserting callouts into code listings.
*/
private static final String[] SUBSTITUTION_VALUES = {
"/*...*/", "⋮",
"/*1*/", "➀",
"/*2*/", "➁",
"/*3*/", "➂",
"/*4*/", "➃",
"/*5*/", "➄",
"/*6*/", "➅",
"/*7*/", "➆",
"/*8*/", "➇",
"/*9*/", "➈",
"/*+*/", "<span class='hli'>",
"/*-*/", CLOSE_SPAN,
"/*+1*/", "<span class='hli'>",
"/*-1*/", CLOSE_SPAN,
"/*+2*/", "<span class='hlii'>",
"/*-2*/", CLOSE_SPAN,
"/*+3*/", "<span class='hliii'>",
"/*-3*/", CLOSE_SPAN,
"/*+4*/", "<span class='hliv'>",
"/*-4*/", CLOSE_SPAN,
"/*+i*/", "<i>",
"/*-i*/", "</i>",
"/*+=*/", "<span class='strike'>",
"/*-=*/", CLOSE_SPAN,
"\\%", "%",
"[_", "<span class='userinput'>",
"_]", CLOSE_SPAN
};
/**
* Create a substitution set.
*/
public SourceCodeSubstitutions() {
}
/**
* Apply substitutions.
*
* @param toString original string
* @return original after applying substitutions.
*/
@Override
public final String apply(final String toString) {
String result = toString;
for (int i = 0; i < SUBSTITUTION_VALUES.length; i += 2) {
String target = SUBSTITUTION_VALUES[i];
String value = SUBSTITUTION_VALUES[i + 1];
result = result.replace(target, value);
}
return result;
}
}