is there a kotlin library that escapes strings to ...
# announcements
c
is there a kotlin library that escapes strings to be safe as xml attributes? I could use https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/StringEscapeUtils.html but I would really like to avoid adding a dependency
j
isn't there just like 4 characters that needs escaping in XML?
b
Going by this reference, this function should do the trick
👍 2
Although Apache's implementation handles some extra cases (like control characters and invalid unicode codepoints): source code
r
In my experience, whenever I think “isn’t it just...” about serialising to or parsing a text based data format I’m just about to introduce a bug.
👍 2
c
@Ben Woodworth thanks that snippet is exactly what i need. for attributes I'm also going to escape \n but then its perfect
162 Views