mbeckerle commented on code in PR #799:
URL: https://github.com/apache/daffodil/pull/799#discussion_r889014288


##########
daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala:
##########
@@ -2362,32 +2359,32 @@ sealed abstract class DocumentPart(part: Node, parent: 
Document) {
   }.trim.toUpperCase()
 
   /*
-  * Description: Compare ByteDocumentPart/BitsDocumentPart string to a string 
of valid characters.
-  *              If the string runs into non-valid characters, skip over them.
-  *              If the string runs into "//", any character following it will 
be skipped (including valid ones).
-  *              Characters on a new line will be considered again, unless 
they are found after a "//"
-  * Parameters: String containing the acceptable characters (0,1 for bits) 
(0-9,A-F,a-f for bytes)
-  * Return: ListBuffer[Char] of the accepted characters from the 
ByteDocumentPart/BitsDocumentPart element
+  * Allow "//" and "/* */" (inline) to act as comments.
+  * Any characters not explicitly allowed are also considered comments and are 
removed.
   */
-  def commentCompatibleFormat(validCharacters: String) : ListBuffer[Char] = {
-    val tempListBuffer = new ListBuffer[Char]()
-    var noCommentBool = true
-
-    for (i <- 0 to partRawContent.length()-1){
-      //Check if valid
-      if(noCommentBool && validCharacters.contains(partRawContent(i))){
-        tempListBuffer += partRawContent(i)
-      }
-      else if(partRawContent(i) == '/' && i < partRawContent.length()-1){
-        if(partRawContent(i+1) == '/'){
-          noCommentBool = false
-        }
-      }
-      else if(partRawContent(i) == '\n'){
-        noCommentBool = true
-      }
+  def removeComments(validCharactersSet : String, userData : String ) : String 
= {
+    lazy val doubleForwardPattern = "//.*".r
+    lazy val openClosePattern = "/[*].*[*]/".r
+
+    //Remove the comments (//) and (/* */)
+    lazy val noCommentsForward = doubleForwardPattern.replaceAllIn(userData,"")
+    lazy val noCommentsBothFormats = 
openClosePattern.replaceAllIn(noCommentsForward,"")
+
+    //Throw exception if /* or */ still found. This means user input was not 
formatted correctly.
+    if(noCommentsBothFormats.contains("/*") || 
noCommentsBothFormats.contains("*/")){
+      throw TDMLException("Improper formatting of /* */ style comment", None)
     }
-    tempListBuffer
+
+    //Remove the new lines - concatenate after
+    lazy val noCommentsString = noCommentsBothFormats.split('\n').mkString
+
+    //Iterate over and check value of the characters, if invalid character 
found create log and skip over it

Review Comment:
   By " " you mean adding quotation marks? I think those are unwise and we 
don't have them as yet anywhere I've seen. 
   
   If you meant spaces. I think we should definitely tolerate whitespace of 
course. I thought there was elsewhere in the code removing that, but maybe that 
was just newlines?
   
   As for "." I can see it being used.... somewhere. So yeah, add that one too. 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to