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 2022/09/08 15:01:43 UTC

[GitHub] [daffodil] OWL-Varun commented on a diff in pull request #832: Daffodil 2720 wip create new char class entities

OWL-Varun commented on code in PR #832:
URL: https://github.com/apache/daffodil/pull/832#discussion_r966083283


##########
daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/DFDLDelimiter.scala:
##########
@@ -86,112 +92,183 @@ class Delimiter {
   // it may not be.
   //
   def reduceDelimBuf(delims: Array[DelimBase]): Array[DelimBase] = {
+    var reducedWSP = reduceWhitespaceDelimiters(delims, "wsp")
+    var reducedLSP = reduceWhitespaceDelimiters(reducedWSP, "lsp")
+    var reducedDelims = reduceWhitespaceDelimiters(reducedLSP, "sp")
+    reducedDelims
+  }
 
+  def reduceWhitespaceDelimiters(delims: Array[DelimBase], delimType: String): Array[DelimBase] = {
     val q: Queue[DelimBase] = new Queue[DelimBase]()
 
-    // Counters to keep track of WSP,+,* objects
-    var numWSP: Int = 0
-    var numWSP_Plus: Int = 0
-    var numWSP_Star: Int = 0
+    // Counters to keep track of delim standard,+,* objects
+    var numDelim_Standard: Int = 0
+    var numDelim_Plus: Int = 0
+    var numDelim_Star: Int = 0
 
     var idx: Int = 0 // To index the resultant array
 
     delims.foreach(delim => {
-      delim match {
-        case wsp: WSPDelim => numWSP += 1
-        case wsp: WSPPlusDelim => numWSP_Plus += 1
-        case wsp: WSPStarDelim => numWSP_Star += 1
-        case _ => {
-          // We've reached a non WSP delimiter, check if we've
-          // previously encountered any WSP delimiter objects and
-          // return the equivalent representation (if any)
-          val result = getReducedDelim(numWSP, numWSP_Plus, numWSP_Star)
-
-          if (result.isDefined) {
-            val x = result.get
-            // WSP exists and an equivalent representation was found
-            x.index = idx // Set the delimiter's index
-            q += x
+      if (delimType == "wsp") {
+        delim match {
+          case wsp: WSPDelim => numDelim_Standard += 1
+          case wsp: WSPPlusDelim => numDelim_Plus += 1
+          case wsp: WSPStarDelim => numDelim_Star += 1
+          case _ => {
+            val (newQ, newIdx) = updateQueue(numDelim_Standard, numDelim_Plus, numDelim_Star, q, idx, delimType)

Review Comment:
   You're right. With my previous code, the logic in updateQueue() needed to be run a couple times so I thought it best to create a method so that the method could be called. With your suggested changes, the code can be left the same as you said.



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

To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org