Here you can find the source of escapeCellText(String text, boolean wrap, boolean multiline)
Parameter | Description |
---|---|
text | the text |
wrap | whether to allow wrap |
multiline | whether to show multiple line |
public static String escapeCellText(String text, boolean wrap, boolean multiline)
//package com.java2s; import java.util.List; public class Main { /**/*from www . j ava 2 s .co m*/ * Escape character that has special meaning in HTML such as <, &, etc.. * @param text the text * @param wrap whether to allow wrap * @param multiline whether to show multiple line * @return the HTML */ public static String escapeCellText(String text, boolean wrap, boolean multiline) { final StringBuffer out = new StringBuffer(); for (int j = 0, tl = text.length(); j < tl; ++j) { char cc = text.charAt(j); switch (cc) { case '&': out.append("&"); break; case '<': out.append("<"); break; case '>': out.append(">"); break; case ' ': out.append(wrap ? " " : " "); break; case '\n': if (wrap && multiline) { out.append("<br/>"); break; } default: out.append(cc); } } return out.toString(); } private static String escapeCellText(String text, boolean wrap, boolean multiline, List<int[]> runs) { StringBuffer out = new StringBuffer(); if (text != null) { int j = 0; for (int[] run : runs) { for (int tl = run[0]; j < tl; ++j) { char cc = text.charAt(j); out.append(cc); } for (int tl = run[1]; j < tl; ++j) { char cc = text.charAt(j); switch (cc) { case '&': out.append("&"); break; case '<': out.append("<"); break; case '>': out.append(">"); break; case ' ': out.append(wrap ? " " : " "); break; case '\n': if (wrap && multiline) { out.append("<br/>"); break; } default: out.append(cc); } } } for (int tl = text.length(); j < tl; ++j) { char cc = text.charAt(j); out.append(cc); } } return out.toString(); } }