stevedlawrence commented on a change in pull request #75: Daffodil 1738 zoned
decimal
URL: https://github.com/apache/incubator-daffodil/pull/75#discussion_r195402785
##########
File path:
daffodil-lib/src/main/scala/org/apache/daffodil/util/DecimalUtils.scala
##########
@@ -335,4 +335,142 @@ object DecimalUtils {
outArray
}
+ def convertFromAsciiStandard(digit: Int): (Int, Boolean) = {
+ if ((digit >= 48) && (digit <= 57)) // positive 0-9
+ return (digit - 48, false)
+ else if ((digit >= 112) && (digit <= 121)) // negative 0-9
+ return (digit - 112, true)
+ else
+ throw new NumberFormatException("Invalid zoned digit: " + digit)
+ }
+
+ def convertToAsciiStandard(digit: Char, positive: Boolean, op: Boolean):
Char = {
+ if (positive || !op)
+ return digit
+ else
+ return (digit + 64).asInstanceOf[Char]
+ }
+
+ def convertFromAsciiTranslatedEBCDIC(digit: Int): (Int, Boolean) = {
+ if (digit == 123)
+ return (0, false)
+ else if (digit == 125)
+ return (0, true)
+ else if ((digit >= 65) && (digit <= 73)) // positive 1-9
+ return (digit - 64, false)
+ else if ((digit >= 74) && (digit <= 82)) // negative 1-9
+ return (digit - 73, true)
+ else if ((digit >= 48) && (digit <= 57))
+ return (digit - 48, false) // non-overpunched digit
+ else
+ throw new NumberFormatException("Invalid zoned digit: " + digit)
+ }
+
+ def convertToAsciiTranslatedEBCDIC(digit: Char, positive: Boolean, op:
Boolean): Char = {
+ val result = (positive, op) match {
+ case (true, true) => { // Overpunch character with positive sign
+ if (digit == '0')
+ 123
+ else
+ digit + 16
+ }
+ case (false, true) => { // Overpunch character with negative sign
+ if (digit == '0')
+ 125
+ else
+ digit + 25
+ }
+ case _ => digit
+ }
+
+ return result.asInstanceOf[Char]
+ }
+
+ def convertFromAsciiCARealiaModified(digit: Int): (Int, Boolean) = {
+ if ((digit >= 48) && (digit <= 57)) // positive 0-9
+ return (digit - 48, false)
+ else if ((digit >= 32) && (digit <= 41)) // negative 0-9
+ return (digit - 32, true)
+ else
+ throw new NumberFormatException("Invalid zoned digit: " + digit)
+ }
+
+ def convertToAsciiCARealiaModified(digit: Char, positive: Boolean, op:
Boolean): Char = {
+ if (positive || !op)
+ return digit
+ else
+ return (digit - 16).asInstanceOf[Char]
+ }
+
+ def convertFromAsciiTandemModified(digit: Int): (Int, Boolean) = {
+ if ((digit >= 48) && (digit <= 57)) // positive 0-9
+ return (digit - 48, false)
+ else if ((digit >= 128) && (digit <= 137)) // negative 0-9
+ return (digit - 128, true)
+ else
+ throw new NumberFormatException("Invalid zoned digit: " + digit)
+ }
+
+ def convertToAsciiTandemModified(digit: Char, positive: Boolean, op:
Boolean): Char = {
+ if (positive || !op)
+ return digit
+ else
+ return (digit + 80).asInstanceOf[Char]
+ }
+
+ def zonedToNumber(num: String, zonedStyle: TextZonedSignStyle): String = {
+ val decodedValue = new StringBuilder()
Review comment:
It's probably a good idea to give an an initial capacity to the
StringBuilder constructor. I think the result string will always be the same
length as the length of num + 1 for a potential negative sign? So num.length +
1 for initial capacity should be enough?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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