I'm busy trying to answer this question myself: Scala Play 2.4.x handling extended characters through anorm (MySQL) to Java Mail
and I came across this possible solution: https://objectpartners.com/2013/04/24/html-encoding-utf-8-characters/
So I decided to rewrite the sample in Scala:
def htmlEncode(input: String) = htmlEncode_sb(input).toString
def htmlEncode_sb(input: String, stringBuilder: StringBuilder = new StringBuilder()) = {
for ((c, i) <- input.zipWithIndex) {
if (CharUtils.isAscii(c)) {
// Encode common HTML equivalent characters
stringBuilder.append(StringEscapeUtils.escapeHtml4(c.toString()))
} else {
// Why isn't this done in escapeHtml4()?
stringBuilder.append(String.format("&#x%x;": String, Character.codePointAt(input, i)))
}
}
stringBuilder
}
}
FYI: I tend to re-write most things that work on Strings into a wrapped StringBuilder call in case I'm already building something with another StringBuilder in which case I can just pass that StringBuilder as a param - if not then works as a normal String by calling the first function.
You would think this is all fine and dandy however the Scala compiler has this to say:
[info] Compiling 1 Scala source to /SomeOne/SomePath/SomeProject/target/scala-2.11/classes...
[error] /SomeOne/SomePath/SomeProject/TKEmailAgent.scala:278: overloaded method value format with alternatives:
[error] (x$1: java.util.Locale,x$2: String,x$3: Object*)String <and>
[error] (x$1: String,x$2: Object*)String
[error] cannot be applied to (String, Int)
[error] stringBuilder.append(String.format("&#x%x;": String, Character.codePointAt(input, i)))
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
Note that I even tried "declaring" the first parameter needed to be a string:
stringBuilder.append(String.format("&#x%x;": String, Character.codePointAt(input, i)))
and yet the compiler didn't take the hint that the overloaded method with a java.util.Locale would do the trick.
I moved the code to a less cluttered class thinking perhaps it was an import doing this but no such luck.
So the question is how does one disable Implicit's that are not of one's choosing?
OR
How does one satisfy the compiler's need to know what you really want here?