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
}