From 88bd8553d204d0b61fb52f8e35a4adac1d10563b Mon Sep 17 00:00:00 2001 From: "donghyuk.yang" Date: Tue, 30 Jul 2013 19:15:22 +0900 Subject: [PATCH] [Title] Modified CharacterStripper --- .../pkg/commander/rpm/RpmCommanderCommon.java | 2 +- .../nativeplatform/util/CharacterStripper.java | 44 ++++++++++------------ 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderCommon.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderCommon.java index e7539b5..c972098 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderCommon.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/pkg/commander/rpm/RpmCommanderCommon.java @@ -766,7 +766,7 @@ public abstract class RpmCommanderCommon implements IPkgCommander { } String stripXml = CharacterStripper.stripShellEscapseSequence(CharacterStripper - .stripNonValidXMLCharacters(xml)); + .stripInvalidXMLChar(xml)); return stripXml; } diff --git a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CharacterStripper.java b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CharacterStripper.java index 394bc3c..08a836f 100644 --- a/org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CharacterStripper.java +++ b/org.tizen.nativeplatform/src/org/tizen/nativeplatform/util/CharacterStripper.java @@ -28,35 +28,29 @@ package org.tizen.nativeplatform.util; public class CharacterStripper { - /** - * This method ensures that the output String has only valid XML unicode - * characters as specified by the XML 1.0 standard. For reference, please - * see the - * standard. This method will return an empty String if the input is - * null or empty. - * - * @param in - * The String whose non-valid characters we want to remove. - * @return The in String, stripped of non-valid characters. - */ - public static String stripNonValidXMLCharacters(String in) { - StringBuffer out = new StringBuffer(); // Used to hold the output. - char current; // Used to reference the current character. - if (in == null || ("".equals(in))) { - return ""; // vacancy test. + public static String stripInvalidXMLChar(String str) { + int i = 0; + char ch; + StringBuffer result = new StringBuffer(); + + if (str == null || str.isEmpty()) { + return ""; } - for (int i = 0; i < in.length(); i++) { - current = in.charAt(i); // NOTE: No IndexOutOfBoundsException caught - // here; it should not happen. - if ((current == 0x9) || (current == 0xA) || (current == 0xD) - || ((current >= 0x20) && (current <= 0xD7FF)) - || ((current >= 0xE000) && (current <= 0xFFFD)) - || ((current >= 0x10000) && (current <= 0x10FFFF))) { - out.append(current); + + while (i < str.length()) { + ch = str.charAt(i); + if (isValidXMLChar(ch)) { + result.append(ch); } + i++; } - return out.toString(); + return result.toString(); + } + + public static boolean isValidXMLChar(char ch) { + return ((ch == 0x9) || (ch == 0xA) || (ch == 0xD) || ((ch >= 0x20) && (ch <= 0xD7FF)) + || ((ch >= 0xE000) && (ch <= 0xFFFD)) || ((ch >= 0x10000) && (ch <= 0x10FFFF))); } public static String stripShellEscapseSequence(String in) { -- 2.7.4