stevedlawrence commented on a change in pull request #75: Daffodil 1738 zoned
decimal
URL: https://github.com/apache/incubator-daffodil/pull/75#discussion_r195404344
##########
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()
+ var negative = false
+
+ for (char <- num.chars().toArray) {
Review comment:
I believe chars().toArray is going to allocate stuff, which we want to
avoid. Strings have constant time indexing, so it would probably be better to
do something like
```
var i = 0
while (i < num.length) {
val digit = num(i)
...
i += 1
}
```
----------------------------------------------------------------
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