0

In Python3, we have a function like this

Python 3.8.5 (v3.8.5:580fbb018f, Jul 20 2020, 12:11:27) 

>>> from html import unescape

>>> unescaped = unescape("here is ' apostrophe")

>>> print(unescaped)

here is ' apostrophe
>>>

I'm having trouble finding an equivalent in Clojure. Does a base library function exist.

1
  • I wouldn't expect it to exist in the Clojure standard library; it smells like something already covered by Java, JavaScript, or otherwise platform-specific libraries that Clojure provides access to, where there would be very little benefit to reimplementing the wheel. Commented Oct 23, 2020 at 18:17

1 Answer 1

2

The library apache.commons.text can do this job:

(ns tst.demo.core
  (:use tupelo.core tupelo.test)
  (:import
    [org.apache.commons.text StringEscapeUtils]))

(dotest
  (let [hng      "hi & goodbye"
        encoded  (StringEscapeUtils/escapeHtml4 hng)]
    (is= encoded "hi & goodbye")
    (is= hng (StringEscapeUtils/unescapeHtml4 encoded))))

The Apache site has the full API docs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.