Last active
August 29, 2015 14:20
-
-
Save frangarcia/8a74107f47f476ede89f to your computer and use it in GitHub Desktop.
Replacing surrogates chars by html entities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes( | |
@Grab(group='commons-lang', module='commons-lang', version='2.6') | |
) | |
/*@Grapes( | |
@Grab(group='org.apache.commons', module='commons-lang3', version='3.3') | |
)*/ | |
import org.apache.commons.lang.StringEscapeUtils | |
//import org.apache.commons.lang3.StringEscapeUtils | |
String sentence = "This is my < first caption ππππβΊοΈπππππππππ©π§π³πΉπΏπ¬ππππππππ’πππππππππͺπππ½πππππ―πππππΌπ π‘β²οΈππ¨β οΈπ¬π§πͺπ²π²ππΌππππ β΅οΈπππ©ππππΊπΊπΌππππΈ" | |
String sentenceOut = "" | |
(0..<sentence.size()).each { | |
if (Character.isHighSurrogate(sentence.charAt(it))) { | |
sentenceOut += StringEscapeUtils.escapeHtml(sentence[it]+sentence[it+1]) | |
//sentenceOut += StringEscapeUtils.escapeHtml4(sentence[it]+sentence[it+1]) | |
println "escaping ${sentence[it]+sentence[it+1]}" | |
} else if (Character.isLowSurrogate(sentence.charAt(it))){ | |
} else { | |
sentenceOut += sentence[it] | |
} | |
} | |
return sentenceOut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment