aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/com/android/utils/XmlUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/com/android/utils/XmlUtils.java')
-rw-r--r--common/src/com/android/utils/XmlUtils.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/common/src/com/android/utils/XmlUtils.java b/common/src/com/android/utils/XmlUtils.java
index 73e1d11..94b7405 100644
--- a/common/src/com/android/utils/XmlUtils.java
+++ b/common/src/com/android/utils/XmlUtils.java
@@ -182,6 +182,27 @@ public class XmlUtils {
}
/**
+ * Converts the given attribute value to an XML-text-safe value, meaning that
+ * less than and ampersand characters are escaped.
+ *
+ * @param textValue the text value to be escaped
+ * @return the escaped value
+ */
+ @NonNull
+ public static String toXmlTextValue(@NonNull String textValue) {
+ for (int i = 0, n = textValue.length(); i < n; i++) {
+ char c = textValue.charAt(i);
+ if (c == '<' || c == '&') {
+ StringBuilder sb = new StringBuilder(2 * textValue.length());
+ appendXmlTextValue(sb, textValue);
+ return sb.toString();
+ }
+ }
+
+ return textValue;
+ }
+
+ /**
* Appends text to the given {@link StringBuilder} and escapes it as required for a
* DOM attribute node.
*