From 3f926146892c3d98598ec6079640036d8db4a4e6 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 25 Apr 2013 17:47:54 +0400 Subject: [PATCH] moved to util --- .../com/intellij/xml/util/XmlTagUtilBase.java | 61 +------------------ .../com/intellij/xml/util/XmlStringUtil.java | 60 +++++++++++++++++- 2 files changed, 60 insertions(+), 61 deletions(-) rename platform/{platform-api => util}/src/com/intellij/xml/util/XmlStringUtil.java (51%) diff --git a/platform/platform-api/src/com/intellij/xml/util/XmlTagUtilBase.java b/platform/platform-api/src/com/intellij/xml/util/XmlTagUtilBase.java index f3d9c9a86ae1..b42b8ab62d31 100644 --- a/platform/platform-api/src/com/intellij/xml/util/XmlTagUtilBase.java +++ b/platform/platform-api/src/com/intellij/xml/util/XmlTagUtilBase.java @@ -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); } } \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/xml/util/XmlStringUtil.java b/platform/util/src/com/intellij/xml/util/XmlStringUtil.java similarity index 51% rename from platform/platform-api/src/com/intellij/xml/util/XmlStringUtil.java rename to platform/util/src/com/intellij/xml/util/XmlStringUtil.java index 8e4042b79739..5d678b8c88c9 100644 --- a/platform/platform-api/src/com/intellij/xml/util/XmlStringUtil.java +++ b/platform/util/src/com/intellij/xml/util/XmlStringUtil.java @@ -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