olabusayoT commented on a change in pull request #260: Adds support for
non-spacing and combining chars
URL: https://github.com/apache/incubator-daffodil/pull/260#discussion_r302148180
##########
File path: daffodil-io/src/main/scala/org/apache/daffodil/io/Dump.scala
##########
@@ -516,24 +544,41 @@ class DataDumper {
// Either way, we got our one character
Assert.invariant(nConsumedBytes > 0)
Assert.invariant(cb.hasArray)
- var allChars = cb.array
- remapped = if (allChars.length > 1) allChars.mkString else
Misc.remapCodepointToVisibleGlyph(allChars(0)).toChar.toString
- nCols = if (allChars.length > 1) {
- try {
- var uCodePoint = UCharacter.getCodePoint(allChars(0),
allChars(1))
- charNColumns(uCodePoint)
- } catch {
- case e: IllegalArgumentException => {
- allChars.mkString.length
+ val allChars = cb.array
+
+ val uCodePoint =
+ if (allChars.length > 1) {
+ try {
+ UCharacter.getCodePoint(allChars(0), allChars(1))
+ } catch {
+ case e: IllegalArgumentException => {
+ -1
+ }
+ }
+ } else allChars(0)
+
+ val (r: String, n: Int) =
+ if (allChars.length > 1) {
+ if (uCodePoint == -1) {
+ allChars.map(c => homogenizeChars(c)).foldLeft(("", 0)) {
Review comment:
I updated the code for clarity, adding comments and doing some additional
checks so we don't need to rely on exception handling for illegal surrogate
pairs!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services