You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2019/12/17 14:17:52 UTC

[GitHub] [incubator-daffodil] stevedlawrence commented on a change in pull request #301: DAFFODIL-2169 Add typesafty to our handling of infoset data values.

stevedlawrence commented on a change in pull request #301: DAFFODIL-2169 Add typesafty to our handling of infoset data values.
URL: https://github.com/apache/incubator-daffodil/pull/301#discussion_r358807003
 
 

 ##########
 File path: daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/FNFunctions.scala
 ##########
 @@ -55,24 +103,31 @@ case class FNAbs(recipe: CompiledDPath, argType: NodeInfo.Kind) extends FNOneArg
 }
 
 case class FNStringLength(recipe: CompiledDPath, argType: NodeInfo.Kind) extends FNOneArg(recipe, argType) {
-  override def computeValue(str: AnyRef, dstate: DState) = asAnyRef(str.asInstanceOf[String].length.toLong)
+  override def computeValue(str: DataValuePrimitive, dstate: DState):DataValueLong = str.getString.length.toLong
 }
 
 case class FNLowerCase(recipe: CompiledDPath, argType: NodeInfo.Kind) extends FNOneArg(recipe, argType) {
-  override def computeValue(str: AnyRef, dstate: DState) = str.asInstanceOf[String].toLowerCase
+  override def computeValue(str: DataValuePrimitive, dstate: DState):DataValueString = str.getString.toLowerCase
 }
 
 case class FNUpperCase(recipe: CompiledDPath, argType: NodeInfo.Kind) extends FNOneArg(recipe, argType) {
-  override def computeValue(str: AnyRef, dstate: DState) = str.asInstanceOf[String].toUpperCase
+  override def computeValue(str: DataValuePrimitive, dstate: DState):DataValueString = str.getString.toUpperCase
 }
 
 case class FNConcat(recipes: List[CompiledDPath]) extends FNArgsList(recipes) {
-  override def computeValue(values: List[Any], dstate: DState) = values.mkString
+  override def computeValue(values: List[DataValuePrimitive], dstate: DState):DataValueString = {
+    val ans = new StringBuilder()
+    for(i <- 0 to values.length-1){
+      ans.append(values(i).getAnyRef.toString())
+    }
+    ans.toString()
+  }
 }
 
 // No such function in DFDL v1.0
 // But leave this here because we probably will want to add it as a
 // daffodil extension function and then eventually hope it gets into DFDL1.1
+// 12/12/2019 - We refactored how these functions are defined. The args should now be of type DataValuePrimitive
 //case class FNStringJoin(recipes: List[CompiledDPath]) extends FNTwoArgs(recipes) {
 //  override def computeValue(arg1: AnyRef, arg2:AnyRef, dstate: DState) = {
 //    val values = arg1.asInstanceOf[List[String]]
 
 Review comment:
   This entire comment doesn't really seem worth keeping to me, or at least not updating to use the new DataValuePrimitive. The fn:string-join function looks like it is supposed to accept a sequence of arguments and concats them all together. So it's fn:concat, but with varargs. Daffodil doesn't support sequences, and I don't think that's anywhere on the nearterm roadmap. And the commented function only accepts two args anyway, so doesn't even seem correct. Seems like this is just cruft.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services