mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moved to util
This commit is contained in:
@@ -15,69 +15,10 @@
|
||||
*/
|
||||
package com.intellij.xml.util;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class XmlTagUtilBase {
|
||||
public static String escapeString(@Nullable final String str, final boolean escapeWhiteSpace) {
|
||||
if (str == null) return null;
|
||||
StringBuffer buffer = null;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
@NonNls String entity;
|
||||
char ch = str.charAt(i);
|
||||
switch (ch) {
|
||||
case '\n':
|
||||
entity = escapeWhiteSpace ? " " : null;
|
||||
break;
|
||||
case '\r':
|
||||
entity = escapeWhiteSpace ? " " : null;
|
||||
break;
|
||||
case '\t':
|
||||
entity = escapeWhiteSpace ? "	" : null;
|
||||
break;
|
||||
case'\"':
|
||||
entity = """;
|
||||
break;
|
||||
case'<':
|
||||
entity = "<";
|
||||
break;
|
||||
case'>':
|
||||
entity = ">";
|
||||
break;
|
||||
case'&':
|
||||
entity = "&";
|
||||
break;
|
||||
case 160: // unicode char for
|
||||
entity = " ";
|
||||
break;
|
||||
default:
|
||||
entity = null;
|
||||
break;
|
||||
}
|
||||
if (buffer == null) {
|
||||
if (entity != null) {
|
||||
// An entity occurred, so we'll have to use StringBuffer
|
||||
// (allocate room for it plus a few more entities).
|
||||
buffer = new StringBuffer(str.length() + 20);
|
||||
// Copy previous skipped characters and fall through
|
||||
// to pickup current character
|
||||
buffer.append(str.substring(0, i));
|
||||
buffer.append(entity);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (entity == null) {
|
||||
buffer.append(ch);
|
||||
}
|
||||
else {
|
||||
buffer.append(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there were any entities, return the escaped characters
|
||||
// that we put in the StringBuffer. Otherwise, just return
|
||||
// the unmodified input string.
|
||||
return buffer == null ? str : buffer.toString();
|
||||
return XmlStringUtil.escapeString(str, escapeWhiteSpace);
|
||||
}
|
||||
}
|
||||
+59
-1
@@ -38,7 +38,65 @@ public class XmlStringUtil {
|
||||
}
|
||||
|
||||
public static String escapeString(@Nullable String str, final boolean escapeWhiteSpace) {
|
||||
return XmlTagUtilBase.escapeString(str, escapeWhiteSpace);
|
||||
if (str == null) return null;
|
||||
StringBuilder buffer = null;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
@NonNls String entity;
|
||||
char ch = str.charAt(i);
|
||||
switch (ch) {
|
||||
case '\n':
|
||||
entity = escapeWhiteSpace ? " " : null;
|
||||
break;
|
||||
case '\r':
|
||||
entity = escapeWhiteSpace ? " " : null;
|
||||
break;
|
||||
case '\t':
|
||||
entity = escapeWhiteSpace ? "	" : null;
|
||||
break;
|
||||
case'\"':
|
||||
entity = """;
|
||||
break;
|
||||
case'<':
|
||||
entity = "<";
|
||||
break;
|
||||
case'>':
|
||||
entity = ">";
|
||||
break;
|
||||
case'&':
|
||||
entity = "&";
|
||||
break;
|
||||
case 160: // unicode char for
|
||||
entity = " ";
|
||||
break;
|
||||
default:
|
||||
entity = null;
|
||||
break;
|
||||
}
|
||||
if (buffer == null) {
|
||||
if (entity != null) {
|
||||
// An entity occurred, so we'll have to use StringBuffer
|
||||
// (allocate room for it plus a few more entities).
|
||||
buffer = new StringBuilder(str.length() + 20);
|
||||
// Copy previous skipped characters and fall through
|
||||
// to pickup current character
|
||||
buffer.append(str.substring(0, i));
|
||||
buffer.append(entity);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (entity == null) {
|
||||
buffer.append(ch);
|
||||
}
|
||||
else {
|
||||
buffer.append(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there were any entities, return the escaped characters
|
||||
// that we put in the StringBuffer. Otherwise, just return
|
||||
// the unmodified input string.
|
||||
return buffer == null ? str : buffer.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Reference in New Issue
Block a user