united_to_one_line(f90src)
private
Continuous lines are united.
Comments in continuous lines are removed.
Show source
def united_to_one_line(f90src)
return "" unless f90src
lines = f90src.split("\n")
previous_continuing = false
now_continuing = false
body = ""
lines.each{ |line|
words = line.split("")
next if words.empty? && previous_continuing
commentout = false
brank_flag = true ; brank_char = ""
squote = false ; dquote = false
ignore = false
words.collect! { |char|
if previous_continuing && brank_flag
now_continuing = true
ignore = true
case char
when "!" ; break
when " " ; brank_char << char ; next ""
when "&"
brank_flag = false
now_continuing = false
next ""
else
brank_flag = false
now_continuing = false
ignore = false
next brank_char + char
end
end
ignore = false
if now_continuing
next ""
elsif !(squote) && !(dquote) && !(commentout)
case char
when "!" ; commentout = true ; next char
when "\""; dquote = true ; next char
when "\'"; squote = true ; next char
when "&" ; now_continuing = true ; next ""
else next char
end
elsif commentout
next char
elsif squote
case char
when "\'"; squote = false ; next char
else next char
end
elsif dquote
case char
when "\""; dquote = false ; next char
else next char
end
end
}
if !ignore && !previous_continuing || !brank_flag
if previous_continuing
body << words.join("")
else
body << "\n" + words.join("")
end
end
previous_continuing = now_continuing ? true : nil
now_continuing = nil
}
return body
end