The following piece of code is supposed to add html spaces in place of leading spaces.
/**
* Finds all leading spaces on each line and replaces it with
* an HTML space ( )
*
* @param s string containing text to replaced with  
* @return the new string
*/
public final static String leadingSpaces(String s) {
s = noNull(s);
StringBuffer str = new StringBuffer();
boolean justAfterLineBreak = true;
for (int i = 0; i < s.length(); i++) {
if (justAfterLineBreak) {
if (s.charAt(i) == ' ') {
str.append(" ");
} else if (s.charAt(i) == '\n') {
str.append(s.charAt(i));
} else {
str.append(s.charAt(i));
justAfterLineBreak = false;
}
} else {
if (s.charAt(i) == '\n') {
justAfterLineBreak = true;
}
str.append(s.charAt(i));
}
}
return str.toString();
}
I tried using this code in my application for formatting String text. he outcome includes " " in its body. Could you please let me know what I am missing. The code snippet is from:
http://svn.opensymphony.com/svn/oscore/trunk/src/java/com/opensymphony/util/TextUtils.java