/**
* DealingCharacter.java
* Description:
* @author li.b
* @version 2.0
* Jun 27, 2008
*/
public class DealingCharacter {
/**
* Description: 转译特殊符号标签
* @param value 需要处理的字符串
* @return
*/
public static String filter(String value)
{
if(value == null || value.length() == 0)
return value;
StringBuffer result = null;
String filtered = null;
for(int i = 0; i < value.length(); i++)
{
filtered = null;
switch(value.charAt(i)) { case 60: // '<'
filtered = "<";
break;
case 62: // '>'
filtered = ">";
break;
case 38: // '&'
filtered = "&";
break;
case 34: // '"'
filtered = """;
break;
case 39: // '\''
filtered = "'";
break;
}
if(result == null)
{
if(filtered != null)
{
result = new StringBuffer(value.length() + 50);
if(i > 0)
result.append(value.substring(0, i));
result.append(filtered);
}
} else
if(filtered == null)
result.append(value.charAt(i));
else
result.append(filtered);
}
return result != null ? result.toString() : value;
}
public static void main(String[] args) {
System.out.println(DealingCharacter.filter("sdfasfas"));
}
}
|