Date: 03/22/07 (Code WTF) Keywords: xml, java, google Есть такая контора - ThoughtWorks. И есть у неё такая библиотечка - XStream. Довольно широко используемая. /**
* Unescapes name re-enstating '$' and '_' when replacement strings are found
* @param name the name of attribute or node
* @return The String with unescaped name
*/
public String unescapeName(String name) {
StringBuffer result = new StringBuffer();
int length = name.length();
for(int i = 0; i < length; i++) {
char c = name.charAt(i);
if ( stringFoundAt(name, i, underscoreReplacement)) {
i += underscoreReplacement.length() - 1;
result.append('_');
} else if ( stringFoundAt(name, i, dollarReplacement)) {
i += dollarReplacement.length() - 1;
result.append('$');
} else {
result.append(c);
}
}
return result.toString();
}
private boolean stringFoundAt(String name, int i, String replacement) {
if ( name.length() >= i + replacement.length()
&& name.substring(i, i + replacement.length()).equals(replacement) ){
return true;
}
return false;
}http://www.google.com/codesearch?hl=e Source: http://community.livejournal.com/code_wtf/74748.html
|