stevedlawrence commented on a change in pull request #75: Daffodil 1738 zoned 
decimal
URL: https://github.com/apache/incubator-daffodil/pull/75#discussion_r195409724
 
 

 ##########
 File path: 
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/ZonedTextParsers.scala
 ##########
 @@ -17,14 +17,421 @@
 
 package org.apache.daffodil.processors.parsers
 
+import org.apache.daffodil.schema.annotation.props.gen. { 
TextNumberCheckPolicy, TextNumberRounding, TextNumberRoundingMode, 
TextZonedSignStyle }
+import org.apache.daffodil.exceptions.ThrowsSDE
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.exceptions.UnsuppressableException
+import org.apache.daffodil.util.Maybe
+import org.apache.daffodil.util.DecimalUtils
+import java.text.ParsePosition
+import com.ibm.icu.text.DecimalFormat
+import org.apache.daffodil.util.MaybeDouble
+import org.apache.daffodil.util.MaybeDouble
+import java.lang.{ Number => JNumber }
+import java.math.{ BigDecimal => JBigDecimal, BigInteger => JBigInt }
+import org.apache.daffodil.infoset.DISimple
 import org.apache.daffodil.processors.ElementRuntimeData
+import org.apache.daffodil.processors.ParseOrUnparseState
+import org.apache.daffodil.processors.Success
+import java.lang.{ Number => JNumber }
+import java.math.{ BigDecimal => JBigDecimal }
+import java.math.{ BigInteger => JBigInt }
+import org.apache.daffodil.processors.TermRuntimeData
 
-class ZonedTextNumberParser(override val context: ElementRuntimeData)
-  extends TextPrimParser {
+case class ConvertZonedCombinatorParser(
+  rd: TermRuntimeData,
+  valueParser: Parser,
+  converterParser: Parser)
+  extends CombinatorParser(rd) {
 
   override lazy val runtimeDependencies = Nil
 
+  override lazy val childProcessors = Seq(valueParser, converterParser)
+
+  def parse(start: PState): Unit = {
+    valueParser.parse1(start)
+    if (start.processorStatus ne Success) {
+      return
+    }
+    converterParser.parse1(start)
+  }
+}
+
+case class ConvertZonedNumberParser[S](
+  helper: ConvertZonedNumberParserUnparserHelperBase[S],
+  nff: ZonedFormatFactoryBase[S],
+  zonedSignStyle: TextZonedSignStyle,
+  override val context: ElementRuntimeData) extends TextPrimParser {
+  override lazy val runtimeDependencies = Nil
+
+  override def toString = "to(xs:" + helper.xsdType + ")"
+
   def parse(start: PState): Unit = {
-    context.notYetImplemented("Zoned Numbers")
+    val node: DISimple = start.simpleElement
+    val str = node.dataValueAsString
+
+    Assert.invariant(str != null) // worst case it should be empty string. But 
not null.
+    if (str == "") {
+      PE(start, "Convert to %s (for xs:%s): Cannot parse number from empty 
string", helper.prettyType, helper.xsdType)
+      return
+    }
+
+    var checkLength = str.length
+    val numValue = {
+      val df = nff.getNumFormat(start)
+      val pos = new ParsePosition(0)
+      val num = try {
+        val decodedNum = DecimalUtils.zonedToNumber(str, zonedSignStyle)
+        if (decodedNum(0) == '-')
+          checkLength = checkLength + 1
+        df.get.parse(decodedNum, pos)
+      } catch {
+        case s: scala.util.control.ControlThrowable => throw s
+        case u: UnsuppressableException => throw u
+        case e: Exception => {
+          PE(start, "Convert to %s (for xs:%s): Parse of '%s' threw exception 
%s",
+            helper.prettyType, helper.xsdType, str, e)
+          return
+        }
 
 Review comment:
   DecimalFormat JavaDoc claims that it dos not throw an Exception, which means 
this whole try/catch block shouldn't be needed. I wonder if we're just using an 
older version of ICU4J that does throw, but newer versions don't....

----------------------------------------------------------------
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

Reply via email to