Strip comments from code in launcher

Propose new features and changes
iPhilip
Posts: 829
Joined: 02 Oct 2013, 12:21

Strip comments from code in launcher

09 Jan 2023, 13:13

I recently encountered a launcher issue (link) that could be solved by stripping commented lines from the code being analyzed. I would like to suggest that a version of the function below be used in the GetLaunchParameters() function inside the launcher.ahk file.

Code: Select all

StripComments(InputFile, OutputFile := "", Encoding := "") {
   FileEncoding Encoding
   Code := "", CommentSection := false
   Loop Read InputFile, OutputFile
   {
      Line := RegExReplace(A_LoopReadLine, "[ `t]*;.*")
      if RegExMatch(Line, "^[ `t]*/\*")
         CommentSection := true
      else if RegExMatch(Line, "^[ `t]*\*/(.*)", &Match) {
         CommentSection := false, Line := Match[1]
         if (Line = "")
            continue
      }
      if !CommentSection {
         Code .= Line "`r`n"
         if OutputFile
            FileAppend(Line "`r`n")
      }
   }
   return Code
}
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 3 guests